Ejemplo n.º 1
0
 public void TransformGameObject(ref GameObject toTransform)
 {
     toTransform.World = Matrix.Identity;
     ScaleGameObject(ref toTransform);
     TranslateGameObject(ref toTransform);
     RotateGameObject(ref toTransform);
 }
Ejemplo n.º 2
0
        public void TranslateGameObject(ref GameObject toBeTranslated)
        {
            Vector3 posInWorldSpace = toBeTranslated.PositionInWorld;

            Matrix translationMatrix = Matrix.CreateTranslation(posInWorldSpace);

            toBeTranslated.World *= translationMatrix;
        }
Ejemplo n.º 3
0
        public void ScaleGameObject(ref GameObject toBeScaled)
        {
            float scale = toBeScaled.ScalingInWorld;

            Matrix scalingMatrix;

            Matrix.CreateScale(scale, out scalingMatrix);

            toBeScaled.World *= scalingMatrix;
        }
Ejemplo n.º 4
0
        public void RotateGameObject(ref GameObject toBeRotated)
        {
            Vector3 axis = toBeRotated.RotationAxis;
            float angle = MathHelper.ToRadians(toBeRotated.RotationAngleInDegrees);
            float angleHalf = angle / 2;
            float sinAngleHalf = (float)Math.Sin(angleHalf);
            Quaternion rotationQuaternion = new Quaternion(axis.X * sinAngleHalf, axis.Y * sinAngleHalf, axis.Z * sinAngleHalf, (float)Math.Cos(angleHalf));
            rotationQuaternion.Normalize();

            Matrix rotationMatrix = Matrix.CreateFromQuaternion(rotationQuaternion);

            toBeRotated.World *= rotationMatrix;
        }
Ejemplo n.º 5
0
        private Level Parse(XmlLevel toParse)
        {
            Level parsed = new Level();

            parsed.AmbientLight = new Vector4(toParse.ambientLightColor.red, toParse.ambientLightColor.blue,
                toParse.ambientLightColor.blue, toParse.ambientLightIntensity);

            parsed.Lights = new List<LightSource>();
            foreach (XmlLightSource lightSource in toParse.lightSources)
            {
                LightSource parsedLightSource = new LightSource();

                parsedLightSource.Light = new Vector4(lightSource.color.red, lightSource.color.green,
                    lightSource.color.blue, lightSource.lightIntensity);
                parsedLightSource.PositionInWorld = new Vector4(lightSource.position.x,
                    lightSource.position.y, lightSource.position.z, lightSource.position.w);

                parsed.Lights.Add(parsedLightSource);
            }

            parsed.gameObjects = new List<GameObject>();
            foreach (XmlGameObject gameObject in toParse.gameObjects)
            {
                GameObject parsedObject = new GameObject();

                // TODO error handling
                parsedObject.ObjectModelContentName = gameObject.model;

                parsedObject.PositionInWorld = new Vector3(gameObject.position.x,
                    gameObject.position.y, gameObject.position.z);

                parsedObject.RotationAxis = new Vector3(gameObject.rotationAxis.x,
                    gameObject.rotationAxis.y, gameObject.rotationAxis.z);

                parsedObject.ScalingInWorld = gameObject.scaling;

                parsedObject.World = Matrix.Identity;

                parsed.gameObjects.Add(parsedObject);
            }

            return parsed;
        }