align a quad to camera

Blitz3D Forums/Blitz3D Beginners Area/align a quad to camera

scribbla(Posted 2010) [#1]
im trying to align a quad thats part of a mesh to the camera, i dont want to turn the entity just a quad


; i need understand/figure out how to make x#,y#,z# = camera view, i got this out of the code archives ive picked it to pieces so i can get the quad i want, but aligning it is proving a pain

the stuff in the archives is not very well documented for novices

x#=VertexX(s,i+0)+1 : y#=VertexY(s,i+0)+1 : z#=VertexZ(s,i+0)+1

VertexCoords s,i+0,x#,y#,z#
VertexCoords s,i+1,x#,y#,z#
VertexCoords s,i+2,x#,y#,z#
VertexCoords s,i+3,x#,y#,z#
;


any help/ideas or point me in the right direction

thanks


Ross C(Posted 2010) [#2]
What i would do, is get the height and width of the quad (By getting the distances between the vetices. Now, take any vertex, and tform the co-ords of the vertices in the cameras space, using the distances. I'm struggling to explain this any better i'm afraid. I will knock up a code smaple when i get home. My computer is running in safe mode, as it's completely buggered and still haven't got the cash for a new one :'( I have no sound!!


scribbla(Posted 2010) [#3]
thanks ross
evertime i googled this your posts came up form years ago ,lol

cashless i know that feeling :(

dont laugh ;)
but this is where im upto

......-->...zip file Clicky....<--.....


Ross C(Posted 2010) [#4]
Np's, i'll have a look when i get home (about 5 ish)


Ross C(Posted 2010) [#5]
Ok, i've had a look. Are you just creating this one quad? If so, aren't you easier using a sprite? The .3ds file only contains one quad :)

If you have a model, and it has a quad in there already, you'll need to know the vertex index of each of the 4 vertices.

Can you expand upon what y9our trying to achieve?


scribbla(Posted 2010) [#6]
no theres a plane with quads on, in the zip

press "w" for wireframe

a big plane and one selected quad attached to the mouse

its going to be part of an explosion entity/animation
i just need to align the quads to the camera, i suppose its the same principle as aligning sprites to the camera

ive manged to pick apart the code from archives that selects the quad
i just can not for life of me figure out how to align it





thanks for taking look man ;)


Ross C(Posted 2010) [#7]
Nps, how can you isolate the quad though?


scribbla(Posted 2010) [#8]
its this bit

try changing "mainquad = 8"

;quad index multiples of 4 ie: 0,4,8,16,32....up to last quad 252
; postions bottom right--> 0, 4 , 8 , 12, 16 , 20 ---> 252 top left

Function PositionQuad(s%,i%,x#,y#,z#=0.0) ; at mouse x,y
Local dx#,dy#,dz# , o%
dx=x-VertexX(s,i)
dy=y-VertexY(s,i)
dz=z-VertexZ(s,i)
For o=0 To 3
VertexCoords s,i+o,VertexX(s,i+o)+dx,VertexY(s,i+o)+dy,VertexZ(s,i+o)+dz
Next
End Function


i dont realy understand what the its doing, but im fighting my way thru it ;)


Ross C(Posted 2010) [#9]
Well, if the quad isn't rotated on any other axis, other than the Y axis, this should be verrrrrrrry simple. Can you clarify that?


scribbla(Posted 2010) [#10]
no its all , player could be left/right or going under or over it, i have a feeling that makes it very hard

damn impossible for me man, i gota change hobbies ;)


scribbla(Posted 2010) [#11]
this is doing head in

nearest thing i can find in the archives, it picks quads , but no align to camera




i thought it might be something to do with entityyaw, pitch,roll of camera, lol but i think im out of my depth

this must be like align polys in a particle engine

......-->...zip file Clicky....<--.....


.... any ideas welcome


Kryzon(Posted 2010) [#12]
That's exactly it, like aligning particles in a single surface engine.

What you need to do is calculate the center of that polygon\quad (averaging the XYZ of all 4 vertices), placing a pivot at that averaged position, and then spinning the pivot to the cameras global Pitch, Yaw and Roll.

Then, you use TFormVector from that pivot like with this:
;After positioning the pivot at the averaged XYZ of all 4 vertices:

RotateEntity Pivot,EntityPitch(Camera,True),EntityYaw(Camera,True),EntityRoll(Camera,True),True

TFormVector sx#, -sy#, 0, Pivot, 0
v1x# = TFormedX()
v1y# = TFormedY() 
v1z# = TFormedZ()
TFormVector -sx#, -sy#, 0, Pivot, 0
v2x# = TFormedX() 
v2y# = TFormedY()
v2z# = TFormedZ() 
TFormVector sx#, sy#, 0, Pivot, 0
v3x# = TFormedX() 
v3y# = TFormedY() 
v3z# = TFormedZ() 
TFormVector -sx#, sy#, 0, Pivot, 0
v4x# = TFormedX() 
v4y# = TFormedY() 
v4z# = TFormedZ() 


Then you use each set of v#XYZ variables for each vertice.
Problem is, you have to find out the sx and sy values, which are the size of the quad.
For that you'll probably have to take the difference from each vertice's coordinates regarding to that averaged center of the quad. That will be your sx and sy (you should calculate a sx and sy for each vertice, to avoid deforming the quad).
Then you simply place the 4 vertices with the calculated v-1234-XYZ variables, and you have yourself a camera-aligned quad.


scribbla(Posted 2010) [#13]
i knew it would complicated, thats guna take some time to understand, if at all

but at least i know its doable, thanks


Kryzon(Posted 2010) [#14]
I made this diagram, hope it helps:




scribbla(Posted 2010) [#15]
Ive got something going on , nothing like the way your suggesting, perhaps I need to spend another few weeks learning what the hell is going on,

......-->...zip file Clicky....<--.....

Thanks for trying Kryzon but I just don’t have the brain pan
Its like trying to show a baboon how to drive a car, he gets in pushes a few buttons, waves his arms around & gets out

I think I will just go back to my crayons & colouring books



The problem is ive dragged something out of the code archives and pulled it apart thinking I could follow it

This is going to sound long winded and a strange way of doing things to most people,
The thing started because in no way could I code a particle engine, I have particle candy but don’t like it,
so I came up with a more visual way of doing things and a lot easier for me.
What I wanted to do was create an explosion as an md2 file, 1 entity 1 surface
So I could do the explosion in lightwave with a plane full of quads I can pick each quad and position it.
With its own explostion sprite on, so I would end up with an md2 file with lots of different explosion anims on, simple place entity and run an anim



My only issue is aligning each quad to the camera while the anim is playing


thanks for trying, get out while ya can ;)


Ross C(Posted 2010) [#16]
I can maybe knock something simple particle wise to do this some time this week.


scribbla(Posted 2010) [#17]
cheers Ross

you know im not the greatest at understanding this sort of thing

i owe you a beer, or six, just something i can pull apart and ruin ;)