Exemple #1
0
        public void Update(Stopwatch gameTime, KeyboardState state, KeyboardState prevstate, ref Matrix4 cameraPosition, ref Matrix4 cameraRotation, MouseState mousestate, MouseState prevmousestate)
        {
            foreach (gameObject g in gameObjects)
            {
                g.Update(gameTime, state);
            }

            cameraheight.Y += mousestate.ScrollWheelValue - prevmousestate.ScrollWheelValue;
            Matrix4 carTransform = carbody.CalcFinalTransform();

            cameraPosition = Matrix4.Invert(carTransform.ClearRotation()) * Matrix4.CreateTranslation(cameraheight);
            cameraRotation = Matrix4.Invert(carTransform.ClearTranslation()) * Matrix4.CreateRotationY((float)Math.PI) * Matrix4.CreateRotationX((float)(0.5 * Math.PI));

            if (state.IsKeyDown(Key.H) && !prevstate.IsKeyDown(Key.H))
            {
                if (headlight)
                {
                    spotlights = spotlights.GetRange(0, spotlights.Count - 4);
                    headlight  = false;
                }
                else
                {
                    spotlights.Add(new Spotlight(new Vector4(-0.25f, 0.2f, 0.75f, 1), new Vector4(0, 0, 1, 0), 50, new Vector3(1, 1, 1), carbody, 0.8f));
                    spotlights.Add(new Spotlight(new Vector4(0.25f, 0.2f, 0.75f, 1), new Vector4(0, 0, 1, 0), 50, new Vector3(1, 1, 1), carbody, 0.8f));
                    spotlights.Add(new Spotlight(new Vector4(-0.25f, 0.2f, -0.5f, 1), new Vector4(0, 0, -1, 0), 30, new Vector3(1, 0, 0), carbody, 0.95f));
                    spotlights.Add(new Spotlight(new Vector4(0.25f, 0.2f, -0.5f, 1), new Vector4(0, 0, -1, 0), 30, new Vector3(1, 0, 0), carbody, 0.95f));
                    headlight = true;
                }
            }
        }
Exemple #2
0
 public void calc()
 {
     if (parent != null)
     {
         Matrix4 parentmatrix = parent.CalcFinalTransform();
         position = localPosition * parentmatrix.ClearScale();
     }
 }
Exemple #3
0
 // calculate final transformation
 public Matrix4 CalcFinalTransform()
 {
     if (parent != null)
     {
         return(localScale * localRotation * localTranslation * parent.CalcFinalTransform());
     }
     else
     {
         return(localScale * localRotation * localTranslation);
     }
 }