|
 | camera dragging | |  |
| Poster | : Aplsos2 | | Posts | : 3 | | Country | : US | | City | : Cinci |
| | | | Posted by Aplsos2 on 05/02/2008 at 07:59:13
| | so im using basically all your code, Im using the 3d city code but i wanted to use a mouse cam, so im using the code out of this tut. when i ran my code the first time it was fast, hectic, etc and looked like it was spinning crazy without input. slowed it down, and found a draw/rotation, without mouse movement to the bottom right corner of the window. I've stared and stared and i can't for the life of me figure out why?
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
ProcessInput((float)gameTime.ElapsedGameTime.Milliseconds / 1220.0f);
UpdateCameraMatrices();
base.Update(gameTime);
}
private void ProcessInput(float amountOfMovement)
{
Vector3 moveVector = new Vector3();
KeyboardState keys = Keyboard.GetState();
if (keys.IsKeyDown(Keys.Right))
moveVector.X += amountOfMovement;
if (keys.IsKeyDown(Keys.Left))
moveVector.X -= amountOfMovement;
if (keys.IsKeyDown(Keys.Down))
moveVector.Y -= amountOfMovement;
if (keys.IsKeyDown(Keys.Up))
moveVector.Y += amountOfMovement;
Matrix cameraRotation = Matrix.CreateRotationX(cameraAngles.X) * Matrix.CreateRotationZ(cameraAngles.Z);
cameraPosition += Vector3.Transform(moveVector, cameraRotation);
MouseState currentMouseState = Mouse.GetState();
if (currentMouseState.X != previousMouseState.X)
cameraAngles.Z -= amountOfMovement / 80.0f * (currentMouseState.X - previousMouseState.X);
if (currentMouseState.Y != previousMouseState.Y)
cameraAngles.X -= amountOfMovement / 80.0f * (currentMouseState.Y - previousMouseState.Y);
Mouse.SetPosition(Window.ClientBounds.Width / 2, Window.ClientBounds.Height / 2);
}
private void UpdateCameraMatrices()
{
Matrix cameraRotation = Matrix.CreateRotationX(cameraAngles.X) * Matrix.CreateRotationZ(cameraAngles.Z);
Vector3 targetPos = cameraPosition + Vector3.Transform(new Vector3(0, 1, 0), cameraRotation);
Vector3 upVector = Vector3.Transform(new Vector3(0, 0, 1), cameraRotation);
viewMatrix = Matrix.CreateLookAt(cameraPosition, targetPos, upVector);
projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, (float)this.Window.ClientBounds.Width / (float)this.Window.ClientBounds.Height, 1.0f, 1000.0f);
}
protected override void Draw(GameTime gameTime)
{
device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.DarkSlateBlue, 1.0f, 0);
Matrix worldMatrix = Matrix.Identity;
effect.CurrentTechnique = effect.Techniques["Textured"];
effect.Parameters["xWorld"].SetValue(worldMatrix);
effect.Parameters["xView"].SetValue(viewMatrix);
effect.Parameters["xProjection"].SetValue(projectionMatrix);
effect.Parameters["xTexture"].SetValue(scenerytexture);
effect.Begin();
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Begin();
device.VertexDeclaration = new VertexDeclaration(device, VertexPositionNormalTexture.VertexElements);
device.DrawUserPrimitives(PrimitiveType.TriangleList, verticesarray, 0, verticesarray.Length / 3);
pass.End();
}
effect.End();
base.Draw(gameTime);
}
}
} |
| |
|
| | | | | | Poster | : Aplsos2 | | Posts | : 3 | | Country | : US | | City | : Cinci |
| | | | Posted by Aplsos2 on 05/02/2008 at 08:00:13
| | | im sorry about the double post, got an error first time and didnt think it went through | |
|
| | | | | | Poster | : haxpor | | Posts | : 19 | | Country | : | | City | : |
| | | | Posted by haxpor on 27/10/2008 at 15:02:49
| | Check your first time setting of mouse position.
It should be set before setting the originalMouseState. | |
|
| | | | | | Poster | : riemer | | Posts | : 1392 | | Country | : Belgium | | City | : Antwerp |
| | | | Posted by riemer on 27/10/2008 at 15:10:58
| | | exactly | |
|
| | | | | | Poster | : Anonymous | | Posts | : | | Country | : | | City | : |
| | | | Posted by Anonymous on 20/08/2011 at 02:37:22
| | | I got this also, the camera going nuts. I was just copying and pasting as I read, in this step 2 lines in theh LoadContent function were not highlighted as changed code, so I got all confused. Then I saw it :) | |
|
| | | | | | Poster | : Anonymous | | Posts | : | | Country | : | | City | : |
| | | | Posted by Anonymous on 27/07/2012 at 14:43:09
| | | Incorrect.By davoIRELAND's judgment: McDonald's makes more prfiot, because more people eat there I'm one of the people who play games on consoles, by the way.The wits is: When I buy a console game, I'm certain it'll run, unlike some PC-games that require a Quadcore when they pretend to run on Dualcores (just as an example) | |
|
|
 | | |  |
|
|
|
If you appreciate the amount of time I spend creating and updating these pages, feel free to donate -- any amount is welcome !
|
- Website design & DirectX code : Riemer Grootjans - ©2006 Riemer Grootjans
|
|