About Store Forum Documentation Contact
Donations:
158$/mo



Post Reply 
Camera pos in player local space.
Author Message
Ioannis Offline
Member

Post: #1
Camera pos in player local space.
Working on walk bob camera animations for a regular first-person player class. To control the camera I use:
Code:
Cam.setSpherical(mvCameraPosition, Cam.yaw, Cam.pitch, Cam.roll, Cam.dist);
Problem is that the first parameter of the SetSpherical function which is handling the camera position seems to be affecting the camera's world space position while I'm interested in applying it in player/camera local space.
I wonder if there's a built-in way to do it instead of having to go through matrices and rotating vectors manually.
(This post was last modified: 04-13-2020 09:01 PM by Ioannis.)
04-13-2020 08:41 PM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Bronze Supporter

Post: #2
RE: Camera pos in player local space.
Not too sure what is the constraint that you are having, cant you just pass your char world pos ?

You could make your own function of setspherical

Code:
Camera& Camera::setSpherical(C VecD &at, Flt yaw, Flt pitch, Flt roll, Flt dist)
{
   T.at   =at;
   T.yaw  =yaw;
   T.pitch=pitch;
   T.roll =roll;
   T.dist =dist;
   return setSpherical();
}
Camera& Camera::setSpherical()
{
   matrix.setPos(0, 0, -dist).rotateZ(-roll).rotateXY(-pitch, -yaw).move(at);
   return T;
}

And have your move at to be taking your local space and add attached pos
(This post was last modified: 04-13-2020 09:22 PM by RedcrowProd.)
04-13-2020 09:14 PM
Find all posts by this user Quote this message in a reply
Ioannis Offline
Member

Post: #3
RE: Camera pos in player local space.
From a quick look at that code, I'm guessing that Cam.matrix.setPos() is most likely the answer to my problem. I will give it a shot a bit later. Thanks!

Yeap, passing cam offset.x using Cam.matrix.setPos() got all my problems fixed. Thanks again!
(This post was last modified: 04-13-2020 11:24 PM by Ioannis.)
04-13-2020 10:57 PM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Bronze Supporter

Post: #4
RE: Camera pos in player local space.
Glad smile
(This post was last modified: 04-14-2020 04:12 AM by RedcrowProd.)
04-14-2020 03:07 AM
Find all posts by this user Quote this message in a reply
Post Reply