void DestroyBackgroundImageMeshObject()
 {
     if( backgroundImageMeshObject != null )
     {
         backgroundImageMeshObject.Dispose();
         backgroundImageMeshObject = null;
         backgroundImageSceneNode.Dispose();
         backgroundImageSceneNode = null;
     }
 }
Example #2
0
        void ControlPanelButton_Click( EButton sender )
        {
            int index = int.Parse( sender.Name.Substring( "ControlPanelButton".Length ) );

            TaskTargetChooseIndex = -1;

            List<RTSUnitAI.UserControlPanelTask> tasks = GetControlTasks();

            if( tasks == null || index >= tasks.Count )
                return;
            if( !tasks[ index ].Enable )
                return;

            RTSUnitAI.Task.Types taskType = tasks[ index ].Task.Type;

            switch( taskType )
            {
            //Stop, SelfDestroy
            case RTSUnitAI.Task.Types.Stop:
            case RTSUnitAI.Task.Types.SelfDestroy:
                foreach( Unit unit in selectedUnits )
                {
                    RTSUnitAI intellect = unit.Intellect as RTSUnitAI;
                    if( intellect == null )
                        continue;

                    if( IsEnableTaskTypeInTasks( intellect.GetControlPanelTasks(), taskType ) )
                        intellect.DoTask( new RTSUnitAI.Task( taskType ), false );
                }
                break;

            //ProductUnit
            case RTSUnitAI.Task.Types.ProductUnit:
                foreach( Unit unit in selectedUnits )
                {
                    RTSBuildingAI intellect = unit.Intellect as RTSBuildingAI;
                    if( intellect == null )
                        continue;

                    if( IsEnableTaskTypeInTasks( intellect.GetControlPanelTasks(), taskType ) )
                        intellect.DoTask( new RTSUnitAI.Task( taskType, tasks[ index ].Task.EntityType ), false );
                }
                break;

            //Move, Attack, Repair
            case RTSUnitAI.Task.Types.Move:
            case RTSUnitAI.Task.Types.Attack:
            case RTSUnitAI.Task.Types.Repair:
                //do taskTargetChoose
                TaskTargetChooseIndex = index;
                break;

            //BuildBuilding
            case RTSUnitAI.Task.Types.BuildBuilding:
                if( selectedUnits.Count == 1 )
                {
                    Unit unit = selectedUnits[ 0 ];
                    RTSUnitAI intellect = unit.Intellect as RTSUnitAI;
                    if( intellect != null )
                    {
                        //do taskTargetChoose
                        TaskTargetChooseIndex = index;

                        taskTargetBuildingType = (RTSBuildingType)tasks[ index ].Task.EntityType;

                        string meshName = null;
                        {
                            foreach( MapObjectTypeAttachedObject typeAttachedObject in
                                taskTargetBuildingType.AttachedObjects )
                            {
                                MapObjectTypeAttachedMesh typeMeshAttachedObject = typeAttachedObject as
                                    MapObjectTypeAttachedMesh;
                                if( typeMeshAttachedObject != null )
                                {
                                    meshName = typeMeshAttachedObject.MeshName;
                                    break;
                                }
                            }
                        }

                        taskTargetBuildMeshObject = SceneManager.Instance.CreateMeshObject( meshName );
                        taskTargetBuildSceneNode = new SceneNode();
                        taskTargetBuildSceneNode.Attach( taskTargetBuildMeshObject );
                        taskTargetBuildSceneNode.Visible = false;
                    }
                }
                break;

            }
        }
        void CreateBackgroundImageMeshObject()
        {
            backgroundImageMeshObject = SceneManager.Instance.CreateMeshObject(
                "JigsawPuzzleGame\\BackgroundImage.mesh" );

            if( backgroundImageMeshObject != null )
            {
                backgroundImageSceneNode = new SceneNode();
                backgroundImageSceneNode.Attach( backgroundImageMeshObject );
            }
        }
        private unsafe void UpdateGeometry()
        {
            DestroyGeometry();

            Curve positionCurve = GetPositionCurve();

            Curve radiusCurve = null;
            {
                bool existsSpecialRadius = false;
                foreach (MapCurvePoint point in Points)
                {
                    RenderableCurvePoint point2 = point as RenderableCurvePoint;
                    if (point2 != null && point2.OverrideRadius >= 0)
                    {
                        existsSpecialRadius = true;
                        break;
                    }
                }

                if (existsSpecialRadius)
                {
                    switch (radiusCurveType)
                    {
                        case RadiusCurveTypes.UniformCubicSpline:
                            radiusCurve = new UniformCubicSpline();
                            break;

                        case RadiusCurveTypes.Bezier:
                            radiusCurve = new BezierCurve();
                            break;

                        case RadiusCurveTypes.Line:
                            radiusCurve = new LineCurve();
                            break;
                    }

                    for (int n = 0; n < Points.Count; n++)
                    {
                        MapCurvePoint point = Points[n];

                        if (!point.Editor_IsExcludedFromWorld())
                        {
                            float rad = radius;
                            RenderableCurvePoint renderableCurvePoint = point as RenderableCurvePoint;
                            if (renderableCurvePoint != null && renderableCurvePoint.OverrideRadius >= 0)
                                rad = renderableCurvePoint.OverrideRadius;
                            radiusCurve.AddValue(point.Time, new Vec3(rad, 0, 0));
                        }
                    }
                }
            }

            //create mesh
            Vertex[] vertices = null;
            int[] indices = null;
            if (positionCurve != null && positionCurve.Values.Count > 1 && Points.Count >= 2)
            {
                Vec3 positionOffset = -Position;

                int steps = (Points.Count - 1) * pathSteps + 1;
                int vertexCount = steps * (shapeSegments + 1);
                int indexCount = (steps - 1) * shapeSegments * 2 * 3;

                vertices = new Vertex[vertexCount];
                indices = new int[indexCount];

                //fill data
                {
                    int currentVertex = 0;
                    int currentIndex = 0;
                    float currentDistance = 0;
                    Vec3 lastPosition = Vec3.Zero;
                    Quat lastRot = Quat.Identity;

                    for (int nStep = 0; nStep < steps; nStep++)
                    {
                        int startStepVertexIndex = currentVertex;

                        float coefficient = (float)nStep / (float)(steps - 1);
                        Vec3 pos = CalculateCurvePointByCoefficient(coefficient) + positionOffset;

                        Quat rot;
                        {
                            Vec3 v = CalculateCurvePointByCoefficient(coefficient + .3f / (float)(steps - 1)) -
                                CalculateCurvePointByCoefficient(coefficient);
                            if (v != Vec3.Zero)
                                rot = Quat.FromDirectionZAxisUp(v.GetNormalize());
                            else
                                rot = lastRot;
                        }

                        if (nStep != 0)
                            currentDistance += (pos - lastPosition).Length();

                        float rad;
                        if (radiusCurve != null)
                        {
                            Range range = new Range(radiusCurve.Times[0], radiusCurve.Times[radiusCurve.Times.Count - 1]);
                            float t = range.Minimum + (range.Maximum - range.Minimum) * coefficient;
                            rad = radiusCurve.CalculateValueByTime(t).X;
                        }
                        else
                            rad = radius;

                        for (int nSegment = 0; nSegment < shapeSegments + 1; nSegment++)
                        {
                            float rotateCoefficient = ((float)nSegment / (float)(shapeSegments));
                            float angle = rotateCoefficient * MathFunctions.PI * 2;
                            Vec3 p = pos + rot * new Vec3(0, MathFunctions.Cos(angle) * rad, MathFunctions.Sin(angle) * rad);

                            Vertex vertex = new Vertex();
                            vertex.position = p;
                            Vec3 pp = p - pos;
                            if (pp != Vec3.Zero)
                                vertex.normal = pp.GetNormalize();
                            else
                                vertex.normal = Vec3.XAxis;
                            //vertex.normal = ( p - pos ).GetNormalize();
                            vertex.texCoord = new Vec2(currentDistance * textureCoordinatesTilesPerMeter, rotateCoefficient + .25f);
                            vertex.tangent = new Vec4(rot.GetForward(), 1);
                            vertices[currentVertex++] = vertex;
                        }

                        if (nStep < steps - 1)
                        {
                            for (int nSegment = 0; nSegment < shapeSegments; nSegment++)
                            {
                                indices[currentIndex++] = startStepVertexIndex + nSegment;
                                indices[currentIndex++] = startStepVertexIndex + nSegment + 1;
                                indices[currentIndex++] = startStepVertexIndex + nSegment + 1 + shapeSegments + 1;
                                indices[currentIndex++] = startStepVertexIndex + nSegment + 1 + shapeSegments + 1;
                                indices[currentIndex++] = startStepVertexIndex + nSegment + shapeSegments + 1;
                                indices[currentIndex++] = startStepVertexIndex + nSegment;
                            }
                        }

                        lastPosition = pos;
                        lastRot = rot;
                    }
                    if (currentVertex != vertexCount)
                        Log.Fatal("RenderableCurve: UpdateRenderingGeometry: currentVertex != vertexCount.");
                    if (currentIndex != indexCount)
                        Log.Fatal("RenderableCurve: UpdateRenderingGeometry: currentIndex != indexCount.");
                }

                if (vertices.Length != 0 && indices.Length != 0)
                {
                    //create mesh
                    string meshName = MeshManager.Instance.GetUniqueName(
                        string.Format("__RenderableCurve_{0}_{1}", Name, uniqueMeshIdentifier));
                    uniqueMeshIdentifier++;
                    //string meshName = MeshManager.Instance.GetUniqueName( string.Format( "__RenderableCurve_{0}", Name ) );
                    mesh = MeshManager.Instance.CreateManual(meshName);
                    SubMesh subMesh = mesh.CreateSubMesh();
                    subMesh.UseSharedVertices = false;

                    //init vertexData
                    VertexDeclaration declaration = subMesh.VertexData.VertexDeclaration;
                    declaration.AddElement(0, 0, VertexElementType.Float3, VertexElementSemantic.Position);
                    declaration.AddElement(0, 12, VertexElementType.Float3, VertexElementSemantic.Normal);
                    declaration.AddElement(0, 24, VertexElementType.Float2, VertexElementSemantic.TextureCoordinates, 0);
                    declaration.AddElement(0, 32, VertexElementType.Float4, VertexElementSemantic.Tangent, 0);

                    fixed (Vertex* pVertices = vertices)
                    {
                        subMesh.VertexData = VertexData.CreateFromArray(declaration, (IntPtr)pVertices,
                            vertices.Length * Marshal.SizeOf(typeof(Vertex)));
                    }
                    subMesh.IndexData = IndexData.CreateFromArray(indices, 0, indices.Length, false);

                    //set material
                    subMesh.MaterialName = materialName;

                    //set mesh gabarites
                    Bounds bounds = Bounds.Cleared;
                    foreach (Vertex vertex in vertices)
                        bounds.Add(vertex.position);
                    mesh.SetBoundsAndRadius(bounds, bounds.GetRadius());
                }
            }

            //create MeshObject, SceneNode
            if (mesh != null)
            {
                meshObject = SceneManager.Instance.CreateMeshObject(mesh.Name);
                if (meshObject != null)
                {
                    meshObject.SetMaterialNameForAllSubObjects(materialName);
                    meshObject.CastShadows = true;

                    sceneNode = new SceneNode();
                    sceneNode.Attach(meshObject);
                    //apply offset
                    sceneNode.Position = Position;
                    MapObject.AssociateSceneNodeWithMapObject(sceneNode, this);
                }
            }

            //create collision body
            if (mesh != null && collision)
            {
                Vec3[] positions = new Vec3[vertices.Length];
                for (int n = 0; n < vertices.Length; n++)
                    positions[n] = vertices[n].position;
                string meshPhysicsMeshName = PhysicsWorld.Instance.AddCustomMeshGeometry(positions, indices, null,
                    MeshShape.MeshTypes.TriangleMesh, 0, 0);

                collisionBody = PhysicsWorld.Instance.CreateBody();
                collisionBody.Static = true;
                collisionBody._InternalUserData = this;
                collisionBody.Position = Position;

                MeshShape shape = collisionBody.CreateMeshShape();
                shape.MeshName = meshPhysicsMeshName;
                shape.MaterialName = CollisionMaterialName;
                shape.ContactGroup = (int)ContactGroup.Collision;
                //shape.VehicleDrivableSurface = collisionVehicleDrivableSurface;

                collisionBody.PushedToWorld = true;
            }

            needUpdate = false;
        }
        private void DestroyGeometry()
        {
            if (collisionBody != null)
            {
                collisionBody.Dispose();
                collisionBody = null;
            }

            if (sceneNode != null)
            {
                sceneNode.Dispose();
                sceneNode = null;
            }

            if (meshObject != null)
            {
                meshObject.Dispose();
                meshObject = null;
            }

            if (mesh != null)
            {
                mesh.Dispose();
                mesh = null;
            }
        }
Example #6
0
		void DestroyMeshObject()
		{
			if( meshObject != null )
			{
				sceneNode.Detach( meshObject );
				sceneNode.Dispose();
				sceneNode = null;
				meshObject.Dispose();
				meshObject = null;
			}
		}
Example #7
0
		void CreateMeshObject()
		{
			DestroyMeshObject();

			meshObject = SceneManager.Instance.CreateMeshObject( "Base\\Simple Models\\Cylinder.mesh" );
			if( meshObject != null )
			{
				meshObject.SetMaterialNameForAllSubObjects( "Red" );

				sceneNode = new SceneNode();
				sceneNode.Visible = false;
				sceneNode.Position = new Vec3( 5, 0, 0 );
				sceneNode.Rotation = new Angles( 50, 50, 50 ).ToQuat();
				sceneNode.Attach( meshObject );
			}
		}
        public override void OnSceneManagementGetAffectingLightsForObject( Camera camera,
			RenderLight[] affectingLights, SceneNode sceneNode )
        {
            if( tempLightArray.Length != affectingLights.Length )
                tempLightArray = new RenderLight[ affectingLights.Length ];

            int count = 0;

            foreach( RenderLight light in affectingLights )
            {
                //Sphere boundingSphere = new Sphere( sceneNode.Position, 0 );
                //{
                //   for( int n = 0; n < sceneNode.MovableObjects.Count; n++ )
                //   {
                //      MovableObject movableObject = sceneNode.MovableObjects[ n ];

                //      float radius = movableObject._GetBoundingRadius();
                //      if( radius > boundingSphere.Radius )
                //         boundingSphere.Radius = radius;
                //   }
                //}

                if( light.Type == RenderLightType.Point || light.Type == RenderLightType.Spot )
                {
                    Bounds bounds;
                    sceneNode.GetWorldBounds( out bounds );
                    if( !IsIntersects( light, bounds ) )
                        continue;
                }

                tempLightArray[ count ] = light;
                count++;
            }

            sceneNode.SetAffectingLights( tempLightArray, count );
        }
Example #9
0
        /// <summary>
        /// Creates the element in the world. It automatically
        /// sets up the mesh and the node.</summary>
        protected virtual void Initialise(RenderQueueGroupID renderGroup, string materialName, Vec3 scale)
        {
            mBillboardSet = SceneManager.Instance.CreateBillboardSet(2);
            mBillboardSet.CastShadows = false;
            mBillboardSet.RenderQueueGroup = renderGroup;
            mBillboardSet.MaterialName = materialName;
            mBillboardSet.DefaultSize = new Vec2(1, 1);

            // Attaches the mesh on a node
            if (mBillboardSet.ParentSceneNode == null)
            {
                mNode = new SceneNode();
                mNode.Attach(mBillboardSet);
            }
            else
                mNode = mBillboardSet.ParentSceneNode;

            // Sets up the node (Position, Scale and Rotation)
            mBillboardSet.CreateBillboard(Vec3.Zero);
            mNode.Position = Vec3.Zero;
            mNode.Scale = scale;

            mMainLight = SceneManager.Instance.CreateLight();
            mMainLight.Type = RenderLightType.Directional;
            mMainLight.AllowStaticLighting = false;
            mMainLight.CastShadows = true;
            mMainLight.Position = new Vec3(0, 0, 150);
        }
Example #10
0
        void DestroyPlane()
        {
            DestroyReflectionTexture();

            if( sceneNode != null )
            {
                sceneNode.Dispose();
                sceneNode = null;
            }
            if( meshObject != null )
            {
                meshObject.Dispose();
                meshObject = null;
            }
            if( meshPlane != null )
            {
                meshPlane.Dispose();
                meshPlane = null;
            }

            if( material != null )
            {
                material.Dispose();
                material = null;
            }
        }
Example #11
0
        void CreatePlane()
        {
            if( RenderSystem.Instance.IsDeviceLost() )
                return;

            DestroyPlane();

            Viewport defaultViewport = RendererWorld.Instance.DefaultViewport;

            if( RenderSystem.Instance.HasShaderModel2() &&
                RenderSystem.Instance.Capabilities.UserClipPlanes &&
                ReflectionLevel != ReflectionLevels.None )
            {
                CreateReflectionTexture();
            }

            string meshName = MeshManager.Instance.GetUniqueName( "WaterPlane" );

            Vec2 tile;
            if( fixedPipelineMapTiling != 0 )
                tile = size / fixedPipelineMapTiling;
            else
                tile = new Vec2( 0, 0 );

            meshPlane = MeshManager.Instance.CreatePlane( meshName, new Plane( new Vec3( 0, 0, 1 ), 0 ),
                size, segments, true, 1, tile, new Vec3( 0, 1, 0 ) );

            //create material
            string materialName = MaterialManager.Instance.GetUniqueName( "_GeneratedWaterPlane" );
            material = (WaterPlaneHighLevelMaterial)HighLevelMaterialManager.Instance.
                CreateMaterial( materialName, "WaterPlaneHighLevelMaterial" );
            material.Init( this );
            material.UpdateBaseMaterial();

            //change material of mesh
            foreach( SubMesh subMesh in meshPlane.SubMeshes )
                subMesh.MaterialName = material.Name;

            meshObject = SceneManager.Instance.CreateMeshObject( meshName );
            meshObject.RenderQueueGroup = renderQueueGroup;

            sceneNode = new SceneNode();
            sceneNode.Attach( meshObject );
            sceneNode.Position = position;
            sceneNode.Visible = Visible;

            needUpdatePlane = false;
        }
Example #12
0
		void CreatePlane()
		{
			DestroyPlane();

			string meshName;

			if( !string.IsNullOrEmpty( customMesh ) )
			{
				meshName = customMesh;
			}
			else
			{
				meshName = MeshManager.Instance.GetUniqueName( "WaterPlane" );

				Vec2 tile;
				if( fixedPipelineMapTiling != 0 )
					tile = size / fixedPipelineMapTiling;
				else
					tile = new Vec2( 0, 0 );

				meshPlane = MeshManager.Instance.CreatePlane( meshName, new Plane( new Vec3( 0, 0, 1 ), 0 ),
					size, segments, true, 1, tile, new Vec3( 0, 1, 0 ) );
			}

			//create material
			string materialName = MaterialManager.Instance.GetUniqueName( "_GeneratedWaterPlane" );
			material = (WaterPlaneHighLevelMaterial)HighLevelMaterialManager.Instance.
				CreateMaterial( materialName, "WaterPlaneHighLevelMaterial" );
			material.Init( this );
			material.UpdateBaseMaterial();

			meshObject = SceneManager.Instance.CreateMeshObject( meshName );
			if( meshObject != null )
			{
				meshObject.SetMaterialNameForAllSubObjects( material.Name );
				meshObject.RenderQueueGroup = renderQueueGroup;

				sceneNode = new SceneNode();
				sceneNode.Position = position;
				sceneNode.Visible = Visible;
				sceneNode.AllowSceneManagementCulling = false;
				sceneNode.Attach( meshObject );
			}

			needUpdatePlane = false;
		}
            private void CreateMeshObject()
            {
                meshObject = SceneManager.Instance.CreateMeshObject("Base\\Simple Models\\Box.mesh");
                if (meshObject != null)
                {
                    meshObject.SetMaterialNameForAllSubObjects("Red");

                    sceneNode = new SceneNode();
                    //sceneNode.Position = new Vec3( 0, 0, 1 );
                    sceneNode.Attach(meshObject);
                }
            }
        // Build a depot
        private void BuildDepot()
        {
            if (builderAI != null)
            {
                taskTargetBuildingType = (RTSBuildingType)EntityTypes.Instance.GetByName("RTSDepot");

                string meshName = null;
                {
                    foreach (MapObjectTypeAttachedObject typeAttachedObject in
                        taskTargetBuildingType.AttachedObjects)
                    {
                        MapObjectTypeAttachedMesh typeMeshAttachedObject = typeAttachedObject as
                            MapObjectTypeAttachedMesh;
                        if (typeMeshAttachedObject != null)
                        {
                            meshName = typeMeshAttachedObject.MeshName;
                            break;
                        }
                    }
                }

                MeshObject taskTargetBuildMeshObject = SceneManager.Instance.CreateMeshObject(meshName);
                SceneNode taskTargetBuildSceneNode = new SceneNode();
                taskTargetBuildSceneNode.Attach(taskTargetBuildMeshObject);
                taskTargetBuildSceneNode.Visible = false;

                // Randomly generate positions within 25 units of the hive
                Random rand = new Random();
                Vec3 pos;
                do
                {
                    pos = new Vec3(hive.Position.X + ((float)rand.NextDouble() * 50f - 25f),
                        hive.Position.Y + ((float)rand.NextDouble() * 50f - 25f), hive.Position.Z);
                } while (!IsFreeForBuildTaskTargetBuild(pos));

                // Build the barracks
                builderAI.DoTask(new AntUnitAI.Task(AntUnitAI.Task.Types.BuildBuilding, pos,
                    (RTSBuildingType)EntityTypes.Instance.GetByName("RTSDepot")), false);

                GameEngineApp.Instance.ControlManager.PlaySound(
                    "Sounds\\Feedback\\RTSBuildBuilding.ogg");
            }
        }