Cameron Kloot

hi, i am new to this so....
i am wanting to rotate the camera view around the middle (0, 0, 0) i am currently useing this code:
MouseState currentMState = Mouse.GetState();
mouseX = currentMState.X + 30.0f;
mouseY = currentMState.Y + 30.0f;
cameraPosition = new Vector3(mouseX, mouseY, 10000.0f);
but it isnt do what i want so...
thanks




Re: XNA Game Studio Express camera movement prob

Kyle_W

You need to explain in greater detail what you want to do because I don't understand. Why are you adding 30.0f to the MouseX and MouseY values Keep in mind that the origin (0,0) for mouse coordinates is the upper left corner of the game window. You are creating a 3D game correct



Re: XNA Game Studio Express camera movement prob

Cameron Kloot

well, last question first. no i am learning by using a 3d model. i want to make it so that when i move the mouse around it revolves around the middle of the "map". i added the 30 f because i was just trying diff stuff. i just want some sample code for the "revolve around the middle".
thanks






Re: XNA Game Studio Express camera movement prob

deejay169

You don't want to add the value, that gives you a translation (movement) instead of a rotation. You (probably) want to rotate about the Y-axis when you move the mouse left and right and rotate about the X-axis when you move up and down.

Try this:

Code Snippet

cameraPosition = new Vector3(0, 0, 10000f);

Matrix yrot = Matrix.RotationY((float)currentMState.X * 0.01f);

Matrix xrot = Matrix.RotationX((float)currentMState.Y * 0.01f);

cameraPosition = Vector3.Transform(cameraPosition, yrot * xrot);

I haven't tried building that so it might not work straight off. The 0.01f determines how much you rotate depending on the movement of the mouse.

Cheers,

Dave J





Re: XNA Game Studio Express camera movement prob

Cameron Kloot

ok thanks, but the Matrix.RotationY and X dont work :
Error 1 'Microsoft.Xna.Framework.Matrix' does not contain a definition for 'RotationY'
and the same for X
and would u, or someone else, explain how this code works
thanks







Re: XNA Game Studio Express camera movement prob

Kyle_W

Cameron if you look at the XNA class library reference you will see that the correct method names are CreateRotationX and CreateRotationY, although I suspect that code will still need to be modified to get the desired result. Before you begin attempting to write a game, you need to have a good understanding of C# and how to find the relevant classes, properties, and methods that are available in the library reference in the help files or on http://msdn2.microsoft.com. After that, you probably need to read a book on game programming. There are some books available now that talk about XNA specifically. Here are a few:

http://search.barnesandnoble.com/booksearch/results.asp WRD=XNA&z=y&cds2Pid=9481

Beyond this, the best way to learn in my opinion is to look at a lot of code samples and dissect them to figure out how they work. A place to start is with the XNA tutorials:

http://msdn2.microsoft.com/en-us/library/bb203897.aspx





Re: XNA Game Studio Express camera movement prob

Kyle_W

One more note... if you want to solidify your understanding of C#, I recommend you start here:

http://msdn2.microsoft.com/en-us/library/kx37x362(VS.80).aspx





Re: XNA Game Studio Express camera movement prob

Cameron Kloot

i ask questions so i can figure stuff out. Wink i am going trough the tutorials. where can u find the ref library






Re: XNA Game Studio Express camera movement prob

Kyle_W

Inside of XNA Game Studio Express, click Help > Contents > XNA Game Studio Express > Class Library Reference, or you can find it online here:

http://msdn2.microsoft.com/en-us/library/bb200104.aspx





Re: XNA Game Studio Express camera movement prob

Darkside

Yup, most of this basic camera stuff is handled in the tutorials section for cameras @ http://msdn2.microsoft.com/en-us/library/bb203904.aspx

Bit of a trawl to find it but you'll get all the info you need for camera maths and translations.

Also check out Riemers site where there is a very good 3D series for XNA, it'll give you more background.

But if you just starting out i'd suggest you get your 2D basics down first before you jump into 3D, try XNAResources series tutorial on making a 2D tile game, its a good start. Or this article on c-sharpcorner, which is a tutorial for a 2D spacewar clone, covers a lot.

Hope this helps






Re: XNA Game Studio Express camera movement prob

Cameron Kloot

thanks