Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.



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

If you intended to correct an error in the post then please contact us.

Recommended Posts

yes i got a problem with the velocity vector of my camera when i make a rotation i use this code to give another orientation to to my velocity: velocity.z:=(sin(dir)*velocity.x+cos(dir)*velocity.z); velocity.x:=(cos(dir)*velocity.x-sin(dir)*velocity.z); have to knox that i''m doing a tomraider like view: so my player is always in front of me. the problem is that when i turn a lot this velocity vector tend to 0. and i don''t anderstands why. at the end i can''t not move again. all is here Tcamera = class position:Tvector; velocity:Tvector; view:Tvector; upvector:Tvector; rayon:glfloat; constructor Create; procedure positioncamera(posx:glfloat;posy:glfloat;posz:glfloat;viewx:glfloat; viewy:glfloat;viewz:glfloat;upx:glfloat;upy:glfloat;upz:glfloat); procedure mov(speed:glfloat); procedure rotate(dir:glfloat); procedure rotatearound(joueur:Tvector;dir:glfloat); end; implementation constructor Tcamera.Create; begin inherited Create; with position do begin x:=0; y:=0; z:=0; end; with view do begin x:=0; y:=1.0; z:=0.5; end; with upvector do begin x:=0; y:=1; z:=0; end; rayon:=5; with velocity do begin x:=0; y:=0; z:=-2; end; end; procedure Tcamera.positioncamera(posx:glfloat;posy:glfloat;posz:glfloat;viewx:glfloat; viewy:glfloat;viewz:glfloat;upx:glfloat;upy:glfloat;upz:glfloat); begin with position do begin x:=posx; y:=posy; z:=posz; end; with view do begin x:=viewx; y:=viewy; z:=viewz; end; with upvector do begin x:=upx; y:=upy; z:=upz; end; end; procedure Tcamera.mov(speed:glfloat); begin position.x:=position.x+velocity.x*speed; position.z:=position.z+velocity.z*speed; view.x:=view.x+velocity.x*speed; view.z:=view.z+velocity.z*speed; end; procedure Tcamera.rotatearound(joueur:Tvector;dir:glfloat); var aux:Tvector; begin with aux do begin x:=position.x-joueur.x; z:=position.z-joueur.z; end; position.z:=(joueur.z+sin(dir)*aux.x+cos(dir)*aux.z); position.x:=(joueur.x+cos(dir)*aux.x-sin(dir)*aux.z); velocity.z:=(sin(dir)*velocity.x+cos(dir)*velocity.z); velocity.x:=(cos(dir)*velocity.x-sin(dir)*velocity.z); velocity.y:=velocity.y; end; procedure Tcamera.rotate(dir:glfloat); var aux:Tvector; begin with aux do begin x:=view.x-position.x; y:=view.y-position.y; z:=view.z-position.z; end; view.z:=(position.z+sin(dir)*aux.x+cos(dir)*aux.z); view.x:=(position.x+cos(dir)*aux.x-sin(dir)*aux.z); velocity.z:=(sin(dir)*velocity.x)+(cos(dir)*velocity.z); velocity.x:=(cos(dir)*velocity.x)-(sin(dir)*velocity.z); end; end. so if you have another solution for rotation give it to me the thing is that i want to have my velocity vector oriented in the good direction after doing a rotation. please if someone can give me an exemple of code it would illustrate waht you say more love and peace

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!