Lights, Camera(??!?!), Action.

Editor
Jan 16, 2010 at 2:10 AM

Hi there, first of all, WOW. what a great little project you have here, its just brilliant.  I have started to write some tutorials for beginners, as i find it a useful way to compound my knowledge.  I am, however, stuck with the camera use.  it could be me being completely stupid, or it could be me not being clever....wait.... yeah its proabbly me being stupid.

but anyway, I cannot for the life of me seem to apply decent matrix transforms/rotates to the camera, i have camera code in an old xna project that basically moves/rotates a camera, i cannot seem to reuse this code in conjunction with the camera in Ox.  will i have to edit the source code to allow this or is it just me misuing the Orientation methods in the camera?  im basically trying to create a freeroam camera  with gamepad controls, so left stick is movement, right is looking around etc, i am 100% ok with handling the input code, just this teeny problem with applying changed to the engine camera. 

sorry if this post isnt 100% clear i can repost with more sense, if required :D

thanks.

rich.

Coordinator
Jan 16, 2010 at 7:42 AM

Hi rich!

I can't really deduce what you intend to do to the Camera object from your post. Why not post the code you've written to manipulate Ox's camera?

Cheers!

Coordinator
Jan 16, 2010 at 8:15 AM

BTW, you're not applying any translation values to the camera's orientation, are you? The orientation property is only meant to handle optionally-concatenated rotation values. Translations are to be applied to the position property.

Would the API be clearer if the orientation property were named 'rotation' instead?

Cheers!

Editor
Jan 16, 2010 at 8:20 AM

actually i am trying to rotate it. im trying to make a free roam camera, ill post the code im using to try and do this, (sorry if its sloppy i dont tidy code until its working)

 public void moveCamera()
        {
            Matrix cameraRotation = Matrix.CreateRotationX(xLook) * Matrix.CreateRotationY(yLook);
            Vector3 cameraOriginalTarget = new Vector3(0, 0, -1);
            Vector3 cameraOriginalUpVector = new Vector3(0, 1, 0);
            Vector3 cameraRotatedTarget = Vector3.Transform(cameraOriginalTarget, cameraRotation);
            Vector3 cameraFinalTarget = Engine.Camera.Position + cameraRotatedTarget;
            Vector3 cameraRotatedUpVector = Vector3.Transform(cameraOriginalUpVector, cameraRotation);
            Matrix lookat = Matrix.CreateLookAt(Engine.Camera.Position, cameraFinalTarget, cameraRotatedUpVector);
            Engine.Camera.SetOrientation(ref lookat);
          
        }
xLook and yLook are the inputs from the gamepad. this code definately works in normal XNA so im just assuming that i have not used your camera correctly. hope this makes sense, if it doesnt ill repost again :D

<font size="2">

thanks for your response :)

</font>

 

Editor
Jan 16, 2010 at 8:22 AM
bubzy wrote:

actually i am trying to rotate it. im trying to make a free roam camera, ill post the code im using to try and do this, (sorry if its sloppy i dont tidy code until its working)

 public void moveCamera()
        {
            Matrix cameraRotation = Matrix.CreateRotationX(xLook) * Matrix.CreateRotationY(yLook);
            Vector3 cameraOriginalTarget = new Vector3(0, 0, -1);
            Vector3 cameraOriginalUpVector = new Vector3(0, 1, 0);
            Vector3 cameraRotatedTarget = Vector3.Transform(cameraOriginalTarget, cameraRotation);
            Vector3 cameraFinalTarget = Engine.Camera.Position + cameraRotatedTarget;
            Vector3 cameraRotatedUpVector = Vector3.Transform(cameraOriginalUpVector, cameraRotation);
            Matrix lookat = Matrix.CreateLookAt(Engine.Camera.Position, cameraFinalTarget, cameraRotatedUpVector);
            Engine.Camera.SetOrientation(ref lookat);
          
        }
xLook and yLook are the inputs from the gamepad. this code definately works in normal XNA so im just assuming that i have not used your camera correctly. hope this makes sense, if it doesnt ill repost again :D

<font size="2">

thanks for your response :)

</font>

 

 *sigh* i called the function "moveCamera()" i know :) its because i intend to have all function in there at some point, just hope this doesnt throw you off. the movement is working ok. :)

Coordinator
Jan 16, 2010 at 8:26 AM
Edited Jan 16, 2010 at 8:27 AM

Matrix.CreateLookAt does not return an orientation matrix. Instead, it returns a projection matrix. The two are quite different as the projection involves more than rotation data.

I'm trying to remember how to derive an orientation matrix with a similar approach, but the knowledge escapes me at the moment (too much 2D programming :).

Perhaps there's something posted on xna.creators.com.

Editor
Jan 16, 2010 at 8:34 AM

thanks very much, ill go hunting now, ill post my findings in a bit :)

Coordinator
Jan 16, 2010 at 8:50 AM
Edited Jan 16, 2010 at 8:53 AM

You know what, I think I'm off a bit here. Matrix.CreateLookAt doesn't create a projection matrix, but rather a view matrix. I think the view matrix has translation data in addition to rotation data. Prehaps there's some way to decompose the translation data and apply it to the position property while decomposing the rotation data and apply it to the orientation property.

Man I'm rusty @ 3D :)

property
Editor
Jan 16, 2010 at 8:56 AM
Edited Jan 16, 2010 at 8:58 AM

Well.....Ahem. i think i overcomplicated the issue to be honest.   heres my working code....

 protected override void UpdateHook(GameTime gameTime)
        {
            base.UpdateHook(gameTime);
            
             
            rotateCamera();
            moveCamera();
 
        }
        public void rotateCamera()
        {       
	   xLook += Engine.GamePadState.ThumbSticks.Right.Y* 0.1f;
            yLook += Engine.GamePadState.ThumbSticks.Right.X* 0.1f;
RotMatrix = Matrix.CreateRotationX(-xLook)* Matrix.CreateRotationY(-yLook); Engine.Camera.SetOrientation(ref RotMatrix); } private void AddToCameraPosition(Vector3 vectorToAdd) { Matrix cameraRotation = RotMatrix; Vector3 rotatedVector = Vector3.Transform(vectorToAdd, cameraRotation); Engine.Camera.Position += moveSpeed * rotatedVector; } public void moveCamera() { Vector3 moveVector = new Vector3(0, 0, 0); float moveForward = Engine.GamePadState.ThumbSticks.Left.Y; float moveLeftRight = Engine.GamePadState.ThumbSticks.Left.X; moveVector += new Vector3(0, 0, -moveForward); moveVector += new Vector3(moveLeftRight, 0, 0); AddToCameraPosition(moveVector * moveSpeed); }

xna creators forums are full of too many clever people with very complicated words.  i just think a fresh look at this, this morning and your direction helped a lot.

ill be back with more queries soon enough :)

Coordinator
Jan 16, 2010 at 9:00 AM

I'll be around!

cheers!

 

Editor
Jan 16, 2010 at 9:36 AM

Maybe im being stupid again(its likely). i cant seem to find a zip file with ALL of the source code in it. there are a few things i want to change and thats not possible with the dll's. ive checked sourceforge but seem to be able to only download one file at a time, and thats just gonna take forever.

sorry to keep bothering you :)

rich.

Coordinator
Jan 16, 2010 at 9:40 AM

You have to do an 'SVN check out'. Download TortoiseSVN and read up on how to pull down a repository. There might also be some instructions on checking out a repository at SourceForge.

cheers!