Rotation Issue in XNA 3.0

September 6, 2008 by admin
Filed under: Xbox360 News 
1 //… 
2         protected override void Update(GameTime gameTime) 
3         { 
4             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) 
5                 this.Exit(); 
6
7 #if !XBOX 
8             if (Keyboard.GetState().IsKeyDown(Keys.Escape)) 
9                 this.Exit(); 
10 #endif 
11  
12             GamePadState gamePadStateP1 = GamePad.GetState(PlayerIndex.One); 
13             GamePadState gamePadStateP2 = GamePad.GetState(PlayerIndex.Two); 
14             GamePadState gamePadStateP3 = GamePad.GetState(PlayerIndex.Three); 
15             GamePadState gamePadStateP4 = GamePad.GetState(PlayerIndex.Four); 
16
17 #if !XBOX 
18             KeyboardState keyboardState = Keyboard.GetState(); 
19 #endif 
20  
21             previousGamePadStateP1 = GamePad.GetState(PlayerIndex.One); 
22             previousGamePadStateP2 = GamePad.GetState(PlayerIndex.Two); 
23             previousGamePadStateP3 = GamePad.GetState(PlayerIndex.Three); 
24             previousGamePadStateP4 = GamePad.GetState(PlayerIndex.Four); 
25  
26             terrain.rotation.X = ((gamePadStateP1.Triggers.Right / 2) - (gamePadStateP1.Triggers.Left / 2) - 1.5f); 
27  
28             terrain.rotation.Z = gamePadStateP1.ThumbSticks.Left.Y; 
29  
30             base.Update(gameTime); 
31         } 
32 //… 
33         void DrawGameObject(GameObject gameobject) 
34         { 
35             foreach (ModelMesh mesh in gameobject.model.Meshes) 
36             { 
37                 foreach (BasicEffect effect in mesh.Effects) 
38                 { 
39                     effect.EnableDefaultLighting(); 
40                     effect.PreferPerPixelLighting = true; 
41  
42                     effect.World = 
43                         Matrix.CreateFromYawPitchRoll( 
44                         gameobject.rotation.Y, 
45                         gameobject.rotation.X, 
46                         gameobject.rotation.Z) * 
47  
48                         Matrix.CreateScale(gameobject.scale) * 
49                         Matrix.CreateTranslation(gameobject.position); 
50  
51                     effect.Projection = cameraProjectionMatrix; 
52                     effect.View = cameraViewMatrix; 
53                 } 
54                 gameobject.position += gameobject.velocity; 
55                 mesh.Draw(); 
56             } 
57         } 
58 //… 
59  

I've started my own game project based on the 3D tutorial. I didn't
complete the tutorial but I had the basics of what I needed for my
game. But, there's one issue that has stopped me from progressing. The
rotation doesn't work right. The X rotation works fine, but when trying
to rotate Y and Z, they act like one another. Example: trying to tilt
the level forward using the Y axis spins it like a record. Trying to
tilt it using the Z axis also spins like a record, but in the opposite
direction.

If you look at line 28, there's a rotation on the Z axis, but I also tried the Y axis and neither achieves the affect I'm looking for.

 Here's the full project: http://www.thestoryofbob.com/content/RotateIssue.zip

If it matters, I modeled in freeware program Blender and I used XNA 3.0 CTP.

Any help would be greatly appreciated.

Cheap wow gold

Comments

Feel free to leave a comment...
and oh, if you want a pic to show with your comment, go get a gravatar!