SOMETHING WRONG WITH CAMERA ROTATION!
Blitz3D Forums/Blitz3D Programming/SOMETHING WRONG WITH CAMERA ROTATION!
| ||
Someone PLEASE help! SOMETHING is wrong with my camera's x rotation when I try to rotate the camera with the mouse. Can someone tell me why everytime I try to rotate my camera to look up or down, it acts like there's an earthquake there? You'll need this include file: Key_Consts.bb: Main.bb: You'll also need to add this line to your user32.decls file: user32.decls: Thank you to ALL who help! :) Last edited 2012 |
| ||
PLEASE DON'T WRITE IN CAPS. IT'S TERRIBLY ANNOYING AND DOESN'T MAKE ANYONE THINK YOUR PROBLEM IS PARTICULARLY IMPORTANT. Sounds like a gimblelock problem: http://en.wikipedia.org/wiki/Gimbal_lock Yours is caused by entitypitch when adding/subtracting a number. When the yaw value reaches +90/-90, then the entity flips the yaw and roll values to -180. The entity snaps right round. Graphics3D 800,600 SetBuffer BackBuffer() Global cam = CreateCamera() Global sphere = CreateSphere() FlipMesh sphere ScaleEntity sphere,3,3,3 Global light = CreateLight() While Not KeyHit(1) If KeyDown(200) Then RotateEntity cam,EntityPitch(cam,True)+1,EntityYaw(cam,True),EntityRoll(cam,True) If KeyDown(208) Then RotateEntity cam,EntityPitch(cam,True)-1,EntityYaw(cam,True),EntityRoll(cam,True) RenderWorld Color 0,0,0 Text 0,0,EntityPitch(cam,True)+","+EntityYaw(cam,True)+","+EntityRoll(cam,True) Flip Wend End You need to keep track and set the values of the rotations of the camera everytime you call rotateentity, or else it may flip: Graphics3D 800,600 SetBuffer BackBuffer() Global cam = CreateCamera() Global sphere = CreateSphere() FlipMesh sphere ScaleEntity sphere,3,3,3 Global light = CreateLight() Global pitch# = 0.0 Global yaw# = 0 Global roll# = 0 While Not KeyHit(1) If KeyDown(200) Then pitch = pitch + 1 RotateEntity cam,pitch,yaw,roll ElseIf KeyDown(208) Then pitch = pitch - 1 RotateEntity cam,pitch,yaw,roll End If RenderWorld Color 0,0,0 Text 0,0,EntityPitch(cam,True)+","+EntityYaw(cam,True)+","+EntityRoll(cam,True) Flip Wend End Works perfectly. Last edited 2012 |
| ||
Thanks alot, Ross! :) |
| ||
For those of u who dont want to deal with gimbal lock like me, here's the PERFECT, 3rd person, flying camera code: Please note, you'll need the user32.decls line in your user32 decls file, and the constants library, along with the GDI_VKeyDown() function in order to get this to work. GDI_VKeyDown is a MUCH better version of KeyDown() It ALSO works with the MOUSE! So if you specify GDI_VKeyDown(VK_LEFTMOUSE, True), then it will check to see if you're holding the left mouse button down! =D To use the function, simply call in your main loop before updateworld() AND / OR renderworld(): Enjoy! =D Last edited 2012 |
| ||
Ok, something's weird with this code... Ive gotten rid of gimbal lock, but NOW if xang# > 85.0 or xang# < -85.0, and i move the mouse up or down too much, for some reason, it doesnt rotate the camera unless whatever's causing this problem is apparently close to 0 on either the positive or negative rotation scale. Here's the code: Thanks guys! :) |
| ||
Anyone? :/ |
| ||
Can you supply all the code so we can run it? Your "xang" variable should never be greater than 85 or less than -85. Have you tried using the debuglog commands to help you? Oh, and if your supplying code for everyone to use, you shouldn't use global variables is in that people don't have. Your function should be passed across everything it needs, unless it is a type object. Last edited 2012 |
| ||
Ok, well here's an example code. Although.. I have NO idea why it's gimbal locking again... o.o At any rate, here's the code: Just hold space to activate the camera :) Try to go past 85.0 or -85.0 for a while, then move ur mouse in the reverse direction after that. ull see what i mean, if u are able to fix gimbal lock.. i tried and cant >< Thanks! :) Last edited 2012 |
| ||
Ok, your xang variable is not being declared anyway. That's why in my last psot I mentioned about not having variables in a function that rely on them being declared Global elsewhere, which you haven't done. You are also using the "xang" and "yang" value as your rotation numbers. It should be Dest_xang and Dest_yang: Graphics3D 800, 600, 0, 2 Global cam = CreateCamera() PositionEntity cam, 0, 1, 0 CameraRange cam, .1, 100000 AmbientLight 255, 255, 255 Global sky = CreateSphere(25) EntityColor sky, 127, 127, 127 ScaleEntity sky, 10000, 10000, 10000 FlipMesh sky Global plane = CreatePlane() EntityColor plane, 102, 102, 255 Global something = CreateCube() PositionEntity something, 10, 1, 10 Global xang#,yang#,Dest_yang#,Dest_xang# While Not KeyHit(1) Cls If KeyDown(57) Then FreeLook(cam, 10.0) UpdateWorld() RenderWorld() Text GraphicsWidth()/2, GraphicsHeight()/2, "xang#: "+dest_xang#, 1, 1 Text GraphicsWidth()/2, GraphicsHeight()/2+20, "yang#: "+dest_yang#, 1, 1 Flip Wend Function FreeLook(cam, maxmovespeed#) mxs#=MouseXSpeed()/2.0*1.25 mys#=MouseYSpeed()/2.0*1.25 DebugLog("mys="+mys) MoveMouse GraphicsWidth()/2,GraphicsHeight()/2 Dest_xang#=Dest_xang#+mys Dest_yang#=Dest_yang#-mxs xang#=CurveValue#(xang#,Dest_xang#,5) yang#=CurveValue#(yang#,Dest_yang#,5) If Dest_xang# > 85.0 Then dest_xang# = 85.0 If Dest_xang# < -85.0 Then dest_xang# = -85.0 RotateEntity cam,xang#,yang#,0 MoveEntity cam, 0, 0, (MouseDown(1)-MouseDown(2))*0.5 End Function Function CurveValue#(current#,destination#,curve#) current#=current#+((destination#-current#)/curve#) Return current# End Function |
| ||
um, thanks lol. but why is it backwards? o.o |
| ||
I don't know. That's the way you've coded it. It is actually the right way round. Games usually invert the Y axis. Beginners stuff...mys#=MouseYSpeed()/2.0*1.25 try: mys#=MouseYSpeed()/2.0*-1.25 Should invert the Y movement. |