Advertisement

I wnat to move around in my level

Started by June 17, 2003 01:55 PM
5 comments, last by The Only 21 years, 8 months ago
Hi You Guys, I''m new here and im German, so sorry flr my bad english... My Problem is, that I have loaded a level and i want to move around there as in Counterstrike or Half-Lfie or ...(Turning with the mouse and moving with keyboard) I already wrote some code, but it doesnt work correctly. If I Want to turn(look back), I cant, because the Camera turns very fast, although I''Äm only moving the Mouse just a bit. Heres my Code: if(g_DIState[TB_KEY_UP]) { m_CamPos.x += sinf(m_YRot) * fPassedSecs; m_CamPos.z += (cosf(m_YRot) + cosf(m_XRot)) * fPassedSecs; m_CamPos.y += sinf(m_XRot) * fPassedSecs; } if(g_DIState[TB_KEY_DOWN]) { m_CamPos.x -= sinf(m_YRot) * fPassedSecs; m_CamPos.z -= (cosf(m_YRot) + cosf(m_XRot)) * fPassedSecs; m_CamPos.y -= sinf(m_XRot) * fPassedSecs; } if(g_DIState[TB_MOUSE_X_NEG]) m_YRot -= g_DIState[TB_MOUSE_X_NEG] * fPassedSecs * 50.0f; if(g_DIState[TB_MOUSE_X_POS]) m_YRot += g_DIState[TB_MOUSE_X_POS] * fPassedSecs * 50.0f; if(g_DIState[TB_MOUSE_Y_NEG]) m_XRot += g_DIState[TB_MOUSE_Y_NEG] * fPassedSecs * 50.0f; if(g_DIState[TB_MOUSE_Y_POS]) m_XRot -= g_DIState[TB_MOUSE_Y_POS] * fPassedSecs * 50.0f; m_CamView = m_CamPos + tbVector3(sinf(m_YRot), sinf(m_XRot), cosf(m_XRot)+cosf(m_YRot)); some explaining: g_DIState stores current DeviceStates. TB_MOUSE_X_NEG gives the moving of the mouse since the last "ask" to the left side. TB_MOUSE_X_POS gives th same but in the right direction. I hope you can help me, because nobody in the German Forums could hep me. Maxi
You need to scale down your rotation angle. You can''t just make your rotation angle the number of pixels the mouse pointer moved, otherwise a small mouse move of just 90 pixels (not that much) would result in a 90 degree turn. Just divide the change in mouse position by some amount (for you to figure out) and let that be your rotation angle. Play around with different numbers until you find one that works.
Advertisement
Not only that, but the sin and cos functions expect angles in radians, and I think you might be passing in degrees. Convert your degrees to radians before passing to sin and cos.
what is fPassedSecs ?
is it the time taken by the frame to be rendered?
if you try to do fps independent movement, you must not do it with mouse motion!
hm, thanks for replies but thats not the point.

I dont turn too fast, only, when i want to turn around, if i want to go in -z-direction its turning very very fast and i cant move in -z.

I think that there ist a problem with the right choosing of sin and cos. Maybe you have some links or already programmed something like that.

Maxi
quote:
I dont turn too fast, only, when i want to turn around, if i want to go in -z-direction its turning very very fast and i cant move in -z.



I think we are just having trouble understanding the exact nature of the problem. Are you saying that when you move, the direction of movement is not in the direction that you are facing? If this is true then you need to define a vector that points along your direction. You rotate this vector and use that vector to do your movement.
Advertisement
I think i found the problem, but i cant solve it. Ill try to explain in my bad English

OK: Everything is OK, until I want to turn around 180° so that i look into -z. The Poitn is, when i look into -z, m_YRot is -PI;
But the cos of -PI is -1. And if I look horizontally, so that XRot = 0. But cos of 0=1. And -1+1=0 so that the z-part of the vector looks at almost the same as the Position and so it turns very fast.

I fixed it now because I wrote for the z-coordinate:
m_CamPos.z += (cosf(m_YRot) + sinf(m_XRot)) * fPassedSecs

Now i Can move around as i want but if i turned a bit, the turning "turns", if I move my mouse down, i look up.

I hope you undertand my problem and i hope i will fix it soon

Maxi

This topic is closed to new replies.

Advertisement