- Timestamp:
- 2016-06-16 23:31:50 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2016/24/SimoR/Tasohyppelypeli/Tasohyppelypeli/Tasohyppelypeli/Tasohyppelypeli.cs
r7399 r7400 139 139 float matrixLerp = 0f; 140 140 float cameraRotation = 0f; 141 float norsuRotation = 0f; 142 143 bool rotateStar = false; 144 float starRotation = 0f; 141 145 142 146 bool perspective = false; 143 147 bool light = false; 144 145 146 protected override void Initialize()147 {148 base.Initialize();149 150 var parameters = new PresentationParameters()151 {152 MultiSampleCount = 4153 };154 155 //graphics = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile.Reach, parameters);156 }157 148 158 149 protected override void LoadContent() … … 184 175 tahtiTexture = Content.Load<Texture2D>("tahti"); 185 176 177 Keyboard.Listen(Key.W, ButtonState.Pressed, () => 178 { 179 rotateStar = !rotateStar; 180 if (!rotateStar) 181 starRotation = 0f; 182 }, null); 183 184 Keyboard.Listen(Key.F2, ButtonState.Down, () => { norsuRotation += 0.3f; }, null); 185 186 186 // A ja D pyörittää maailmaa. 187 187 Keyboard.Listen(Key.A, ButtonState.Down, () => { cameraRotation += 0.005f; }, null); … … 197 197 protected override void Draw(Microsoft.Xna.Framework.GameTime gameTime) 198 198 { 199 float dt = (float)gameTime.ElapsedGameTime.TotalSeconds; 200 199 201 base.Draw(gameTime); // Piirretään Jypeli jutut ensin. 202 203 // Tähtien pyörittely. 204 if (rotateStar) 205 starRotation += -1.3f * dt; 200 206 201 207 // Sulava muunnos projektiomatriisien välille. 202 208 float dir = perspective ? 1f : -1f; 203 matrixLerp += dir * 0.3f * (float)gameTime.ElapsedGameTime.TotalSeconds;209 matrixLerp += dir * 0.3f * dt; 204 210 matrixLerp = MathHelper.Clamp(matrixLerp, 0f, 1f); 205 211 … … 208 214 209 215 // Piirretään 3D-mallit päälle. 210 DrawModel(norsuModel, norsuTexture, pelaaja1.Position );216 DrawModel(norsuModel, norsuTexture, pelaaja1.Position, norsuRotation); 211 217 foreach (var taso in tasot) 212 218 { 213 DrawModel(tasoModel, vihreaTexture, taso.Position );219 DrawModel(tasoModel, vihreaTexture, taso.Position, 0f); 214 220 } 215 221 foreach (var tahti in tahdet) 216 222 { 217 DrawModel(tahtiModel, tahtiTexture, tahti.Position );218 } 219 } 220 221 void DrawModel(Model model, Texture2D tex, Vector jypeliPos )223 DrawModel(tahtiModel, tahtiTexture, tahti.Position, starRotation); 224 } 225 } 226 227 void DrawModel(Model model, Texture2D tex, Vector jypeliPos, float rotation) 222 228 { 223 229 var transforms = new Matrix[model.Bones.Count]; … … 246 252 effect.EnableDefaultLighting(); 247 253 effect.DiffuseColor = new Vector3(1f, 1f, 1f); 248 //effect.DirectionalLight0.249 254 } 250 255 251 effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY( 0f) * Matrix.CreateTranslation(modelPosition);256 effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(rotation) * Matrix.CreateTranslation(modelPosition); 252 257 effect.View = Matrix.CreateLookAt(cameraPos, Vector3.Zero, Vector3.Up); 253 258 effect.Projection = finalMat;
Note: See TracChangeset
for help on using the changeset viewer.