Skip to main content
GameDev.net gamedev.net
🔒 Locked

Camera problems

Started by MDI Mar 20, 2003 at 3:35 AM 1 replies 250+ views
Original Post
MDI
MDI
I've been using the GameTutorials.com code as a base for my Camera class, but I can't seem to get the code working correctly. I think I have narrowed it down to two sources, either the camera rotation code, or the cross product of the vector (formula gained from a website). Could you be so kind to check over the two? Here's the cross product:
        
    Vector3 Vector3 :: crossProduct (const Vector3& rhs) {
		double tX = (vecY * rhs.vecZ) - (vecZ * rhs.vecY);
		double tY = (vecZ * rhs.vecX) - (vecX * rhs.vecZ);
		double tZ = (vecX * rhs.vecY) - (vecY * rhs.vecX);
		return Vector3 (tX, tY, tZ);
    }

  
And here is the rotation code:
  
void W32Camera :: rotateCamera (float angle, const Vector3& rotator) {
		Vector3 nView;
		Vector3 View = target - position;
		double x = rotator.getX ();
		double y = rotator.getY ();
		double z = rotator.getZ ();
		float cAng = static_cast <float> (cos (angle));
		float sAng = static_cast <float> (sin (angle));
		
		nView.setX ((cAng + (1 - cAng) * x * x)	* View.getX ());
		nView.setX (nView.getX () + ((1 - cAng) * x * y - z * sAng) * View.getY ());
		nView.setX (nView.getX () + ((1 - cAng) * x * z + y * sAng) * View.getZ ());

		nView.setY (((1 - cAng) * x * y + z * sAng) * View.getX ());
		nView.setY (nView.getY () + (cAng + (1 - cAng) * y * y) * View.getY ());
		nView.setY (nView.getY () + ((1 - cAng) * y * z - x * sAng) * View.getZ ());

		nView.setZ (((1 - cAng) * x * z - y * sAng) * View.getX ());
		nView.setZ ((nView.getZ () + (1 - cAng) * y * z + x * sAng) * View.getY ());
		nView.setZ ((nView.getZ () + cAng + (1 - cAng) * z * z) * View.getZ ());

		target = position + nView;
    }
      
If these two function's aren't the problem, then can anyone recommend a good place to start looking for the problem? Sometimes the scene flashes on the screen, but the dissapears again when the buffers are swapped and camera position updated. Thank you in advance. [edited by - MDI on March 20, 2003 4:40:44 AM]
JuNC
JuNC
The cross product is correct.

Does the display work correctly when you don''t use the camera class? Have you actually narrowed it down to that class?

Now I don''t know what the setX method actually does in your vector (I imagine it does the obvious) and in that case you are just overwriting the values twice, is this the behaviour you want?

Post some code as to how you modify the transform matrices from that code, I mean what is target and position?
MDI
MDI
quote:

I mean what is target and position?



Target is the position vector that the Camera is currently pointing at, whereas position is the position vector that the Camera is currently pointing from.

I've narrowed it down to the Camera class now, it is drawing the scene nicely with just a gluLookAt with hardcoded values (but surprisingly when I set the initial position, target and up vectors of the class to the same values, it doesn't draw the scene at all).

quote:

Now I don't know what the setX method actually does in your vector (I imagine it does the obvious) and in that case you are just overwriting the values twice, is this the behaviour you want?



Well, I stared at my code for a good 30 seconds trying to work out where you got that from, and finally came to the conclusion you missed the getX () calls, in effect += on the X coord of the vector :-)

I use gluLookAt for the actual viewing of the camera, I assume that's not the problem, no?



"And that whole philosophy has crept into everything we do now. Music's the last thing where people can go and pay the same amount of money for a piece of shit or a diamond. And that's why we've got to care about it."
- Ashcroft

[edited by - MDI on March 20, 2003 1:41:18 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.