-
Hard Math Problem!
I have a small universe, with the 3 standard dimensions: X,Y and Z.
Given these things:
- The (x,y,z) coordinates of the "camera"
- the direction that the camera is pointing
- the (x,y,z) coordinate of a point in space
Can someone tell me the maths expression that will resolve this info into an (x,y) coordinate, so I can plot it on a picturebox.
My brain is aching, please help!
-
You need to use some linear algebra for this kind of thing, what you're basically looking for is a projection matrix (I think that's what it's called). I don't know too much about it myself but there are a lot of articles on this kind of translation at www.gamedev.net , since it's the sort of thing that 3D games use a lot of. www.flipcode.com has some good maths resources for this sort of stuff too.
-
What are you programming this in? GDI, OGL, D3D, Other? If its D3D8, there is a function in the D3DX library called D3DXVec3Project(...) that will do what you want. OGL has a similar function, although i dont know what its called. Search for "Project". If its GDI, you are going to have some fun playing with vector calculus.
Z.
-
Oh dear, I knew someone would ask me that. I'm using PocketC on the PalmOS platform! All I have to work with are the standard math expressions: Cos() Atn() etc...
Its a black/white LCD display on my Palm IIIx handheld, so I'm looking for simple solutions really. :)
-
-
Depends if the camera is always upright, or whether it rolls as well.
The maths for a rolling camera is well tricky, but I can give you the bits for upright no sweat.
Assuming x for horizontal, y for vertical & z for lateral,
Using X,Y for final screen,
x1,y1,z1 for camera pos,
x2,y2,z2 for object pos,
and ang for camera angle
X = (x2 - x1) * Cos(ang) + (z2 - z1) * Sin(ang)
Y = (y2 - y1)
This assumes no perpective
With perspective,
Z = (x2 -x2) * Cos(ang) + (z2 - z1) * Sin(ang)
X = ((x2 - x1) * Cos(ang) + (z2 - z1) * Sin(ang)) * Log(Z)
Y = (y2 - y1) * Log(Z)
This is in maths speak and not code, gotta leave some work for you to do ;)