Problem rotating camera

Everything related to 3D programming
mrw
User
User
Posts: 76
Joined: Wed Dec 31, 2014 1:01 pm

Problem rotating camera

Post by mrw »

Hi,
I have camera that I would like to rotate only in the Pitch without touching the other axes.
This causes a bit of a trouble since the RotateCamera() always needs values for all three axes. Or is it possible to omit these values somehow?
I don´t want to involve the y(yaw) or z(roll) axes at all if possible.

I have tried to use #PB_Relative and set the y and z as 0 which does this but I need to set the x as a absolute value. This could ofcourse be calculated but it seems that the value I get from CameraPitch() is different depending on the Yaw axis.

This is really confusing for me so I hope anyone understands what I´m talking about? ;)
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: Problem rotating camera

Post by Comtois »

Please correct my english
http://purebasic.developpez.com/
mrw
User
User
Posts: 76
Joined: Wed Dec 31, 2014 1:01 pm

Re: Problem rotating camera

Post by mrw »

Thanks for your reply!

I didn´t know of that command.. The documentations really should group these command better somehow..
And it looks like the perfect command for what I want.

But I think I have the same problem as with using RotateCamera() with #PB_Relative where the pitch is different depending on the Yaw angle.
The Pitch() command seems to only use relative coordinates.

Let me give you an example of what I´m trying to accomplish.
First-person view where I control the camera using WASD and the mouse.
When I walk forward using W, I use MoveCamera(cam_Main, 0, 0, -0.05, #PB_Local). This is good if I was floating in space, but not when walking on a floor.
I would like for that command to not change the cameras World Y position. How can I solve that?
My thought was to save the current Pitch angle using cam_pitch=CameraPitch(cam_Main, #False), change that to look straight forward, execute the MoveCamera() command above, then change the pitch back to my saved angle.
This can ofcourse be done with relative coordinates but If I turn the camera in Y 180 degrees, the pitch values are not the same anymore. I can´t make any sense of it.
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: Problem rotating camera

Post by Comtois »

Have a look at PitchYaw.pb example
Please correct my english
http://purebasic.developpez.com/
mrw
User
User
Posts: 76
Joined: Wed Dec 31, 2014 1:01 pm

Re: Problem rotating camera

Post by mrw »

Ok, so in that example they create 2 parent nodes to the camera to solve this.
Seems a bit awkward to do this pretty simple thing. But obviously it works.
Is this really the easiest/best/recommended method to use for this?
mrw
User
User
Posts: 76
Joined: Wed Dec 31, 2014 1:01 pm

Re: Problem rotating camera

Post by mrw »

I think I solved using only 1 parent node. I´m guessing that if you need to Roll the camera you probably want one more Node.

Some code:

Code: Select all

; Init Camera and CamHolder Node
node_Camholder = CreateNode(#PB_Any)
cam_Main = CreateCamera(#PB_Any, 0, 0, 100, 100)
AttachNodeObject(node_Camholder,CameraID(cam_Main))

If ExamineMouse()
  Yaw = -MouseDeltaX() * 0.2
  Pitch = -MouseDeltaY() * 0.2
EndIf

If KeyboardPushed(#PB_Key_W)  ;forward
  MoveNode(node_Camholder,0,0,-0.05, #PB_Local)
ElseIf KeyboardPushed(#PB_Key_S)  ;backward
  MoveNode(node_Camholder,0,0,0.05, #PB_Local)
EndIf   
If KeyboardPushed(#PB_Key_A)  ;strafe left
  MoveNode(node_Camholder,-0.05,0,0, #PB_Local)
ElseIf KeyboardPushed(#PB_Key_D)  ;strafe right
  MoveNode(node_Camholder,0.05,0,0, #PB_Local)
EndIf

Yaw(NodeID(node_Camholder),Yaw,#PB_Local)
Pitch(CameraID(cam_Main),Pitch,#PB_Local)
Thanks for pointing me in the right direction!
Post Reply