Egh ok I'm stuck, camera rotations

This topic is 4844 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I'm trying to make a FPS camera using nebula 2 engine, and well I'm not so great with math, so I've read alot of tutorials but now I'm just stuck... All my code does it make the game super gittery, like the world objects are having a seizure. But the strafing/moving forward part works back... its the rotations:
	// matrix rotations....
float LeftRight = m_turnRight - m_turnLeft;
float UpDown = m_lookUp - m_lookDown;

m_targetVec.y = t.pos_component().y + (float)(1.0f * sin(UpDown));
m_targetVec.x = t.pos_component().x + (float)(1.0f * cos(UpDown) * cos(LeftRight));
m_targetVec.z = t.pos_component().z + (float)(1.0f * cos(UpDown) * sin(LeftRight));

m_upVec.x = t.pos_component().x - m_targetVec.x;
m_upVec.z = t.pos_component().z - m_targetVec.z;
m_upVec.y = abs(t.pos_component().y + (float)(1.0f * sin(UpDown + Pi/2)));

t.lookatLh(m_targetVec, m_upVec);
gfx->SetViewMat(t);

LeftRight and UpDown are variables filled in from the input based on mouse movement, they are clamped from -0.5f to 0.5f.. t is the current view matrix4x4, http://nebuladevice.cubik.org/documentation/nebula2/class__matrix44.shtml upvec/target vec are a given =p

Share on other sites
I cant really figure you what your code means, try explaining what you are doing in words, because most people dont really like tryin to decifer a code dump. And a quick question, why are you multiplying by one when computing the m_targetVec? that seems like a bit of waste to me.

Also you are converting a float to a float I think. I dont know what this would do, but it might use the floor function on your float which would cause things to be jerky. So either get rid of that float cast, or if that really is an int and im just missing something, add 0.5f to it so it will round off correctly.

Share on other sites
target vector and up vector are in reality 2 axis for
the camera viewing matrix. So if they get scaled the whole
scene becomes funny because every vertex of your scene will be multiplied by the camera matrix.

I am not shure if the vectors get scaled from looking at your code fragment, but give it a try:
normalize the up/lookAt vectors (give them the length 1)
by doing this (I am sure there is a function for that in nebula)

v.x = v.x/v.length;
v.y = v.y/v.length;
v.z = v.z/v.length;

-- constantin

Ps: I looked for the normalize function in nebula 2:
m_targetVec.norm();
m_upVec.norm();
will do it.

Share on other sites
im basing my code off of http://www.gamedev.net/reference/articles/article2160.asp that article and its math formulas at http://www.gamedev.net/reference/articles/2160/source.txt

which says
targetpos.x = camposition.X + [radius * cos(angle1) * cos(angle2)]

the radius is 1.0f which is pointless as I just realized =p so i removed it... but all I want is the formula to calculate the x,y,z point of the target vector of the camera with certain pitch/yaxis angles, those angles will be changed by the mouse input