示例#1
1
文件: frmMain.cs 项目: zulis/Sandbox
        private void SaveX(TVMesh tvm, string fileName)
        {
            ExtendedMaterial[] exMaterials = new ExtendedMaterial[tvm.GetGroupCount()];
            Material dxMaterial;
            int idx = 0;

            for (int group = 0; group < tvm.GetGroupCount(); group++)
            {
                idx = tvm.GetMaterial(group);
                dxMaterial = new Material();
                dxMaterial.AmbientColor = ToDx(core.MaterialFactory.GetAmbient(idx));
                dxMaterial.DiffuseColor = ToDx(core.MaterialFactory.GetDiffuse(idx));
                dxMaterial.EmissiveColor = ToDx(core.MaterialFactory.GetEmissive(idx));
                dxMaterial.SpecularColor = ToDx(core.MaterialFactory.GetSpecular(idx));
                dxMaterial.SpecularSharpness = core.MaterialFactory.GetPower(idx);
                exMaterials[group].Material3D = dxMaterial;
                // Get the Texture Filename.
                idx = tvm.GetTexture(group);
                // Add em to the array.
                exMaterials[group].TextureFilename = core.TextureFactory.GetTextureInfo(idx).Name;
            }

            // Save the Mesh.
            Microsoft.DirectX.Direct3D.Mesh dxMesh = new Microsoft.DirectX.Direct3D.Mesh(core.InternalObjects.GetD3DMesh(tvm.GetIndex()));
            int[] adjacency = new int[dxMesh.NumberFaces * 3];
            dxMesh.GenerateAdjacency(0f, adjacency);
            dxMesh.Save(fileName, adjacency, exMaterials, XFileFormat.Text);
        }
示例#2
0
 public override void Dispose()
 {
     MaterialFactory.DeleteMaterial(materialIdx);
     Physics.DestroyBody(PhysicsId);
     mesh.Destroy();
     mesh = null;
 }
示例#3
0
        //Add a mesh to a tile
        public void AddMeshToTile(WorldPosition Position, TVMesh Mesh)
        {
            int tilei = Position.TileX - WorldPos.TileX + RenderedTilesDistance;
            int tilej = Position.TileX - WorldPos.TileX + RenderedTilesDistance;

            if ((tilei >= 0) && (tilei <= 2 * RenderedTilesDistance) && (tilej >= 0) && (tilej <= 2 * RenderedTilesDistance))
            {
                Mesh.SetPosition(Position.TileX * MapTile.TileSize * 256 + Position.TilePosX, Position.TilePosY, Position.TileZ * MapTile.TileSize * 256 + Position.TilePosZ);
                MapTiles[tilei][tilej].Meshes.Add(Mesh);
            }
        }
示例#4
0
        public void Unload()
        {
            _gameManager.TvPhysics.DestroyBody(_fieldPhysicsBody);
            _field.Destroy();
            _field = null;
            _gameManager.TvMaterials.DeleteMaterial(StandardMaterial);

            _gameManager.TvLights.DeleteLight(_light);

            _gameManager.Player1.Bat.Unload();
            _gameManager.Player2.Bat.Unload();

            Ball.Unload();
        }
示例#5
0
文件: Water.cs 项目: zulis/Cubica
        public override void Initialize()
        {
            ReflectRS = Scene.CreateRenderSurfaceEx(-1, -1, CONST_TV_RENDERSURFACEFORMAT.TV_TEXTUREFORMAT_DEFAULT, true, true, 1);
            ReflectRS.SetBackgroundColor(Globals.RGBA(0f, 0f, 0.1906f, 1f));

            RefractRS = Scene.CreateRenderSurfaceEx(-1, -1, CONST_TV_RENDERSURFACEFORMAT.TV_TEXTUREFORMAT_DEFAULT, true, true, 1);
            RefractRS.SetBackgroundColor(Globals.RGBA(0f, 0f, 0.1906f, 1f));

            mesh = Core.Scene.CreateMeshBuilder();
            mesh.AddFloor(Helpers.GetDUDVTextureFromResource(Core, Resources.water), -256, -256, 256, 256, -3, 2, 2);
            mesh.SetPosition(Position.x, Position.y, Position.z);
            mesh.SetScale(Scale.x, Scale.y, Scale.z);

            plane = new TV_PLANE(Globals.Vector3(0, 1, 0), 3f);
            GraphicEffect.SetWaterReflection(mesh, ReflectRS, RefractRS, 0, plane);
        }
示例#6
0
文件: Water.cs 项目: zulis/Cubica
        public override void Initialize()
        {
            ReflectRS = Scene.CreateRenderSurfaceEx(-1, -1, CONST_TV_RENDERSURFACEFORMAT.TV_TEXTUREFORMAT_DEFAULT, true, true, 1);
            ReflectRS.SetBackgroundColor(Globals.RGBA(0f, 0f, 0.1906f, 1f));

            RefractRS = Scene.CreateRenderSurfaceEx(-1, -1, CONST_TV_RENDERSURFACEFORMAT.TV_TEXTUREFORMAT_DEFAULT, true, true, 1);
            RefractRS.SetBackgroundColor(Globals.RGBA(0f, 0f, 0.1906f, 1f));

            mesh = Core.Scene.CreateMeshBuilder();
            mesh.AddFloor(Helpers.GetDUDVTextureFromResource(Core, Resources.water), -256, -256, 256, 256, -3, 2, 2);
            mesh.SetPosition(Position.x, Position.y, Position.z);
            mesh.SetScale(Scale.x, Scale.y, Scale.z);

            plane = new TV_PLANE(Globals.Vector3(0, 1, 0), 3f);
            GraphicEffect.SetWaterReflection(mesh, ReflectRS, RefractRS, 0, plane);
        }
示例#7
0
        public Trigger(ICore core)
            : base(core)
        {
            this.core = core;
            Name      = core.GetName <Trigger>();
            Color     = new MyColor(0, 255, 0);

            mesh = core.Scene.CreateMeshBuilder();
            mesh.CreateBox(1f, 1f, 1f, false);
            mesh.SetColor(core.Globals.RGBA(Color.R / 255f, Color.G / 255f, Color.B / 255f, 1));
            mesh.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_MANAGED);
            mesh.SetAlphaTest(true);
            mesh.SetBlendingMode(CONST_TV_BLENDINGMODE.TV_BLEND_ADD);

            UniqueId = mesh.GetMeshName();
        }
示例#8
0
文件: Trigger.cs 项目: zulis/Sandbox
        public Trigger(ICore core)
            : base(core)
        {
            this.core = core;
            Name = core.GetName<Trigger>();
            Color = new MyColor(0, 255, 0);

            mesh = core.Scene.CreateMeshBuilder();
            mesh.CreateBox(1f, 1f, 1f, false);
            mesh.SetColor(core.Globals.RGBA(Color.R / 255f, Color.G / 255f, Color.B / 255f, 1));
            mesh.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_MANAGED);
            mesh.SetAlphaTest(true);
            mesh.SetBlendingMode(CONST_TV_BLENDINGMODE.TV_BLEND_ADD);

            UniqueId = mesh.GetMeshName();
        }
示例#9
0
        public PointLight(ICore core, TV_3DVECTOR position)
            : base(core)
        {
            Position   = new VECTOR3D(position.x, position.y, position.z);
            this.Color = new MyColor();
            mesh       = core.Scene.CreateMeshBuilder();
            mesh       = Core.Scene.CreateBillboard(Helpers.GetTextureFromResource(core, Resources.pointLight), position.x, position.y,
                                                    position.z, 1.0f, 1.0f);
            mesh.SetAlphaTest(true);

            UniqueId = mesh.GetMeshName();
            Radius   = 30f;
            LightId  = core.LightEngine.CreatePointLight(position, 1f, 1f, 1f, Radius);
            Core.LightEngine.SetLightProperties(LightId, true, true, true);
            Name = core.GetName <PointLight>();
        }
示例#10
0
        public void RotateZAroundPoint(TV_3DVECTOR point, float angle)
        {
            TVMesh node = Scene.CreateMeshBuilder();

            node.SetPosition(point.x, point.y, point.z);
            mesh.AttachTo(CONST_TV_NODETYPE.TV_NODETYPE_MESH, node.GetIndex(), -1);
            TV_3DVECTOR nodePos = node.GetPosition();
            TV_3DMATRIX mat     = new TV_3DMATRIX();
            TV_3DMATRIX modyMat = node.GetMatrix();

            MathLibrary.TVMatrixRotationZ(ref mat, angle);
            node.SetRotationMatrix(mat);
            mesh.AttachTo(CONST_TV_NODETYPE.TV_NODETYPE_NONE, -1, -1);
            node.Destroy();
            mat = mesh.GetMatrix();
            Physics.SetBodyMatrix(PhysicsId, mat);
        }
示例#11
0
        public void Load()
        {
            // Camera
            _gameManager.TvCamera.SetPosition(100, 150, 50);
            _gameManager.TvCamera.SetLookAt(100, 0, 55);

            // Scene and lighting
            _gameManager.TvScene.SetShadowParameters(_gameManager.TvGlobals.RGBA(0.1f, 0.1f, 0.1f, 0.5f), false);
            _gameManager.TvScene.SetBackgroundColor(0, 0, 0);
            _light = _gameManager.TvLights.CreatePointLight(new TV_3DVECTOR(100, 200, -100), 0.2f, 0.2f, 0.2f, 500);
            _gameManager.TvLights.SetLightProperties(_light, false, true, true);
            _gameManager.TvLights.EnableLight(_light, true);
            StandardMaterial = _gameManager.TvMaterials.CreateLightMaterial(1, 1, 1, 1);

            // Walls and floor. 100 units = 1m
            _field = _gameManager.TvScene.CreateMeshBuilder();
            _field.AddWall3D(0, 0, 50f, 200, 50f, 10f, 100);                              // floor
            _field.AddWall3D(0, 0, 105f, 200, 105f, 20f, 10f, false, false, 0, 0.1f, 1f); // top side
            _field.AddWall3D(0, 0, -5f, 200, -5f, 20f, 10f, false, false, 0, 0.1f, 1f);   // bottom side

            _field.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_NORMAL);
            _field.SetMaterial(StandardMaterial);
            _field.SetShadowCast(true, true);
            _field.ComputeNormalsEx();

            _fieldPhysicsBody = _gameManager.TvPhysics.CreateStaticMeshBody(_field);
            _gameManager.TvPhysics.SetBodyMaterialGroup(_fieldPhysicsBody, 0);

            // Ball
            Ball = new Ball(_gameManager);
            Ball.Load(new TV_3DVECTOR(100f, 20f, 55f));

            // Player 1
            Area player1MoveArea = new Area(20, 25, 50, 75);

            Player1GoalArea   = new Area(-50, 0, 50, 100);
            Player1GoalHeight = -20;
            _gameManager.Player1.Bat.Load(player1MoveArea);

            // Player 2
            Area player2MoveArea = new Area(150, 25, 180, 75);

            Player2GoalArea   = new Area(150, 0, 250, 100);
            Player2GoalHeight = -20;
            _gameManager.Player2.Bat.Load(player2MoveArea);
        }
示例#12
0
        public override void Initialize()
        {
            mesh = Scene.CreateMeshBuilder();

            switch (Helpers.GetFileFormat(FileName))
            {
            case Helpers.FileFormat.TVM:
                mesh.LoadTVM(FileName, true, false);
                break;

            case Helpers.FileFormat.X:
                mesh.LoadXFile(FileName, true, false);
                break;
            }

            if (Visible)
            {
                mesh.EnableFrustumCulling(true, true);
                mesh.ComputeNormals();
                mesh.ComputeBoundings();
                mesh.ComputeOctree();
                mesh.SetAlphaTest(true);
                mesh.SetCullMode(CONST_TV_CULLING.TV_BACK_CULL);
                mesh.SetBlendingMode(CONST_TV_BLENDINGMODE.TV_BLEND_ALPHA);
                mesh.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_MANAGED);
                mesh.SetShadowCast(true, true);

                mesh.SetPosition(Position.x, Position.y, Position.z);
                mesh.SetRotation(Rotation.x, Rotation.y, Rotation.z);
                mesh.SetScale(Scale.x, Scale.y, Scale.z);

                // Physics
                SetPhysics();
            }
            else
            {
                // Hide mesh.
                for (var i = 0; i < mesh.GetGroupCount(); i++)
                {
                    mesh.SetGroupEnable(i, false);
                }
            }

            // Register object in Lua.
            ScriptManager.SetGlobal(Name, this);
        }
示例#13
0
文件: Trigger.cs 项目: zulis/Cubica
        public override void Initialize()
        {
#if DEBUG
            Show = true;
#endif
            TVMesh mesh = Scene.CreateMeshBuilder(Name);
            mesh.CreateBox(1, 1, 1);
            mesh.SetPosition(Position.x, Position.y, Position.z);
            mesh.SetRotation(Rotation.x, Rotation.y, Rotation.z);
            mesh.SetScale(Scale.x, Scale.y, Scale.z);
            mesh.GetBoundingBox(ref boundingBoxMin, ref boundingBoxMax);
            mesh.Destroy();
            mesh = null;

            // Register object in Lua.
            ScriptManager.SetGlobal(Name, this);
        }
示例#14
0
        public Landscape(ICore core)
            : base(core)
        {
            this.core        = core;
            landTextureIdx   = -1;
            heightTextureIdx = -1;

            landTextureIdx = Helpers.GetTextureFromResource(core, Resources.defaultTexture);

            land = core.Scene.CreateLandscape();
            land.GenerateTerrain(Helpers.GetTextureSourceFromResource(core, Resources.defaultHeight), CONST_TV_LANDSCAPE_PRECISION.TV_PRECISION_HIGH, 8, 8, 0, 0, 0);
            land.SetCullMode(CONST_TV_CULLING.TV_BACK_CULL);
            land.ExpandTexture(landTextureIdx, 0, 0, 8, 8);

            mesh = core.Scene.CreateMeshBuilder();

            Name     = "Landscape";
            UniqueId = land.GetName();
        }
示例#15
0
        public void Load(Area moveArea)
        {
            MoveArea = moveArea;

            _mesh = new TVMesh();
            _mesh = _gameManager.TvScene.CreateMeshBuilder();
            _mesh.CreateCylinder(15, 10, 100);

            _mesh.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_NORMAL);
            _mesh.SetMaterial(_gameManager.CurrentLevel.StandardMaterial);
            _mesh.ComputeNormalsEx();
            _mesh.SetShadowCast(true, true);

            _physicsBody = _gameManager.TvPhysics.CreateMeshBody(1000000, _mesh, CONST_TV_PHYSICSBODY_BOUNDING.TV_BODY_CYLINDER);

            _gameManager.TvPhysics.SetBodyMaterialGroup(_physicsBody, 0);

            _gameManager.TvPhysics.SetBodyPosition(_physicsBody, MoveArea.MidPoint.x, 14f, MoveArea.MidPoint.y);
        }
示例#16
0
        public Landscape(ICore core)
            : base(core)
        {
            this.core = core;
            landTextureIdx = -1;
            heightTextureIdx = -1;

            landTextureIdx = Helpers.GetTextureFromResource(core, Resources.defaultTexture);

            land = core.Scene.CreateLandscape();
            land.GenerateTerrain(Helpers.GetTextureSourceFromResource(core, Resources.defaultHeight), CONST_TV_LANDSCAPE_PRECISION.TV_PRECISION_HIGH, 8, 8, 0, 0, 0);
            land.SetCullMode(CONST_TV_CULLING.TV_BACK_CULL);
            land.ExpandTexture(landTextureIdx, 0, 0, 8, 8);

            mesh = core.Scene.CreateMeshBuilder();

            Name = "Landscape";
            UniqueId = land.GetName();
        }
示例#17
0
文件: Sound.cs 项目: zulis/Sandbox
        public Sound(ICore core, string fileName)
            : base(core)
        {
            FileName = fileName;
            Name = core.GetName<Sound>();

            TV_3DVECTOR position = Core.Camera.GetFrontPosition(10.0f);
            Position = new VECTOR3D(position.x, position.y, position.z);
            Is3D = false;
            mySound = core.SoundFactory.Load(fileName, Is3D);
            core.SoundFactory.StopAllSounds();
            mesh = core.Scene.CreateBillboard(Helpers.GetTextureFromResource(core, Resources.sound), position.x, position.y,
                                              position.z, 1.0f, 1.0f);
            mesh.SetAlphaTest(true);
            Stopped = true;
            Loop = false;
            volume = 100;
            UniqueId = mesh.GetMeshName();
        }
示例#18
0
 public Sound(ICore core, string fileName)
     : base(core)
 {
     FileName = fileName;
     Name = core.GetName<Sound>();
     
     TV_3DVECTOR position = Core.Camera.GetFrontPosition(10.0f);
     Position = new VECTOR3D(position.x, position.y, position.z);
     Is3D = false;
     mySound = core.SoundFactory.Load(fileName, Is3D);
     core.SoundFactory.StopAllSounds();
     mesh = core.Scene.CreateBillboard(Helpers.GetTextureFromResource(core, Resources.sound), position.x, position.y,
                                       position.z, 1.0f, 1.0f);
     mesh.SetAlphaTest(true); 
     Stopped = true;
     Loop = false;
     volume = 100;
     UniqueId = mesh.GetMeshName();
 }
示例#19
0
        public DirectionalLight(ICore core, TV_3DVECTOR position)
            : base(core)
        {
            LightId    = -1;
            Position   = new VECTOR3D(position.x, position.y, position.z);
            Direction  = GetDirection();
            this.Color = new MyColor();
            mesh       = core.Scene.CreateMeshBuilder();
            mesh       = Core.Scene.CreateBillboard(Helpers.GetTextureFromResource(core, Resources.directionalLight), position.x, position.y,
                                                    position.z, 1.0f, 1.0f);
            mesh.SetAlphaTest(true);
            UniqueId = mesh.GetMeshName();

            LightId = core.LightEngine.CreateDirectionalLight(new TV_3DVECTOR(Direction.X, Direction.Y, Direction.Z), Color.R / 255f, this.Color.G / 255f, this.Color.B / 255f, Helpers.SUN);
            //core.LightEngine.SetLightAttenuation(LightId, 1f, 0f, 0f);
            //core.LightEngine.SetSpecularLighting(true);
            //core.LightEngine.EnableLight(LightId, true);
            Core.LightEngine.SetLightProperties(LightId, true, true, true);
            Name = "DirectionalLight";
        }
示例#20
0
        public void Load(TV_3DVECTOR startPosition)
        {
            _startPos = startPosition;

            // Mesh
            _mesh = _gameManager.TvScene.CreateMeshBuilder();
            _mesh.CreateSphere(4.5f);

            _mesh.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_NORMAL);
            _mesh.SetMaterial(_gameManager.CurrentLevel.StandardMaterial);
            _mesh.ComputeNormalsEx();

            // Physics
            _physicsBody = _gameManager.TvPhysics.CreateMeshBody(0.01f, _mesh, CONST_TV_PHYSICSBODY_BOUNDING.TV_BODY_BOX);

            _gameManager.TvPhysics.SetBodyMaterialGroup(_physicsBody, 0);
            _gameManager.TvPhysics.SetDamping(_physicsBody, 0.00001f, new TV_3DVECTOR());

            _gameManager.TvPhysics.SetBodyPosition(_physicsBody, _startPos.x, _startPos.y, _startPos.z);
        }
示例#21
0
        public DirectionalLight(ICore core, TV_3DVECTOR position)
            : base(core)
        {
            LightId = -1;
            Position = new VECTOR3D(position.x, position.y, position.z);
            Direction = GetDirection();
            this.Color = new MyColor();
            mesh = core.Scene.CreateMeshBuilder();
            mesh = Core.Scene.CreateBillboard(Helpers.GetTextureFromResource(core, Resources.directionalLight), position.x, position.y,
                                             position.z, 1.0f, 1.0f);
            mesh.SetAlphaTest(true);
            UniqueId = mesh.GetMeshName();

            LightId = core.LightEngine.CreateDirectionalLight(new TV_3DVECTOR(Direction.X, Direction.Y, Direction.Z), Color.R / 255f, this.Color.G / 255f, this.Color.B / 255f, Helpers.SUN);
            //core.LightEngine.SetLightAttenuation(LightId, 1f, 0f, 0f);
            //core.LightEngine.SetSpecularLighting(true);
            //core.LightEngine.EnableLight(LightId, true);
            Core.LightEngine.SetLightProperties(LightId, true, true, true);
            Name = "DirectionalLight";
        }
示例#22
0
文件: Water.cs 项目: zulis/Sandbox
        public Water(ICore core)
            : base(core)
        {
            this.core = core;

            ReflectRS = core.Scene.CreateRenderSurfaceEx(-1, -1, CONST_TV_RENDERSURFACEFORMAT.TV_TEXTUREFORMAT_DEFAULT, true, true, 1);
            ReflectRS.SetBackgroundColor(core.Globals.RGBA(0f, 0f, 0.1906f, 1f));

            RefractRS = core.Scene.CreateRenderSurfaceEx(-1, -1, CONST_TV_RENDERSURFACEFORMAT.TV_TEXTUREFORMAT_DEFAULT, true, true, 1);
            RefractRS.SetBackgroundColor(core.Globals.RGBA(0f, 0f, 0.1906f, 1f));

            mesh = core.Scene.CreateMeshBuilder();
            mesh.AddFloor(Helpers.GetDUDVTextureFromResource(core, Resources.water), -256, -256, 256, 256, -3, 2, 2);

            plane = new TV_PLANE(core.Globals.Vector3(0, 1, 0), 3f);
            core.GraphicEffect.SetWaterReflection(mesh, ReflectRS, RefractRS, 0, plane);

            Name = core.GetName<Water>();
            UniqueId = mesh.GetMeshName();
        }
示例#23
0
文件: Helpers.cs 项目: zulis/Sandbox
        public static void SetTextureFromResource(ICore core, TVMesh mesh, Bitmap texture, int groupID)
        {
            var ms = new MemoryStream();

            texture.Save(ms, ImageFormat.Png);
            var data = new byte[ms.Length];

            ms.Seek(0, 0);
            data = ms.ToArray();
            ms.Dispose();
            texture.Dispose();
            GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
            int      addr   = handle.AddrOfPinnedObject().ToInt32();

            handle.Free();
            string ds    = core.Globals.GetDataSourceFromMemory(addr, data.Length - 1);
            int    texID = core.TextureFactory.LoadTexture(ds);

            mesh.SetTexture(texID, groupID);
        }
示例#24
0
文件: Water.cs 项目: zulis/Sandbox
        public Water(ICore core)
            : base(core)
        {
            this.core = core;

            ReflectRS = core.Scene.CreateRenderSurfaceEx(-1, -1, CONST_TV_RENDERSURFACEFORMAT.TV_TEXTUREFORMAT_DEFAULT, true, true, 1);
            ReflectRS.SetBackgroundColor(core.Globals.RGBA(0f, 0f, 0.1906f, 1f));

            RefractRS = core.Scene.CreateRenderSurfaceEx(-1, -1, CONST_TV_RENDERSURFACEFORMAT.TV_TEXTUREFORMAT_DEFAULT, true, true, 1);
            RefractRS.SetBackgroundColor(core.Globals.RGBA(0f, 0f, 0.1906f, 1f));

            mesh = core.Scene.CreateMeshBuilder();
            mesh.AddFloor(Helpers.GetDUDVTextureFromResource(core, Resources.water), -256, -256, 256, 256, -3, 2, 2);

            plane = new TV_PLANE(core.Globals.Vector3(0, 1, 0), 3f);
            core.GraphicEffect.SetWaterReflection(mesh, ReflectRS, RefractRS, 0, plane);

            Name     = core.GetName <Water>();
            UniqueId = mesh.GetMeshName();
        }
示例#25
0
文件: Particle.cs 项目: zulis/Sandbox
        //[Browsable(false)]
        //public override VECTOR3D Rotation { get; set; }
        public Particle(ICore core, string fileName)
            : base(core)
        {
            this.core = core;
            FileName = fileName;
            Visible = true;
            Name = core.GetName<Particle>();

            TV_3DVECTOR position = Core.Camera.GetFrontPosition(10.0f);
            Position = new VECTOR3D(position.x, position.y, position.z);
            mesh = core.Scene.CreateBillboard(Helpers.GetTextureFromResource(core, Resources.particleBig), position.x, position.y,
                                              position.z, 1.0f, 1.0f);
            mesh.SetAlphaTest(true);

            particle = core.Scene.CreateParticleSystem();
            particle.Load(fileName);
            particle.SetGlobalPosition(Position.X, Position.Y, Position.Z);
            particle.SetGlobalRotation(Rotation.X, Rotation.Y, Rotation.Z);
            particle.SetGlobalScale(Scale.X, Scale.Y, Scale.Z);

            UniqueId = mesh.GetMeshName();
        }
示例#26
0
        //[Browsable(false)]
        //public override VECTOR3D Rotation { get; set; }

        public Particle(ICore core, string fileName)
            : base(core)
        {
            this.core = core;
            FileName  = fileName;
            Visible   = true;
            Name      = core.GetName <Particle>();

            TV_3DVECTOR position = Core.Camera.GetFrontPosition(10.0f);

            Position = new VECTOR3D(position.x, position.y, position.z);
            mesh     = core.Scene.CreateBillboard(Helpers.GetTextureFromResource(core, Resources.particleBig), position.x, position.y,
                                                  position.z, 1.0f, 1.0f);
            mesh.SetAlphaTest(true);

            particle = core.Scene.CreateParticleSystem();
            particle.Load(fileName);
            particle.SetGlobalPosition(Position.X, Position.Y, Position.Z);
            particle.SetGlobalRotation(Rotation.X, Rotation.Y, Rotation.Z);
            particle.SetGlobalScale(Scale.X, Scale.Y, Scale.Z);

            UniqueId = mesh.GetMeshName();
        }
示例#27
0
文件: Mesh.cs 项目: zulis/Sandbox
        public Mesh(ICore core, ProgramSettings settings, string fileName)
            : base(core)
        {
            this.core     = core;
            this.settings = settings;

            mass            = 0f;
            staticFriction  = 0.9f;
            kineticFriction = 0.5f;
            softness        = 0.1f;
            bounciness      = 0.1f;
            materialIdx     = -1;
            SetMaterialToCustom();

            FileName      = fileName;
            customTexture = string.Empty;
            //Name = fileName.Split(new[] { '\\' }).Last();
            PhysicsId = -1;

            enableLightning = true;

            Name = core.GetName <Mesh>();
            string ending = fileName.Split(new[] { '\\' }).Last().ToUpper();

            mesh = core.Scene.CreateMeshBuilder();

            if (ending.EndsWith(Helpers.GetFileExtension(Helpers.FileFormat.TVM)))
            {
                mesh.LoadTVM(fileName, true, false);
            }
            else if (ending.EndsWith(Helpers.GetFileExtension(Helpers.FileFormat.X)))
            {
                mesh.LoadXFile(fileName, true, false);
            }
            else if (ending.EndsWith(Helpers.GetFileExtension(Helpers.FileFormat.TVA)))
            {
                TVActor actor = core.Scene.CreateActor();
                actor.Load(fileName, true, false);
                mesh = actor.GetDeformedMesh();
                core.Scene.DestroyAllActors();
                IsAnimated = true;
            }
            else
            {
                return;
            }

            mesh.EnableFrustumCulling(true, true);
            mesh.ComputeNormals();
            mesh.ComputeBoundings();
            mesh.ComputeOctree();
            mesh.SetCullMode(CONST_TV_CULLING.TV_BACK_CULL);
            mesh.SetBlendingMode(CONST_TV_BLENDINGMODE.TV_BLEND_ALPHA);
            mesh.SetAlphaTest(true);
            mesh.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_MANAGED);
            mesh.SetShadowCast(true, true);
            lightmapIdx = mesh.GetTextureEx((int)CONST_TV_LAYER.TV_LAYER_LIGHTMAP);

            textureScale = new UV(1.0f, 1.0f);

            LoadTextures();

            UniqueId = mesh.GetMeshName();
        }
示例#28
0
		public void Delete() {
			Engine.TV3DScene.DestroyMesh( ref _mesh );
			_mesh = null;
		}
示例#29
0
 public void Delete()
 {
     Engine.TV3DScene.DestroyMesh(ref _mesh);
     _mesh = null;
 }
示例#30
0
文件: Mesh.cs 项目: zulis/Cubica
 public override void Dispose()
 {
     MaterialFactory.DeleteMaterial(materialIdx);
     Physics.DestroyBody(PhysicsId);
     mesh.Destroy();
     mesh = null;
 }
示例#31
0
 public void Unload()
 {
     _gameManager.TvPhysics.DestroyBody(_physicsBody);
     _mesh.Destroy();
     _mesh = null;
 }
示例#32
0
        //Akce tlacitka nove hry
        private void TSMINova_Click(object sender, EventArgs e)
        {
            MatFactory.DeleteAllMaterials();
            TexFactory.DeleteAllTextures();
            Room.Destroy();
            Obj1.Destroy();

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    Pole[i, j].mesh.Destroy();
                }
            }

            Room = null;
            Obj1 = null;
            Pole = null;
            if(LFC != null)
                foreach (Figurka item in LFC)
                {
                    item.mesh.Destroy();
                }
            if (LFB != null)
                foreach (Figurka item in LFB)
                {
                    item.mesh.Destroy();
                }

            LFC.Clear();
            LFB.Clear();
            LPOznac.Clear();
            LPSkok.Clear();
            LPSmaz.Clear();
            LPTah.Clear();
            label3.Text = "";
            label4.Text = "";
            label5.Text = "";

            NastavPromenne();
            VyvorMistnost();
            xc = -75.0f;
            yc = -27.0f;
            zc = 21.0f;
            VytvorSachovnici(xc, yc, zc);
            NoveFigurky();

            NastavKameru();

            Pause = false;
        }
示例#33
0
文件: Mesh.cs 项目: zulis/Sandbox
        public Mesh(ICore core, ProgramSettings settings, string fileName)
            : base(core)
        {
            this.core = core;
            this.settings = settings;

            mass = 0f;
            staticFriction = 0.9f;
            kineticFriction = 0.5f;
            softness = 0.1f;
            bounciness = 0.1f;
            materialIdx = -1;
            SetMaterialToCustom();

            FileName = fileName;
            customTexture = string.Empty;
            //Name = fileName.Split(new[] { '\\' }).Last();
            PhysicsId = -1;

            enableLightning = true;

            Name = core.GetName<Mesh>();
            string ending = fileName.Split(new[] { '\\' }).Last().ToUpper();
            mesh = core.Scene.CreateMeshBuilder();

            if (ending.EndsWith(Helpers.GetFileExtension(Helpers.FileFormat.TVM)))
            {
                mesh.LoadTVM(fileName, true, false);
            }
            else if (ending.EndsWith(Helpers.GetFileExtension(Helpers.FileFormat.X)))
            {
                mesh.LoadXFile(fileName, true, false);
            }
            else if (ending.EndsWith(Helpers.GetFileExtension(Helpers.FileFormat.TVA)))
            {
                TVActor actor = core.Scene.CreateActor();
                actor.Load(fileName, true, false);
                mesh = actor.GetDeformedMesh();
                core.Scene.DestroyAllActors();
                IsAnimated = true;
            }
            else
                return;

            mesh.EnableFrustumCulling(true, true);
            mesh.ComputeNormals();
            mesh.ComputeBoundings();
            mesh.ComputeOctree();
            mesh.SetCullMode(CONST_TV_CULLING.TV_BACK_CULL);
            mesh.SetBlendingMode(CONST_TV_BLENDINGMODE.TV_BLEND_ALPHA);
            mesh.SetAlphaTest(true);
            mesh.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_MANAGED);
            mesh.SetShadowCast(true, true);
            lightmapIdx = mesh.GetTextureEx((int)CONST_TV_LAYER.TV_LAYER_LIGHTMAP);

            textureScale = new UV(1.0f, 1.0f);

            LoadTextures();

            UniqueId = mesh.GetMeshName();
        }
示例#34
0
        //Metoda vracejici vytvoreny cylinder
        private TVMesh Cylinder(float Radius, float Height, int Sides, float xm, float ym, float zm, int textureVyskaNasobek, int textureSirkaNasobek)
        {
            TVMesh p = new TVMesh();
            p = Scene.CreateMeshBuilder();
            //Scene.SetRenderMode(CONST_TV_RENDERMODE.TV_LINE);

            double Theta;
            float Inc;
            float x, y, z;
            TV_3DVECTOR n;
            float tu, tv;
            float UStep;
            int sign;

            p.SetPrimitiveType(CONST_TV_PRIMITIVETYPE.TV_TRIANGLESTRIP);
            Inc = (float)((2 * Math.PI) / Sides);
            Theta = 0;
            UStep = (float)(1 / (float)Sides);
            tu = 0;
            sign = -1;

            //Making bottom cap
            for (int i = 1; i <= Sides; i++)
            {
                x = Radius * (float)Math.Cos(sign * Theta);
                y = Height;
                z = Radius * (float)Math.Sin(sign * Theta);

                tu = 0.5f * (float)Math.Cos(sign * Theta) + 0.5f;
                tv = 0.5f * (float)Math.Sin(sign * Theta) + 0.5f;

                p.AddVertex(x - xm, 0 - ym, z - zm, 0, -1, 0, tu, tv);

                if (sign == 1)
                    sign = -1;
                else
                {
                    sign = 1;
                    Theta = Theta + Inc;
                }

            }

            // Making cylinder
            for (int i = 0; i <= Sides; i++)
            {
                x = Radius * (float)Math.Cos(Theta);
                y = Height;
                z = Radius * (float)Math.Sin(Theta);

                n = new TV_3DVECTOR(x, 0, y);
                p.AddVertex(x - xm, 0 - ym, z - zm, n.x, n.y, n.z, 0, 0);
                p.AddVertex(x - xm, y - ym, z - zm, n.x, n.y, n.z, 0, 0);
                Theta = Theta + Inc;

                tu = tu + UStep * textureSirkaNasobek;

            }

            Theta = Math.PI;
            sign = 1;
            //Making top cap
            for (int i = 1; i <= Sides; i++)
            {
                x = Radius * (float)Math.Cos(sign * Theta);
                y = Height;
                z = Radius * (float)Math.Sin(sign * Theta);

                tu = 0.5f * (float)Math.Cos(sign * Theta) + 0.5f;
                tv = 0.5f * (float)Math.Sin(sign * Theta) + 0.5f;

                p.AddVertex(x - xm, y - ym, z - zm, 0, 1, 0, tu, tv);

                if (sign == 1)
                {
                    sign = -1;
                    Theta = Theta + Inc;
                }
                else
                    sign = 1;

            }

            return p;
        }
示例#35
0
        //Inicializace a vytvoreni mistnosti
        private void VyvorMistnost()
        {
            //Inicializace mistnosti
            Room = Scene.CreateMeshBuilder("RoomMesh");

            //Nacteni textur
            VytvorTextury();

            //Pridani sten a nastaveni pozice mistnosti
            Room.AddWall3D(Globals.GetTex("Wall"), 150.0f, -350.0f, -350.0f, -350.0f, 350.0f, 5.0f, false, false, -50.0f, 5.0f, 5.0f);
            Room.AddWall3D(Globals.GetTex("Wall"), -350.0f, -350.0f, -350.0f, 150.0f, 350.0f, 5.0f, false, false, -50.0f, 5.0f, 5.0f);
            Room.AddWall3D(Globals.GetTex("Wall"), -350.0f, 150.0f, 150.0f, 150.0f, 350.0f, 5.0f, false, false, -50.0f, 5.0f, 5.0f);
            Room.AddWall3D(Globals.GetTex("Wall"), 150.0f, 150.0f, 150.0f, -350.0f, 350.0f, 5.0f, false, false, -50.0f, 5.0f, 5.0f);
            Room.AddFloor(Globals.GetTex("Floor"), -350.0f, -350f, 150.0f, 150.0f, -50.0f, 20.0f, 20.0f, true);
            Room.AddFloor(Globals.GetTex("Floor"), -350.0f, -350.0f, 150.0f, 150.0f, 300.0f, 10.0f, 10.0f, true);
            Room.SetPosition((float)30.0f, (float)-30.0f, (float)150.0f);

            //Pridani stolku
            Obj1 = new TVMesh();
            Obj1 = Scene.CreateMeshBuilder("Obj1");
            Obj1.LoadXFile("Meshe\\stul.x", true, true);
            Obj1.SetPosition(-57.0f, -80.0f, 38.0f);
            Obj1.SetTexture(Globals.GetTex("Wood"), -1);
            Obj1.SetMeshName("other");

            Obj2 = new TVMesh();
            Obj2 = Scene.CreateMeshBuilder("Obj2");
            Obj2.LoadXFile("Meshe\\okraj.x", true, true);
            Obj2.SetPosition(xc + 17.5f, yc - 1.0f, zc + 17.5f);
            Obj2.SetTexture(Globals.GetTex("Wood2"), -1);
            Obj2.SetMeshName("other");
        }
示例#36
0
 //Add a mesh to a tile
 public void AddMeshToTile(WorldPosition Position, TVMesh Mesh)
 {
     int tilei = Position.TileX - WorldPos.TileX + RenderedTilesDistance;
     int tilej = Position.TileX - WorldPos.TileX + RenderedTilesDistance;
     if ((tilei >= 0) && (tilei <= 2 * RenderedTilesDistance) && (tilej >= 0) && (tilej <= 2 * RenderedTilesDistance))
     {
         Mesh.SetPosition(Position.TileX * MapTile.TileSize * 256 + Position.TilePosX, Position.TilePosY, Position.TileZ * MapTile.TileSize * 256 + Position.TilePosZ);
         MapTiles[tilei][tilej].Meshes.Add(Mesh);
     }
 }
示例#37
0
文件: Helpers.cs 项目: zulis/Sandbox
 public static void SetTextureFromResource(ICore core, TVMesh mesh, Bitmap texture, int groupID)
 {
     var ms = new MemoryStream();
     texture.Save(ms, ImageFormat.Png);
     var data = new byte[ms.Length];
     ms.Seek(0, 0);
     data = ms.ToArray();
     ms.Dispose();
     texture.Dispose();
     GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
     int addr = handle.AddrOfPinnedObject().ToInt32();
     handle.Free();
     string ds = core.Globals.GetDataSourceFromMemory(addr, data.Length - 1);
     int texID = core.TextureFactory.LoadTexture(ds);
     mesh.SetTexture(texID, groupID);
 }
示例#38
0
        private void InitObjects()
        {
            #region Car
            //Building PK9
            pk_9 = scene.CreateMeshBuilder("pk");
            // load the object from an x file
            pk_9.LoadTVM(@"Models\pk8.tvm", false, false);
            // set its position
            pk_9.SetPosition(5.0f, 0.0f, 50.0f);
            // make the table 3x larger
            pk_9.SetScale(3, 3, 3);
            // rotate it 25 degrees around the Y 3D Axis
            pk_9.RotateY(25, true);
            // set the tables texture
            pk_9.SetShadowCast(true, true);
            pk_9.SetTexture(globals.GetTex("pk9tex"), 0);

            //Chassis
            m_chassis = scene.CreateMeshBuilder("mChassis");
            m_chassis.LoadTVM(@"Models\chassis.tvm", false, false);
            m_chassis.SetShadowCast(true, true);
            m_chassis.SetTexture(globals.GetTex("ChassisSTI"), 0);
            //m_chassis.SetTextureEx(0, globals.GetTex("ChassisSTI"), 1);
            //m_chassis.SetTextureEx(1, globals.GetTex("ChassisSTI"), 1);
            m_chassis.SetTexture(globals.GetTex("UnderCarriage"), 2);
            m_chassis.SetMaterial(matWindow, 1);
            m_chassis.SetAlphaTest(true, 0, true, 1);
            m_chassis.SetBlendingMode(CONST_TV_BLENDINGMODE.TV_BLEND_ADD, 1);
            m_chassis.SetCullMode(CONST_TV_CULLING.TV_DOUBLESIDED);
            m_chassis.SetShadowCast(true, true);

            //Front Left Wheel
            float scale = 1f;
            m_fl = scene.CreateMeshBuilder("mfl");
            m_fl.LoadTVM(@"Models\wheel_l.tvm", true, true);
            m_fl.SetScale(scale, scale, scale);
            m_fl.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_MANAGED);
            m_fl.SetMaterial(matWheels);
            m_fl.SetTexture(globals.GetTex("Wheel"));
            m_fl.SetCullMode(CONST_TV_CULLING.TV_DOUBLESIDED);
            m_fl.SetShadowCast(true, true);

            //Front Right Wheel
            m_rl = scene.CreateMeshBuilder("mrl");
            m_rl.LoadTVM(@"Models\wheel_l.tvm", true, true);
            m_rl.SetScale(scale, scale, scale);
            m_rl.SetMaterial(matWheels);
            m_rl.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_MANAGED);
            m_rl.SetTexture(globals.GetTex("Wheel"));
            m_rl.SetCullMode(CONST_TV_CULLING.TV_DOUBLESIDED);
            m_rl.SetShadowCast(true, false);
            m_rl.SetShadowCast(true, true);

            //Rear Left Wheel
            m_fr = scene.CreateMeshBuilder("mfr");
            m_fr.LoadTVM(@"Models\wheel_r.tvm", true, true);
            m_fr.SetScale(scale, scale, scale);
            m_fr.SetMaterial(matWheels);
            m_fr.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_MANAGED);
            m_fr.SetTexture(globals.GetTex("Wheel"));
            m_fr.SetCullMode(CONST_TV_CULLING.TV_DOUBLESIDED);
            m_fr.SetShadowCast(true, false);

            //Rear Right Wheel
            m_rr = scene.CreateMeshBuilder("mrr");
            m_rr.LoadTVM(@"Models\wheel_r.tvm", true, true);
            m_rr.SetScale(scale, scale, scale);
            m_rr.SetMaterial(matWheels);
            m_rr.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_MANAGED);
            m_rr.SetTexture(globals.GetTex("Wheel"));
            m_rr.SetCullMode(CONST_TV_CULLING.TV_DOUBLESIDED);
            m_rr.SetShadowCast(true, false);
            m_rr.SetShadowCast(true, true);

            m_chassis.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_MANAGED);
            m_chassis.SetMaterial(matVehicleBody);
            m_chassis.ComputeNormals();
            m_chassis.ComputeBoundings();
            m_chassis.SetScale(scale, scale, scale);
            #endregion

            //Add The Physics to the chassis
            pbi_chassis = physics.CreateMeshBody(1500, m_chassis, CONST_TV_PHYSICSBODY_BOUNDING.TV_BODY_CONVEXHULL); //1500
            physics.SetAutoFreeze(pbi_chassis, false);
            physics.SetBodyPosition(pbi_chassis, 0f, 15, 0f);
            physics.SetBodyRotation(pbi_chassis, 0f, 0f, 0f);

            //Create The Vehicle
            car_ID = physics.CreateVehicle(pbi_chassis);

            //Do Suspention Settings
            float susheight = 1.5f; //distance from chassis to wheel 0.5f
            float susplen = 1.5f; // 10
            float susshock = 40f; //Springiness of suspension 10
            float susspring = 300f; //Stiffness of suspension 400
            flw = physics.AddVehicleWheelEx(car_ID, 25f, 0.5f * scale, 0.372f * scale+0.1f, new TV_3DVECTOR(1, 0, 0), -0.8f * scale, -susheight * scale - 0.1f, 1.25f * scale + 0.5f, 1, 0, 0, susplen, susshock, susspring, m_fl); //fl
            frw = physics.AddVehicleWheelEx(car_ID, 25f, 0.5f * scale, 0.372f * scale+0.1f, new TV_3DVECTOR(1, 0, 0), 0.8f * scale, -susheight * scale - 0.1f, 1.25f * scale + 0.5f, 1, 0, 0, susplen, susshock, susspring, m_fr); //fr
            rlw = physics.AddVehicleWheelEx(car_ID, 25f, 0.5f * scale, 0.372f * scale+0.1f, new TV_3DVECTOR(1, 0, 0), -0.8f * scale, -susheight * scale - 0.1f, -1.425f * scale + 0.2f, 1, 0, 0, susplen, susshock, susspring, m_rl); //rl
            rrw = physics.AddVehicleWheelEx(car_ID, 25f, 0.5f * scale, 0.372f * scale+0.1f, new TV_3DVECTOR(1, 0, 0), 0.8f * scale, -susheight * scale - 0.1f, -1.425f * scale + 0.2f, 1, 0, 0, susplen, susshock, susspring, m_rr); //rr

            //Change the car's center of mass / make it drive better
            physics.SetBodyCenterOfMass(car_ID, new TV_3DVECTOR(0, -1.0f, 10f));

            //Add wheel frictions
            //Note that this code will also stop sliding on slopes
            float sideslip = 0.1f;
            float sideslipcoef = 0f;
            float maxlongslide = 10000f;
            float maxlongslidecoef = 0f;
            physics.SetVehicleWheelParameters(car_ID, flw, sideslip, sideslipcoef, maxlongslide, maxlongslidecoef);
            physics.SetVehicleWheelParameters(car_ID, frw, sideslip, sideslipcoef, maxlongslide, maxlongslidecoef);
            physics.SetVehicleWheelParameters(car_ID, rlw, sideslip, sideslipcoef, maxlongslide, maxlongslidecoef);
            physics.SetVehicleWheelParameters(car_ID, rrw, sideslip, sideslipcoef, maxlongslide, maxlongslidecoef);
        }
        //*** Render Method
        private void SetupScene(IntPtr hWnd)
        {
            TV_3DVECTOR Min = new TV_3DVECTOR();
            TV_3DVECTOR Max = new TV_3DVECTOR();
            TV_3DVECTOR Offset = new TV_3DVECTOR();
            TV_3DVECTOR SphereCenter = new TV_3DVECTOR();
            TV_3DVECTOR posVector = new TV_3DVECTOR();

            TV = new TVEngine();
            Scene = new TVScene();
            Cam = new TVCamera();
            TF = new TVTextureFactory();
            Mats = new TVMaterialFactory();
            Lights = new TVLightEngine();
            Maths = new TVMathLibrary();

            //Initialize the TV engine
            TV.SetDebugFile(Application.StartupPath + "\\debug.txt");
            TV.Init3DWindowed(hWnd, true);
            TV.SetSearchDirectory(Application.StartupPath);
            TV.SetAngleSystem(CONST_TV_ANGLE.TV_ANGLE_DEGREE);  // use degree system

            Scene.SetBackgroundColor(0.6f, 0.6f, 0.6f);

            //Load the texture into the integer ID holder
            FloorTex = TF.LoadTexture("smallGrid.bmp", "Grid", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_NO, true);
            WallTex = TF.LoadTexture("smallGridWall.bmp", "Wall", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_NO, true);

            Room = Scene.CreateMeshBuilder("Room");
            Room.AddFloor(FloorTex, -300.0f, -300.0f, 300.0f, 300.0f, 0, 15.0f, 15.0f, true);
            Room.AddWall(WallTex, -300.0f, 300.0f, 300.0f, 300.0f, 400.0f, 0, 15.0f, 15.0f, true);
            Room.AddWall(WallTex, 300.0f, -300.0f, -300.0f, -300.0f, 400.0f, 0, 15.0f, 15.0f, true);
            Room.AddWall(WallTex, 300.0f, 300.0f, 300.0f, -300.0f, 400.0f, 0, 15.0f, 15.0f, true);
            Room.AddWall(WallTex, -300.0f, -300.0f, -300.0f, 300.0f, 400.0f, 0, 15.0f, 15.0f, true);
            //ShowVector("RoomLocal", Room.GetPosition());
            //ShowVector("RoomWorld", Room.GetWorldPosition(Room.GetPosition()));

            SensorNode = Scene.CreateMeshBuilder("SensorNode");
            SensorNode.LoadXFile("N70.X", true, true);
            SensorNode.SetParent(CONST_TV_NODETYPE.TV_NODETYPE_MESH, Room.GetIndex(), 1);
            SensorNode.SetPosition(0.0f, 150.0f, 0.0f);
            TV_3DVECTOR oriScale = SensorNode.GetScale();
            SensorNode.SetScale(oriScale.x, oriScale.y, oriScale.z * 1.5f);
            SensorNode.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_NORMAL, 0, 1);
            SensorNode.SetRotation(90.0f, 0.0f, 0.0f);
            //SensorNode.GetBoundingBox(ref Min, ref Max, true);
            //SensorNode.ShowBoundingBox(true);
            //ShowVector("MoteLocal", SensorNode.GetPosition());
            //ShowVector("MoteWorld", Room.GetWorldPosition(SensorNode.GetPosition()));

            //WiimoteMesh = Scene.CreateMeshBuilder("Wiimote");
            //WiimoteMesh.LoadXFile("Wiimote.X", true, true);
            //TV_3DVECTOR oriScale = WiimoteMesh.GetScale();
            //WiimoteMesh.SetScale(oriScale.x * 0.15f, oriScale.y * 0.15f, oriScale.z * 0.15f);
            //WiimoteMesh.SetPosition(0.0f, 70.0f, 0.0f);
            //WiimoteMesh.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_NORMAL, 0, 1);//Tell TV we want normal, per-vertex, lighting with 1 point light.

            Cam.SetParent(CONST_TV_NODETYPE.TV_NODETYPE_MESH, Room.GetIndex(), 0);
            Cam.SetPosition(0.0f, 250.0f, 200.0f);
            Cam.LookAtMesh(SensorNode);
            //ShowVector("CamLocal", Cam.GetPosition());
            //ShowVector("CamWorld", Room.GetWorldPosition(Cam.GetPosition()));

            //Create a point light. Again, these can be more complex.
            IDLight = Lights.CreatePointLight(new TV_3DVECTOR(0.0f, 250.0f, 200.0f), 0.9f, 0.9f, 0.9f, 250.0f);
            IDBackLight = Lights.CreatePointLight(new TV_3DVECTOR(0.0f, 250.0f, -200.0f), 0.1f, 0.1f, 0.1f, 250.0f);
            Lights.SetSpecularLighting(false);
        }
示例#40
0
        public void Init()
        {
            //bool DebugToConsole = true;

            // We have to create the TV object before anything else.
            TV = new TVEngine();

            // Set the search directory of the objects, textures, ...
            TV.SetSearchDirectory(Application.StartupPath);

            // We put the debug file in the app directory
            //TV.SetDebugFile(Application.StartupPath + "\\WorldEngine-Debug.txt");
            //TV.SetDebugMode(true, true, DebugToConsole);
            TV.SetDebugMode(false, false, false, false);

            // We initialize TV in the picture box of the form.
            TV.Init3DWindowed(GameHandle);

            // We want to see the FPS.
            TV.DisplayFPS(true);

            // We create the TVGlobals object.
            Globals = new TVGlobals();

            // We create the input object.
            InputEngine = new TVInputEngine();
            InputEngine.Initialize();

            // New : we create the graphic object so we can add some fog.
            GraphicFX = new TVGraphicEffect();

            // We create the scene (the world).
            Scene = new TVScene();
            //Scene.SetViewFrustum(45, 20000);
            //Scene.SetViewFrustum(45, 20);

            // We create the atmosphere class
            Atmos = new TVAtmosphere();

            // As said above, we need to create a new object which will
            // hold all the textures needed for our land.
            TextureFactory = new TVTextureFactory();

            // We load the sky texture.
            TextureFactory.LoadTexture("Media\\sky\\sunset\\up.jpg", "SkyTop", -1, -1);
            TextureFactory.LoadTexture("Media\\sky\\sunset\\down.jpg", "SkyBottom", -1, -1);
            TextureFactory.LoadTexture("Media\\sky\\sunset\\left.jpg", "SkyLeft", -1, -1);
            TextureFactory.LoadTexture("Media\\sky\\sunset\\right.jpg", "SkyRight", -1, -1);
            TextureFactory.LoadTexture("Media\\sky\\sunset\\front.jpg", "SkyFront", -1, -1);
            TextureFactory.LoadTexture("Media\\sky\\sunset\\back.jpg", "SkyBack", -1, -1);

            // We set the sky textures.
            Atmos.SkyBox_SetTexture(Globals.GetTex("SkyFront"), Globals.GetTex("SkyBack"), Globals.GetTex("SkyLeft"), Globals.GetTex("SkyRight"), Globals.GetTex("SkyTop"), Globals.GetTex("SkyBottom"));
            Atmos.SkyBox_Enable(true);

            // New : the land generation. This is so much fun because it's
            // so simple! You load a texture as a height map, the engine
            // does the rest. But before this, we create the land object.
            Land = new TVLandscape();
            //Land = Scene.CreateLandscape("Land");

            // Generate the height of the land from the grayscale of the image.
            //Land.GenerateTerrain("Media\\heightmap.jpg", CONST_TV_LANDSCAPE_PRECISION.TV_PRECISION_LOW, 8, 8, -1024, 0, -1024, true);
            //Land.CreateEmptyTerrain(CONST_TV_LANDSCAPE_PRECISION.TV_PRECISION_LOW, 1, 1, -128, 0, -128);

            // Because we don't want to have mountains with height that get to
            // the clouds, we adjust the height (Y) factor.
            //Land.SetScale(1, 0.7f, 1);

            // Then, we load the land texture.
            TextureFactory.LoadTexture("Media\\dirtandgrass.jpg", "LandTexture", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_NO, true);
            TextureFactory.LoadTexture("Media\\dirtandgrass2.jpg", "LandTexture2", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_NO, true);

            //...The splatting texture...
            TextureFactory.LoadTexture("Media\\grass.dds", "SplattingTexture", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_NO, true);
            TextureFactory.LoadTexture("Media\\grassa.dds", "SplattingAlphaTexture", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_NO, true);

            // We assign a texture to that land.
            //Land.SetTexture(Globals.GetTex("LandTexture"), -1);
            //Land.SetTextureScale(3, 3, -1);

            // New : the sun. We have to place the sun in the world. Just like the
            // sky box, the sun is attached to the camera position vector. You will
            // never notice it until you start playing really badly with the
            // properties of the sun. Let's start by loading a texture for it.
            TextureFactory.LoadTexture("Media\\sun.jpg", "Sun", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_NO, true);

            // Then, initialize it by placing it via a vector.
            Atmos.Sun_SetTexture(Globals.GetTex("Sun"));
            Atmos.Sun_SetBillboardSize(1);
            Atmos.Sun_SetPosition(-1000f, 570f, 0f);
            Atmos.Sun_Enable(true);

            // New : To add extra visual effects, we add a lens flare effect. For
            // this, we have to load some cirles that will be used to simulate
            // the flare effect.
            TextureFactory.LoadTexture("Media\\flare1.jpg", "Flare1", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_NO, true);
            TextureFactory.LoadTexture("Media\\flare2.jpg", "Flare2", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_NO, true);
            TextureFactory.LoadTexture("Media\\flare3.jpg", "Flare3", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_NO, true);
            TextureFactory.LoadTexture("Media\\flare4.jpg", "Flare4", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_NO, true);

            // Initialize the lens flares.
            Atmos.LensFlare_SetLensNumber(4);
            Atmos.LensFlare_Enable(true);
            Atmos.LensFlare_SetLensParams(0, Globals.GetTex("Flare1"), 2 * 5f, 40, Globals.RGBA(1f, 1f, 1f, 0.5f), Globals.RGBA(1f, 1f, 1f, 0.5f));
            Atmos.LensFlare_SetLensParams(1, Globals.GetTex("Flare2"), 2 * 1f, 18, Globals.RGBA(1f, 1f, 1f, 0.5f), Globals.RGBA(1f, 1f, 1f, 0.5f));
            Atmos.LensFlare_SetLensParams(2, Globals.GetTex("Flare3"), 2 * 1.8f, 15, Globals.RGBA(1f, 1f, 1f, 0.5f), Globals.RGBA(0.7f, 1f, 1f, 0.5f));
            Atmos.LensFlare_SetLensParams(3, Globals.GetTex("Flare4"), 2 * 1f, 6, Globals.RGBA(1f, 0.1f, 0f, 0.5f), Globals.RGBA(0.5f, 1f, 1f, 0.5f));

            // New : also for fun, we add water. We start by loading the
            // water tetxure...

            sngWaterHeight = -1; //60
            TextureFactory.LoadTexture("Media\\water.bmp", "Water");

            WaterMesh = Scene.CreateMeshBuilder();
            WaterMesh.AddFloor(Globals.GetTex("Water"), -700, 0, (8 * 256) - 700, 8 * 256, sngWaterHeight, 1, 1, false);
            RenderSurf1   = Scene.CreateRenderSurface(256, 256, true);
            RenderSurf2   = Scene.CreateRenderSurface(256, 256, true);
            WPlane.Dist   = -sngWaterHeight;
            WPlane.Normal = new TV_3DVECTOR(0, 1, 0);
            RenderSurf1.SetBackgroundColor(355);
            GraphicFX.SetWaterReflection(WaterMesh, RenderSurf1, RenderSurf2, 0, WPlane);

            // New : for fun, we will also add some clouds, just over the water
            // to give a creepy fog effect. Let's start by loading the clouds textures.
            TextureFactory.LoadTexture("Media\\cloud1.dds", "Clouds", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_BLACK, true);

            // Then, set the land's clouds.
            Atmos.Clouds_Create(1, 1024, 1024);
            Atmos.Clouds_SetLayerParameters(0, 300, Globals.GetTex("Clouds"));
            Atmos.Clouds_SetLayerAnimation(0, true, 0.01f, 0.01f);


            // We set the camera vectors (position and look at) and angles.
            sngPositionX = 0f;
            sngPositionY = 20f;
            sngPositionZ = 0f;
            snglookatX   = 0f;
            snglookatY   = 20f;
            snglookatZ   = 50f;
            sngAngleX    = 0f;
            sngAngleY    = 0f;

            // We set the initial values of movement
            sngWalk   = 0f;
            sngStrafe = 0f;

            // Set the viewing distance
            Scene.SetViewFrustum(60f, 900f); //"random" values, TODO : Check for better ones ?
            //http://www.truevision3d.com/forums/tv3d_sdk_63/about_tilemap-t3865.0.html;prev_next=prev

            // We pop the form over everything else.

            //We create the world map
            WMap = new WorldMap(Scene);

            // We start the main loop. You can't create the MainLoop by using the
            // toolbox buttons, nor by clicking on the form "Form1" : you have to
            // create it by yourself. It's not as hard as it may sound...
            DoLoop = true;

            TV.EnableProfiler(true, false);

            Main_Loop();
        }
示例#41
0
        public void Init()
        {
            //bool DebugToConsole = true;

            // We have to create the TV object before anything else.
            TV = new TVEngine();

            // Set the search directory of the objects, textures, ...
            TV.SetSearchDirectory(Application.StartupPath);

            // We put the debug file in the app directory
            //TV.SetDebugFile(Application.StartupPath + "\\WorldEngine-Debug.txt");
            //TV.SetDebugMode(true, true, DebugToConsole);
            TV.SetDebugMode(false, false, false, false);

            // We initialize TV in the picture box of the form.
            TV.Init3DWindowed(GameHandle);

            // We want to see the FPS.
            TV.DisplayFPS(true);

            // We create the TVGlobals object.
            Globals = new TVGlobals();

            // We create the input object.
            InputEngine = new TVInputEngine();
            InputEngine.Initialize();

            // New : we create the graphic object so we can add some fog.
            GraphicFX = new TVGraphicEffect();

            // We create the scene (the world).
            Scene = new TVScene();
            //Scene.SetViewFrustum(45, 20000);
            //Scene.SetViewFrustum(45, 20);

            // We create the atmosphere class
            Atmos = new TVAtmosphere();

            // As said above, we need to create a new object which will
            // hold all the textures needed for our land.
            TextureFactory = new TVTextureFactory();

            // We load the sky texture.
            TextureFactory.LoadTexture("Media\\sky\\sunset\\up.jpg", "SkyTop", -1, -1);
            TextureFactory.LoadTexture("Media\\sky\\sunset\\down.jpg", "SkyBottom", -1, -1);
            TextureFactory.LoadTexture("Media\\sky\\sunset\\left.jpg", "SkyLeft", -1, -1);
            TextureFactory.LoadTexture("Media\\sky\\sunset\\right.jpg", "SkyRight", -1, -1);
            TextureFactory.LoadTexture("Media\\sky\\sunset\\front.jpg", "SkyFront", -1, -1);
            TextureFactory.LoadTexture("Media\\sky\\sunset\\back.jpg", "SkyBack", -1, -1);

            // We set the sky textures.
            Atmos.SkyBox_SetTexture(Globals.GetTex("SkyFront"), Globals.GetTex("SkyBack"), Globals.GetTex("SkyLeft"), Globals.GetTex("SkyRight"), Globals.GetTex("SkyTop"), Globals.GetTex("SkyBottom"));
            Atmos.SkyBox_Enable(true);

            // New : the land generation. This is so much fun because it's
            // so simple! You load a texture as a height map, the engine
            // does the rest. But before this, we create the land object.
            Land = new TVLandscape();
            //Land = Scene.CreateLandscape("Land");

            // Generate the height of the land from the grayscale of the image.
            //Land.GenerateTerrain("Media\\heightmap.jpg", CONST_TV_LANDSCAPE_PRECISION.TV_PRECISION_LOW, 8, 8, -1024, 0, -1024, true);
            //Land.CreateEmptyTerrain(CONST_TV_LANDSCAPE_PRECISION.TV_PRECISION_LOW, 1, 1, -128, 0, -128);

            // Because we don't want to have mountains with height that get to
            // the clouds, we adjust the height (Y) factor.
            //Land.SetScale(1, 0.7f, 1);

            // Then, we load the land texture.
            TextureFactory.LoadTexture("Media\\dirtandgrass.jpg", "LandTexture", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_NO, true);
            TextureFactory.LoadTexture("Media\\dirtandgrass2.jpg", "LandTexture2", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_NO, true);

            //...The splatting texture...
            TextureFactory.LoadTexture("Media\\grass.dds", "SplattingTexture", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_NO, true);
            TextureFactory.LoadTexture("Media\\grassa.dds", "SplattingAlphaTexture", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_NO, true);

            // We assign a texture to that land.
            //Land.SetTexture(Globals.GetTex("LandTexture"), -1);
            //Land.SetTextureScale(3, 3, -1);

            // New : the sun. We have to place the sun in the world. Just like the
            // sky box, the sun is attached to the camera position vector. You will
            // never notice it until you start playing really badly with the
            // properties of the sun. Let's start by loading a texture for it.
            TextureFactory.LoadTexture("Media\\sun.jpg", "Sun", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_NO, true);

            // Then, initialize it by placing it via a vector.
            Atmos.Sun_SetTexture(Globals.GetTex("Sun"));
            Atmos.Sun_SetBillboardSize(1);
            Atmos.Sun_SetPosition(-1000f, 570f, 0f);
            Atmos.Sun_Enable(true);

            // New : To add extra visual effects, we add a lens flare effect. For
            // this, we have to load some cirles that will be used to simulate
            // the flare effect.
            TextureFactory.LoadTexture("Media\\flare1.jpg", "Flare1", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_NO, true);
            TextureFactory.LoadTexture("Media\\flare2.jpg", "Flare2", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_NO, true);
            TextureFactory.LoadTexture("Media\\flare3.jpg", "Flare3", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_NO, true);
            TextureFactory.LoadTexture("Media\\flare4.jpg", "Flare4", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_NO, true);

            // Initialize the lens flares.
            Atmos.LensFlare_SetLensNumber(4);
            Atmos.LensFlare_Enable(true);
            Atmos.LensFlare_SetLensParams(0, Globals.GetTex("Flare1"), 2 * 5f, 40, Globals.RGBA(1f, 1f, 1f, 0.5f), Globals.RGBA(1f, 1f, 1f, 0.5f));
            Atmos.LensFlare_SetLensParams(1, Globals.GetTex("Flare2"), 2 * 1f, 18, Globals.RGBA(1f, 1f, 1f, 0.5f), Globals.RGBA(1f, 1f, 1f, 0.5f));
            Atmos.LensFlare_SetLensParams(2, Globals.GetTex("Flare3"), 2 * 1.8f, 15, Globals.RGBA(1f, 1f, 1f, 0.5f), Globals.RGBA(0.7f, 1f, 1f, 0.5f));
            Atmos.LensFlare_SetLensParams(3, Globals.GetTex("Flare4"), 2 * 1f, 6, Globals.RGBA(1f, 0.1f, 0f, 0.5f), Globals.RGBA(0.5f, 1f, 1f, 0.5f));

            // New : also for fun, we add water. We start by loading the
            // water tetxure...

            sngWaterHeight = -1; //60
            TextureFactory.LoadTexture("Media\\water.bmp", "Water");

            WaterMesh = Scene.CreateMeshBuilder();
            WaterMesh.AddFloor(Globals.GetTex("Water"), -700, 0, (8 * 256) - 700, 8 * 256, sngWaterHeight, 1, 1, false);
            RenderSurf1 = Scene.CreateRenderSurface(256, 256, true);
            RenderSurf2 = Scene.CreateRenderSurface(256, 256, true);
            WPlane.Dist = -sngWaterHeight;
            WPlane.Normal = new TV_3DVECTOR(0, 1, 0);
            RenderSurf1.SetBackgroundColor(355);
            GraphicFX.SetWaterReflection(WaterMesh, RenderSurf1, RenderSurf2, 0, WPlane);

            // New : for fun, we will also add some clouds, just over the water
            // to give a creepy fog effect. Let's start by loading the clouds textures.
            TextureFactory.LoadTexture("Media\\cloud1.dds", "Clouds", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_BLACK, true);

            // Then, set the land's clouds.
            Atmos.Clouds_Create(1, 1024, 1024);
            Atmos.Clouds_SetLayerParameters(0, 300, Globals.GetTex("Clouds"));
            Atmos.Clouds_SetLayerAnimation(0, true, 0.01f, 0.01f);

            // We set the camera vectors (position and look at) and angles.
            sngPositionX = 0f;
            sngPositionY = 20f;
            sngPositionZ = 0f;
            snglookatX = 0f;
            snglookatY = 20f;
            snglookatZ = 50f;
            sngAngleX = 0f;
            sngAngleY = 0f;

            // We set the initial values of movement
            sngWalk = 0f;
            sngStrafe = 0f;

            // Set the viewing distance
            Scene.SetViewFrustum(60f, 900f); //"random" values, TODO : Check for better ones ?
            //http://www.truevision3d.com/forums/tv3d_sdk_63/about_tilemap-t3865.0.html;prev_next=prev

            // We pop the form over everything else.

            //We create the world map
            WMap = new WorldMap(Scene);

            // We start the main loop. You can't create the MainLoop by using the
            // toolbox buttons, nor by clicking on the form "Form1" : you have to
            // create it by yourself. It's not as hard as it may sound...
            DoLoop = true;

            TV.EnableProfiler(true, false);

            Main_Loop();
        }
示例#42
0
文件: Mesh.cs 项目: zulis/Cubica
        public override void Initialize()
        {
            mesh = Scene.CreateMeshBuilder();

            switch (Helpers.GetFileFormat(FileName))
            {
                case Helpers.FileFormat.TVM:
                    mesh.LoadTVM(FileName, true, false);
                    break;
                case Helpers.FileFormat.X:
                    mesh.LoadXFile(FileName, true, false);
                    break;
            }

            if (Visible)
            {
                mesh.EnableFrustumCulling(true, true);
                mesh.ComputeNormals();
                mesh.ComputeBoundings();
                mesh.ComputeOctree();
                mesh.SetAlphaTest(true);
                mesh.SetCullMode(CONST_TV_CULLING.TV_BACK_CULL);
                mesh.SetBlendingMode(CONST_TV_BLENDINGMODE.TV_BLEND_ALPHA);
                mesh.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_MANAGED);
                mesh.SetShadowCast(true, true);

                mesh.SetPosition(Position.x, Position.y, Position.z);
                mesh.SetRotation(Rotation.x, Rotation.y, Rotation.z);
                mesh.SetScale(Scale.x, Scale.y, Scale.z);

                // Physics
                SetPhysics();
            }
            else
            {
                // Hide mesh.
                for (var i = 0; i < mesh.GetGroupCount(); i++)
                    mesh.SetGroupEnable(i, false);
            }

            // Register object in Lua.
            ScriptManager.SetGlobal(Name, this);
        }