Exemplo n.º 1
0
        public LandscapeROAM(SceneContainer scene, String fileName, Vector3 pos, Vector3 scale, int mapSize, int patchSize, bool withVariance)
            : base(scene, pos, Matrix.Identity, scale)
        {
            this.scene    = scene;
            this.fileName = fileName;
            this.scale    = scale;
            if (fileName.Split('.').Length > 1 && fileName.Split('.')[1].ToLower() == "raw")
            {
                this.raw = true;
            }
            else
            {
                this.raw = false;
            }

            this.mapSize           = mapSize;
            this.patchSize         = patchSize;
            this.withVariance      = withVariance;
            this.numPatchesPerSide = mapSize / patchSize;
            triPool = new TriTreeNode[poolSize];
            patches = new PatchROAM[numPatchesPerSide, numPatchesPerSide];
            vb      = new VertexBuffer(scene.Game.GraphicsDevice, typeof(PositionNormalMultiTexture), 50000, BufferUsage.None);
            verts   = new PositionNormalMultiTexture[50000];
            //setObject(pos.X, pos.Y, pos.Z);
            readHeightmap();
            smoothTerrain(1);
            init();
        }
Exemplo n.º 2
0
 public Plane3D(SceneContainer scene, Vector3 pos, Matrix rotation, Vector3 scale, float width, float length)
     : base(scene, pos, rotation, scale)
 {
     this.scene       = scene;
     this.pos         = pos;
     this.width       = width;
     this.length      = length;
     this.counter     = 0.0f;
     this.counterStep = 0.1f;
     this.vb          = new VertexBuffer(scene.Game.GraphicsDevice, typeof(VertexPositionNormalTexture), 6, BufferUsage.None);
     VertexPositionNormalTexture[] verts =
     {
         new VertexPositionNormalTexture(new Vector3(-width, 0.0f, -width), new Vector3(0.0f, 1.0f, 0.0f), new Vector2(0.0f, 1.0f)),
         new VertexPositionNormalTexture(new Vector3(-width, 0.0f, width),  new Vector3(0.0f, 1.0f, 0.0f), new Vector2(0.0f, 0.0f)),
         new VertexPositionNormalTexture(new Vector3(width,  0.0f, width),  new Vector3(0.0f, 1.0f, 0.0f), new Vector2(1.0f, 0.0f)),
         new VertexPositionNormalTexture(new Vector3(width,  0.0f, width),  new Vector3(0.0f, 1.0f, 0.0f), new Vector2(1.0f, 0.0f)),
         new VertexPositionNormalTexture(new Vector3(width,  0.0f, -width), new Vector3(0.0f, 1.0f, 0.0f), new Vector2(1.0f, 1.0f)),
         new VertexPositionNormalTexture(new Vector3(-width, 0.0f, -width), new Vector3(0.0f, 1.0f, 0.0f), new Vector2(0.0f, 1.0f))
     };
     vb.SetData <VertexPositionNormalTexture>(verts);
     setObject(pos.X, pos.Y, pos.Z);
     scaleObject(scale.X, 1.0f, scale.Z);
     //initialize timer
     timer          = new Timer();
     timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
     timer.Enabled  = true;
     timer.Interval = 1;
     timer.Start();
 }
Exemplo n.º 3
0
        public Level3D(SceneContainer scene, Vector3 pos, Matrix rotation, Vector3 scale, bool renderSkybox)
            : base(scene, pos, rotation, scale)
        {
            level          = new Q3BSPLevel(Q3BSPRenderType.BSPCulling); //Q3BSPRenderType.BSPCulling
            level.BasePath = "q3dm1";
            string t = scene.Game.Content.RootDirectory;

            if (level.LoadFromFile(level.BasePath + ".bsp"))
            {
                levelLoaded = level.InitializeLevel(GraphicsDevice, scene.Game.Content, @"q3\scripts\", @"q3\");
            }
            this.renderSkybox = renderSkybox;
            setObject(pos.X, pos.Y, pos.Z);
        }
Exemplo n.º 4
0
 public Skybox(SceneContainer scene, Vector3 pos, Matrix rotation, Vector3 scale, float width, float depth, Object3DSettings renderSettings) : base(scene, pos, rotation, scale, renderSettings)
 {
     this.scene = scene;
     this.width = width;
     this.depth = depth;
     initVertexBuffer();
     // Chapter 4.3.1, Listing 4.3.7
     // load textures
     backTexture   = scene.Game.Content.Load <Texture2D>("Textures/skybox0001");
     frontTexture  = scene.Game.Content.Load <Texture2D>("Textures/skybox0002");
     rightTexture  = scene.Game.Content.Load <Texture2D>("Textures/skybox0003");
     leftTexture   = scene.Game.Content.Load <Texture2D>("Textures/skybox0004");
     topTexture    = scene.Game.Content.Load <Texture2D>("Textures/skybox0005");
     bottomTexture = scene.Game.Content.Load <Texture2D>("Textures/skybox0006");
     //cube = new TextureCube(device, 1, 1, TextureUsage.None, SurfaceFormat.Dxt5);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Chapter 4.3.3, Listing 4.3.19
        /// read heightmap which is an 8 bit greyscale bitmap
        /// </summary>
        /// <param name="device"></param>
        /// <param name="fileName"></param>
        /// <param name="pos"></param>
        public LandscapeGeomipmap(SceneContainer scene, String fileName, Vector3 pos, Matrix rotation, Vector3 scale, ushort mapDetail, ushort mapSize, ushort patchSize, bool doClip)
            : base(scene, pos, rotation, scale)
        {
            this.scene    = scene;
            this.fileName = fileName;
            tempDiffVec   = new Vector3[8];
            tempNormal    = new Vector3[8];
            if (fileName.Split('.').Length > 1 && fileName.Split('.')[1].ToLower() == "raw")
            {
                this.raw = true;
            }
            else
            {
                this.raw = false;
            }
            maxHeight              = getHeightMap(0, 0);
            this.mapSize           = mapSize;
            this.patchSize         = patchSize;
            this.mapDetail         = mapDetail;
            this.numPatchesPerSide = mapSize / patchSize;
            this.doClip            = doClip;
            setObject(pos.X, pos.Y, pos.Z);
            readHeightmap();
            smoothTerrain(3);
            m_Patches = new PatchGeomipmap[numPatchesPerSide, numPatchesPerSide];
            for (int j = 0; j < numPatchesPerSide; j++)
            {
                for (int i = 0; i < numPatchesPerSide; i++)
                {
                    m_Patches[i, j] = new PatchGeomipmap(this, new Vector3(i * patchSize * (int)scale.X, pos.Y, -j * patchSize * (int)scale.Z), Matrix.Identity, i * patchSize, j * patchSize, patchSize, mapSize, mapDetail);
                }
            }
            quadtree = new Quadtree(pos.X, pos.Z, mapSize * (int)scale.X, patchSize * (int)scale.X);
            //compute number of detailmaps

            /*int t = patchSize / 2;
             * while (t >= 1)
             * {
             *  numIndexBuffers++;
             *  t = t / 2;
             * }*/
            // create index buffers
            numIndexBuffers = mapSize / patchSize;
            ib = new IndexBuffer[numIndexBuffers];
            initIndexBuffer();
        }
Exemplo n.º 6
0
        public Model3D(SceneContainer scene, Vector3 pos, Matrix rotation, Vector3 scale, String modelName)
            : base(scene, pos, rotation, scale)
        {
            this.scene     = scene;
            this.modelName = modelName;

            this.saveHeight = pos.Y;
            /* load model */
            model          = scene.Game.Content.Load <Model>(modelName);
            boneTransforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(boneTransforms);
            setObject(pos.X, pos.Y, pos.Z);
            bsLocal = new BoundingSphere();
            foreach (ModelMesh mesh in model.Meshes)
            {
                bsLocal = BoundingSphere.CreateMerged(bsLocal, mesh.BoundingSphere);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Constructs a new projectile.
        /// </summary>
        public Projectile(SceneContainer scene, Vector3 pos, Matrix rotation, Vector3 scale,
                          ParticleSystem explosionParticles,
                          ParticleSystem explosionSmokeParticles,
                          ParticleSystem projectileTrailParticles,
                          Vector3 direction) : base(scene, pos, rotation, scale)
        {
            this.explosionParticles       = explosionParticles;
            this.explosionSmokeParticles  = explosionSmokeParticles;
            this.projectileTrailParticles = projectileTrailParticles;
            this.pos     = pos;
            this.age     = 0.0f;
            this.explode = false;
            bs.Center    = pos;
            bs.Radius    = scale.X;
            velocity.X   = direction.X * sidewaysVelocityRange;
            velocity.Y   = direction.Y * verticalVelocityRange;
            velocity.Z   = direction.Z * sidewaysVelocityRange;

            // Use the particle emitter helper to output our trail particles.
            trailEmitter = new ParticleEmitter(projectileTrailParticles,
                                               trailParticlesPerSecond, pos);
        }
Exemplo n.º 8
0
        public Model3DSkinned(SceneContainer scene, Vector3 pos, Matrix rotation, Vector3 scale, String modelName, String clip)
            : base(scene, pos, rotation, scale)
        {
            this.scene     = scene;
            this.modelName = modelName;

            this.clip    = clip;
            this.animate = false;
            this.jumping = false;
            this.rising  = false;
            model        = scene.Game.Content.Load <Model>(modelName);

            // Look up our custom skinning information.
            skinningData = model.Tag as ModelData;

            if (skinningData != null)
            {
                if (skinningData.RootAnimationClips != null)
                {
                    rootAnimationPlayer = new RootAnimationPlayer();
                }
                if (skinningData.ModelAnimationClips != null)
                {
                    skinnedAnimationPlayer = new SkinnedAnimationPlayer(skinningData.BindPose, skinningData.InverseBindPose, skinningData.SkeletonHierarchy);
                    skinnedAnimationPlayer.StartClip(skinningData.ModelAnimationClips[clip]);
                    boneTransforms = skinnedAnimationPlayer.GetSkinTransforms();
                    skinnedAnimationPlayer.Update(new GameTime(new TimeSpan(), new TimeSpan(2)));
                }
            }
            bsLocal = new BoundingSphere();
            foreach (ModelMesh mesh in model.Meshes)
            {
                bsLocal = BoundingSphere.CreateMerged(bsLocal, mesh.BoundingSphere);
            }
            setObject(pos.X, pos.Y, pos.Z);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Chapter 4.3.3, Listing 4.3.19
        /// read heightmap which is an 8 bit greyscale bitmap
        /// </summary>
        /// <param name="device"></param>
        /// <param name="fileName"></param>
        /// <param name="pos"></param>
        public Landscape(SceneContainer scene, String fileName, Vector3 pos, Vector3 scale, int mapDetail, int mapSize, int patchSize, bool doClip) : base(scene, pos, Matrix.Identity, scale)
        {
            this.scene    = scene;
            this.fileName = fileName;
            tempDiffVec   = new Vector3[8];
            tempNormal    = new Vector3[8];
            if (fileName.Split('.').Length > 1 && fileName.Split('.')[1].ToLower() == "raw")
            {
                this.raw = true;
            }
            else
            {
                this.raw = false;
            }
            maxHeight              = getHeightMap(0, 0);
            this.mapSize           = mapSize;
            this.patchSize         = patchSize;
            this.mapDetail         = mapDetail;
            this.numPatchesPerSide = mapSize / patchSize;
            this.doClip            = doClip;
            setObject(pos.X, pos.Y, pos.Z);
            readHeightmap();
            initVertexBuffer();
            initIndexBuffer();
            fillVertexBuffer();

            m_Patches = new Patch[numPatchesPerSide, numPatchesPerSide];
            for (int j = 0; j < numPatchesPerSide; j++)
            {
                for (int i = 0; i < numPatchesPerSide; i++)
                {
                    m_Patches[i, j] = new Patch(this, i * patchSize, j * patchSize, i * patchSize * (int)scale.X, -j * patchSize * (int)scale.Z, patchSize, mapSize, mapDetail);
                }
            }
            maxVertexBuffer = 0;
        }
Exemplo n.º 10
0
        public Water3D(SceneContainer scene, RenderEngine engine, Vector3 pos, Matrix rotation, Vector3 scale, float xgrid, float zgrid, ushort quadNum)
            : base(scene, pos, rotation, scale)
        {
            this.quadNum = quadNum;
            this.xgrid   = xgrid;
            this.zgrid   = zgrid;
            tempDiffVec  = new Vector3[8];
            tempNormal   = new Vector3[8];

            // Compiler of function code and parser of console commands
            // must have all objects that you want to manipulate
            compiler = new FunctionCompiler(this, engine);

            // initialize vertex buffer
            this.vb   = new VertexBuffer(scene.Game.GraphicsDevice, typeof(VertexPositionNormalTexture), quadNum * quadNum * 6, BufferUsage.None);
            heightmap = new float[quadNum, quadNum];

            worldMatrix = Matrix.Identity;
            transMatrix = Matrix.Identity;

            //initialize timer
            timer          = new Timer();
            timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
            timer.Enabled  = true;
            timer.Interval = timerTick;
            timer.Start();

            //initialize vertices and texture maps
            verts = new VertexPositionNormalTexture[quadNum * quadNum * 6];

            RenderEngine.Compile.OnCompileHandler += new CompileEvent.CompileEventHandler(CompileEventProcessor);
            initVertexBuffer();
            initIndexBuffer();
            setObject(pos.X, pos.Y, pos.Z);
            scaleObject(scale.X, scale.Y, scale.Z);
        }
Exemplo n.º 11
0
 public ProjectileTrailParticleSystem(SceneContainer scene, Vector3 pos, Vector3 scale)
     : base(scene, pos, scale)
 {
 }
Exemplo n.º 12
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public ParticleSystem(SceneContainer scene, Vector3 pos, Vector3 scale) : base(scene, pos, Matrix.Identity, scale)
 {
     this.scene = scene;
 }
Exemplo n.º 13
0
 public virtual void setScene(SceneContainer scene)
 {
     this.scene = scene;
 }
Exemplo n.º 14
0
 public Object3D(SceneContainer scene, Vector3 pos, Matrix rotation, Vector3 scale)
     : this(scene, pos, rotation, scale, null)
 {
 }
Exemplo n.º 15
0
 public Object3D(SceneContainer scene, Vector3 pos, Matrix rotation, Vector3 scale, Object3DSettings renderSettings) : this(pos, rotation, scale, renderSettings)
 {
     scene.addObject(this); //setScene is called in addObject
 }
Exemplo n.º 16
0
 public ExplosionParticleSystem(SceneContainer scene, Vector3 pos, Vector3 scale)
     : base(scene, pos, scale)
 {
 }