Example #1
0
 public void drawme(camera newcam, Boolean lightson)
 {
     if (visible)
     {
         sfunctions3d.drawmodel(position, rotation, size, graphic, transforms, lightson, newcam);
     }
 }
Example #2
0
        // Draw 3D model using Quaternions
        public static void drawmodel(Vector3 position, Vector3 rotation, float scale, Model modelToDraw, Matrix[] transforms, Boolean lightson, camera newcamera)
        {
//            Matrix[] transforms = new Matrix[modelToDraw.Bones.Count];
//            modelToDraw.CopyAbsoluteBoneTransformsTo(transforms);   // get pos of bones in model

            foreach (ModelMesh mesh in modelToDraw.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    if (lightson)
                    {
                        effect.EnableDefaultLighting();                     // Enables default lighting when lightson==TRUE, this can do funny things with textured on 3D models.
                    }
                    effect.PreferPerPixelLighting = true;                   // Makes it shiner and reflects light better
                    effect.World = transforms[mesh.ParentBone.Index] *
                                   Matrix.CreateFromQuaternion(
                        Quaternion.CreateFromAxisAngle(Vector3.Right, rotation.X) *
                        Quaternion.CreateFromAxisAngle(Vector3.Backward, rotation.Z) *
                        Quaternion.CreateFromAxisAngle(Vector3.Up, rotation.Y)) *
                                   Matrix.CreateScale(scale) *
                                   Matrix.CreateTranslation(position);

                    // Set the position of the camera and tell it what to look at
                    effect.View       = Matrix.CreateLookAt(newcamera.position, newcamera.lookAt, newcamera.WhichWayIsUp);
                    effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(newcamera.fov), newcamera.aspectratio, newcamera.nearPlane, newcamera.farPlane);
                }
                mesh.Draw();
            }
        }
Example #3
0
 // This method draws a 3D model with its position and orientation set by the worldmatrix being passed in
 public static void drawmesh(Matrix worldmatrix, Model graphic, Matrix[] transforms, Boolean lightson, camera newcamera)
 {
     foreach (ModelMesh mesh in graphic.Meshes)               // loop through the mesh in the 3d model, drawing each one in turn.
     {
         foreach (BasicEffect effect in mesh.Effects)         // This loop then goes through every effect in each mesh.
         {
             if (lightson)
             {
                 effect.EnableDefaultLighting();                                                                                                                           // Enables default lighting when lightson==TRUE, this can do funny things with textured on 3D models.
             }
             effect.PreferPerPixelLighting = true;                                                                                                                         // Makes it shiner and reflects light better
             effect.World      = transforms[mesh.ParentBone.Index];                                                                                                        // begin dealing with transforms to render the object into the game world
             effect.World     *= worldmatrix;
             effect.View       = Matrix.CreateLookAt(newcamera.position, newcamera.lookAt, newcamera.WhichWayIsUp);                                                        // Set the position of the camera and tell it what to look at
             effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(newcamera.fov), newcamera.aspectratio, newcamera.nearPlane, newcamera.farPlane); // Set Field of View for camera
         }
         mesh.Draw();                                                                                                                                                      // draw the current mesh using the effects.
     }
 }
Example #4
0
        // This method draws a 3D model
        public static void drawmesh(Vector3 position, Vector3 rotation, float scale, Model graphic, Matrix[] transforms, Boolean lightson, camera newcamera)
        {
            // Quaternion rot = Quaternion.Normalize(Quaternion.CreateFromAxisAngle(Vector3.Up, rotation.Y) * Quaternion.CreateFromAxisAngle(Vector3.Right, rotation.X)  * Quaternion.CreateFromAxisAngle(Vector3.Backward, rotation.Z));
            foreach (ModelMesh mesh in graphic.Meshes)               // loop through the mesh in the 3d model, drawing each one in turn.
            {
                foreach (BasicEffect effect in mesh.Effects)         // This loop then goes through every effect in each mesh.
                {
                    if (lightson)
                    {
                        effect.EnableDefaultLighting();                     // Enables default lighting when lightson==TRUE, this can do funny things with textured on 3D models.
                    }
                    effect.PreferPerPixelLighting = true;                   // Makes it shiner and reflects light better
                    effect.World  = transforms[mesh.ParentBone.Index];      // begin dealing with transforms to render the object into the game world
                    effect.World *= Matrix.CreateScale(scale);              // scale the mesh to the right size
                    //effect.World *= Matrix.CreateRotationX(rotation.X);     // rotate the mesh
                    //effect.World *= Matrix.CreateRotationY(rotation.Y);     // rotate the mesh
                    //effect.World *= Matrix.CreateRotationZ(rotation.Z);     // rotate the mesh
                    //effect.World *= Matrix.CreateFromQuaternion(rot);     // Rotate the mesh using Quaternions (This may work better if you are rotating multiple axes)
                    effect.World *= Matrix.CreateFromYawPitchRoll(rotation.Y, rotation.X, rotation.Z);               // rotate the mesh
                    effect.World *= Matrix.CreateTranslation(position);                                              // position the mesh in the game world

                    effect.View = Matrix.CreateLookAt(newcamera.position, newcamera.lookAt, newcamera.WhichWayIsUp); // Set the position of the camera and tell it what to look at

                    // Sets the FOV (Field of View) of the camera. The first paramter is the angle for the FOV, the 2nd is the aspect ratio of your game,
                    // the 3rd is the nearplane distance from the camera and the last paramter is the farplane distance from the camera.
                    effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(newcamera.fov), newcamera.aspectratio, newcamera.nearPlane, newcamera.farPlane);
                }
                mesh.Draw(); // draw the current mesh using the effects.
            }
        }
        // Draw 3D model using Quaternions
        public static void drawmodel(Vector3 position, Vector3 rotation, float scale, Model modelToDraw, Matrix[] transforms, Boolean lightson, camera newcamera)
        {
            //            Matrix[] transforms = new Matrix[modelToDraw.Bones.Count];
            //            modelToDraw.CopyAbsoluteBoneTransformsTo(transforms);   // get pos of bones in model

            foreach (ModelMesh mesh in modelToDraw.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    if (lightson) effect.EnableDefaultLighting();           // Enables default lighting when lightson==TRUE, this can do funny things with textured on 3D models.
                    effect.PreferPerPixelLighting = true;                   // Makes it shiner and reflects light better
                    effect.World = transforms[mesh.ParentBone.Index] *
                        Matrix.CreateFromQuaternion(
                            Quaternion.CreateFromAxisAngle(Vector3.Right, rotation.X) *
                            Quaternion.CreateFromAxisAngle(Vector3.Backward, rotation.Z) *
                            Quaternion.CreateFromAxisAngle(Vector3.Up, rotation.Y)) *
                        Matrix.CreateScale(scale) *
                        Matrix.CreateTranslation(position);

                    // Set the position of the camera and tell it what to look at
                    effect.View = Matrix.CreateLookAt(newcamera.position, newcamera.lookAt, newcamera.WhichWayIsUp);
                    effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(newcamera.fov), newcamera.aspectratio, newcamera.nearPlane, newcamera.farPlane);
                }
                mesh.Draw();
            }
        }
 // This method draws a 3D model with its position and orientation set by the worldmatrix being passed in
 public static void drawmesh(Matrix worldmatrix, Model graphic, Matrix[] transforms, Boolean lightson, camera newcamera)
 {
     foreach (ModelMesh mesh in graphic.Meshes)               // loop through the mesh in the 3d model, drawing each one in turn.
     {
         foreach (BasicEffect effect in mesh.Effects)                // This loop then goes through every effect in each mesh.
         {
             if (lightson) effect.EnableDefaultLighting();           // Enables default lighting when lightson==TRUE, this can do funny things with textured on 3D models.
             effect.PreferPerPixelLighting = true;                   // Makes it shiner and reflects light better
             effect.World = transforms[mesh.ParentBone.Index];       // begin dealing with transforms to render the object into the game world
             effect.World *= worldmatrix;
             effect.View = Matrix.CreateLookAt(newcamera.position, newcamera.lookAt, newcamera.WhichWayIsUp);    // Set the position of the camera and tell it what to look at
             effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(newcamera.fov), newcamera.aspectratio, newcamera.nearPlane, newcamera.farPlane); // Set Field of View for camera
         }
         mesh.Draw(); // draw the current mesh using the effects.
     }
 }
        // This method draws a 3D model
        public static void drawmesh(Vector3 position, Vector3 rotation, float scale, Model graphic, Matrix[] transforms, Boolean lightson, camera newcamera)
        {
            //Quaternion rot = Quaternion.Normalize(Quaternion.CreateFromAxisAngle(Vector3.Up, rotation.Y) * Quaternion.CreateFromAxisAngle(Vector3.Right, rotation.X)  * Quaternion.CreateFromAxisAngle(Vector3.Backward, rotation.Z));
            foreach (ModelMesh mesh in graphic.Meshes)               // loop through the mesh in the 3d model, drawing each one in turn.
            {
                foreach (BasicEffect effect in mesh.Effects)                // This loop then goes through every effect in each mesh.
                {
                    if (lightson) effect.EnableDefaultLighting();           // Enables default lighting when lightson==TRUE, this can do funny things with textured on 3D models.
                    effect.PreferPerPixelLighting = true;                   // Makes it shiner and reflects light better
                    effect.World = transforms[mesh.ParentBone.Index];       // begin dealing with transforms to render the object into the game world
                    effect.World *= Matrix.CreateScale(scale);              // scale the mesh to the right size
                    //effect.World *= Matrix.CreateRotationX(rotation.X);     // rotate the mesh
                    //effect.World *= Matrix.CreateRotationY(rotation.Y);     // rotate the mesh
                    //effect.World *= Matrix.CreateRotationZ(rotation.Z);     // rotate the mesh
                    //                    effect.World *= Matrix.CreateFromAxisAngle(rotaxis, rotamount);
                    //                    effect.World *= Matrix.CreateFromQuaternion(rot);     // Rotate the mesh using Quaternions (This may work better if you are rotating multiple axes)
                    effect.World *= Matrix.CreateFromYawPitchRoll(rotation.Y, rotation.X, rotation.Z); // rotate the mesh
                    effect.World *= Matrix.CreateTranslation(position);     // position the mesh in the game world

                    effect.View = Matrix.CreateLookAt(newcamera.position, newcamera.lookAt, newcamera.WhichWayIsUp);    // Set the position of the camera and tell it what to look at

                    // Sets the FOV (Field of View) of the camera. The first paramter is the angle for the FOV, the 2nd is the aspect ratio of your game, 
                    // the 3rd is the nearplane distance from the camera and the last paramter is the farplane distance from the camera.
                    effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(newcamera.fov), newcamera.aspectratio, newcamera.nearPlane, newcamera.farPlane);
                }
                mesh.Draw(); // draw the current mesh using the effects.
            }
        }
 public void drawme(camera newcam, Boolean lightson)
 {
     if (visible)
         sfunctions3d.drawmodel(position, rotation, size, graphic, transforms, lightson, newcam);
 }
Example #9
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            displaywidth = graphics.GraphicsDevice.Viewport.Width;
            displayheight = graphics.GraphicsDevice.Viewport.Height;
            //graphics.ToggleFullScreen(); // Put game into full screen mode

            gamecamera = new camera(new Vector3(0, 0, 0), new Vector3(0,0,0), displaywidth, displayheight, 45, Vector3.Up, 1000, 20000);

            base.Initialize();
        }
Example #10
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            displaywidth = graphics.GraphicsDevice.Viewport.Width;
            displayheight = graphics.GraphicsDevice.Viewport.Height;
            graphics.ToggleFullScreen();

            accelerometer1.Accelerometer.Initialize();
            gamecamera = new camera(new Vector3(0, 0, 0), new Vector3(0, 0, 0), displaywidth, displayheight, 45, Vector3.Up, 1000, 20000);

            // Initialises Debug shape renderer for drawing bounding boxes and spheres
            DebugShapeRenderer.Initialize(GraphicsDevice);

            base.Initialize();
        }