Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


FPS Camera calculations problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 tom_mai78101   Members   -  Reputation: 577

Like
0Likes
Like

Posted 13 February 2014 - 06:23 AM

I got this information below from a blog that explains the view matrix and its properties.

 

To make a FPS camera, I can use one view matrix, the pitch, and the yaw.

 

By obtaining the eye coordinate in the 3D world, I can use the following pseudocode to create the view matrix:

yaw.toRadians()
pitch.toRadians()
 
Vec3 xAxis = {cos(yaw), -sin(pitch)*sin(yaw), -cos(pitch)*sin(yaw)}
Vec3 yAxis = {0, cos(pitch), -sin(pitch)}
Vec3 zAxis = {sin(yaw), sin(pitch)*cos(yaw), cos(pitch)*cos(yaw)}
 
viewMatrix = {
    xAxis.x, yAxis.y, zAxis.x, 0,
    xAxis.y, yAxis.y, zAxis.y, 0,
    xAxis.z, yAxis.y, zAxis.z, 0,
    -dot(xAxis, eye), -dot(yAxis, eye), -dot(zAxis, eye), 1
}
 

However, when I try to implement this in my code, I get weird results:

 

calnseo.png

brNrOxI.png

 

I can't turn left and right correctly to see the entire green rectangle box. I can look up and down, but the view would get distorted and revolves around my head like a planet revolving around a star. My view is stuck facing at a specific field of view, and I don't know why.

 

My eye vector is {0, 0, 40f}.

The green rectangular box is 112 wide, 16 high. When looked upon from the eye position, I should be able to see all of the box.

 

I don't really know how to fix this. How do I turn and look up/down properly?


Edited by tom_mai78101, 13 February 2014 - 06:26 AM.


Sponsor:

#2 Álvaro   Crossbones+   -  Reputation: 13928

Like
1Likes
Like

Posted 13 February 2014 - 06:52 AM

viewMatrix = {
xAxis.x, yAxis.y, zAxis.x, 0,
xAxis.y, yAxis.y, zAxis.y, 0,
xAxis.z, yAxis.y, zAxis.z, 0,
-dot(xAxis, eye), -dot(yAxis, eye), -dot(zAxis, eye), 1
}



#3 tom_mai78101   Members   -  Reputation: 577

Like
0Likes
Like

Posted 13 February 2014 - 05:18 PM

You threw me offguard with those boldfaced text. I thought that was the answer.

 

Thanks for your difficult answer, the problem is now fixed, and took a long time to see it.



#4 Álvaro   Crossbones+   -  Reputation: 13928

Like
0Likes
Like

Posted 13 February 2014 - 05:56 PM

Well, I was highlighting the problem, not trying to confuse you... Maybe I should have written some text describing the problem, instead of just showing it.

Edited by Álvaro, 13 February 2014 - 05:57 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS