Пример #1
0
 public void Dispose()
 {
     Debug.WriteLine("disposing of game engine objects");
     m_GameInput.Dispose();
     Debug.WriteLine("disposing of terrain");
     if (m_Terrain != null)
     {
         m_Terrain.Dispose();
     }
     Debug.WriteLine("disposing of skybox");
     m_Skybox.Dispose();
     Debug.WriteLine("disposing of quadtree");
     m_QuadTree.Dispose();
     Debug.WriteLine("disposing of splashscreen");
     if (m_SplashScreen != null)
     {
         m_SplashScreen.Dispose();
     }
     Debug.WriteLine("disposing of optionscreen");
     if (m_OptionScreen != null)
     {
         m_OptionScreen.Dispose();
     }
     Debug.WriteLine("number of objects=" + m_Objects.Count);
     for (int i = 0; i < m_Objects.Count; i++)
     {
         try
         {
             Object3D obj = (Object3D)m_Objects[i];
             Debug.WriteLine("calling dispose for " + obj.Name);
             obj.Dispose( );
         }
         catch
         {
         }
     }
     for (int i = 0; i < BillBoard.Objects.Count; i++)
     {
         Object3D obj = (Object3D)BillBoard.Objects[i];
         obj.Dispose();
     }
 }
Пример #2
0
        public Object3D GetObject(string name)
        {
            Object3D obj = null;

            foreach (Object3D o in m_Objects)
            {
                if (o.Name == name)
                {
                    obj = o;
                }
            }
            if (obj == null)
            {
                foreach (Object3D o in BillBoard.Objects)
                {
                    if (o.Name == name)
                    {
                        obj = o;
                    }
                }
            }
            return(obj);
        }
Пример #3
0
        public void setupCamera()
        {
            // Add camera
              camera = Object3D.fromNode(H3d.addCameraNode( H3d.H3DRootNode, "Camera", pipelines[0] ));
              camera.tx = camera_init["tx"];
              camera.ty = camera_init["ty"];
              camera.tz = camera_init["tz"];
              camera.rx = camera_init["rx"];
              camera.ry = camera_init["ry"];
              camera.rz = camera_init["rz"];
              camera.sx = camera_init["sx"];
              camera.sy = camera_init["sy"];
              camera.sz = camera_init["sz"];
              camera.update();

              int w = Platform.Methods.getWidth();
              int h = Platform.Methods.getHeight();

              H3d.setNodeParamI(camera.node, (int)H3d.H3DCamera.ViewportXI, 0);
              H3d.setNodeParamI(camera.node, (int)H3d.H3DCamera.ViewportYI, 0);
              H3d.setNodeParamI(camera.node, (int)H3d.H3DCamera.ViewportWidthI, w );
              H3d.setNodeParamI(camera.node, (int)H3d.H3DCamera.ViewportHeightI, h );

              foreach(int pipe in pipelines) {
            H3d.resizePipelineBuffers( pipe, w, h );
              }
              H3d.setupCameraView( camera.node, 45.0f, ((float)w)/h, 1, 1000.0f );
        }
        public void AddObject(Object3D obj)
        {
            try
            {
                if (obj != null)
                {
                    if (obj.InRect(m_Bounds))
                    {
                        int nIndex = m_Objects.IndexOfKey(obj.Name);
                        try
                        {
                            if (nIndex < 0)                                // add object if we don't have it yet
                            {
                                m_Objects.Add(obj.Name, obj);
                                obj.m_Quads.Add(this);
//								if ( !obj.Name.StartsWith("Quad") && !obj.Name.StartsWith("tree") && !obj.Name.StartsWith("red")&& !obj.Name.StartsWith("blue"))
//								{
//									Console.AddLine(obj.Name + " added to " + Name );
//								}
                                if (m_NorthEast != null && obj.InRect(m_NorthEast.Bounds))
                                {
                                    m_NorthEast.AddObject(obj);
                                }
                                if (m_NorthWest != null && obj.InRect(m_NorthWest.Bounds))
                                {
                                    m_NorthWest.AddObject(obj);
                                }
                                if (m_SouthWest != null && obj.InRect(m_SouthWest.Bounds))
                                {
                                    m_SouthWest.AddObject(obj);
                                }
                                if (m_SouthEast != null && obj.InRect(m_SouthEast.Bounds))
                                {
                                    m_SouthEast.AddObject(obj);
                                }
                            }
                            else
                            {
                                //							Console.AddLine("Attempt to add another " + obj.Name );
                            }
                        }
                        catch (DirectXException d3de)
                        {
                            Console.AddLine("Unable to add object");
                            Console.AddLine(d3de.ErrorString);
                        }
                        catch (Exception e)
                        {
                            Console.AddLine("Unable to add object");
                            Console.AddLine(e.Message);
                        }
                    }
                    else
                    {
                        int nIndex = m_Objects.IndexOfKey(obj.Name);
                        if (nIndex >= 0)                            // remove the  object if we have it
                        {
                            RemoveObject(obj);
                            if (m_Parent != null)
                            {
                                m_Parent.AddObject(obj);
                            }
                        }
                    }
                }
            }
            catch
            {
                Console.AddLine("fails in Quad AddObject");
            }
        }
Пример #5
0
 public void AddObject(Object3D obj)
 {
     Debug.WriteLine("adding " + obj.Name + " to engine object list");
     m_QuadTree.AddObject(obj);
     m_Objects.Add(obj);
 }
 public void LookAt(Object3D obj)
 {
     m_LookAtObject = obj;
 }
 public override bool Collide(Object3D Other)
 {
     return(false);
 }
 public float GetDistance(Object3D obj)
 {
     return(planeFrustum[3].Dot(obj.Position) + m_fNearPlane);
 }
 public void Attach(Object3D parent, Vector3 offset)
 {
     m_AttachedObject = parent;
     m_Offset         = offset;
 }
Пример #10
0
 public static Object3D fromNode(int node)
 {
     Object3D ret = new Object3D();
       ret.node = node;
       return ret;
 }
Пример #11
0
        public override bool Collide(Object3D Other)
        {
            bool bCollide = false;

            if (Visible)
            {
                Plane[]   planeCollide;                  // planes of the collide box
                Vector3[] WorldCorners = new Vector3[8];

                // perform bounding sphere collision test
                float delta_north      = Other.North - North;
                float delta_east       = Other.East - East;
                float distance_squared = delta_north * delta_north + delta_east * delta_east;
                float combined_radius  = (Radius * Radius) + (Other.Radius * Other.Radius);
                bCollide = distance_squared < combined_radius;

                // if the bounding spheres are in contact perform a more precise collision test
                if (bCollide)
                {
                    planeCollide = new Plane[6];

                    for (int i = 0; i < 8; i++)
                    {
                        WorldCorners[i] = Vector3.TransformCoordinate(m_Corners[i], m_Matrix);
                    }

                    planeCollide[0] = Plane.FromPoints(WorldCorners[7], WorldCorners[3], WorldCorners[5]);                   // Right
                    planeCollide[1] = Plane.FromPoints(WorldCorners[2], WorldCorners[6], WorldCorners[4]);                   // Left
                    planeCollide[2] = Plane.FromPoints(WorldCorners[6], WorldCorners[7], WorldCorners[5]);                   // Far
                    planeCollide[3] = Plane.FromPoints(WorldCorners[0], WorldCorners[1], WorldCorners[2]);                   // Near
                    planeCollide[4] = Plane.FromPoints(WorldCorners[2], WorldCorners[3], WorldCorners[6]);                   // Top
                    planeCollide[5] = Plane.FromPoints(WorldCorners[1], WorldCorners[0], WorldCorners[4]);                   // Bottom

                    if (Other.GetType() == typeof(Model))
                    {
                        for (int i = 0; i < 8; i++)
                        {
                            float   distance;
                            Vector3 testPoint = ((Model)Other).GetCorner(i);

                            for (int iPlane = 0; iPlane < 6; iPlane++)
                            {
                                distance = planeCollide[iPlane].Dot(testPoint);
                                if (distance > 0.0f)
                                {
                                    bCollide = true;
                                }
                            }
                        }
                    }
                    else
                    {
                        float   distance;
                        Vector3 testPoint = Other.Position;
                        testPoint.Y += 0.1f;

                        for (int iPlane = 0; iPlane < 6; iPlane++)
                        {
                            distance = planeCollide[iPlane].Dot(testPoint);
                            if (distance > 0.0f)
                            {
                                bCollide = true;
                            }
                        }
                        for (int i = 0; i < 8; i++)
                        {
                            testPoint = Other.Position;

                            float angle = ((float)Math.PI / 4) * i;

                            testPoint.X += (float)Math.Cos(angle) * Other.Radius;
                            testPoint.Y += 0.2f;
                            testPoint.Z += (float)Math.Sin(angle) * Other.Radius;

                            for (int iPlane = 0; iPlane < 6; iPlane++)
                            {
                                distance = planeCollide[iPlane].Dot(testPoint);
                                if (distance > 0.0f)
                                {
                                    bCollide = true;
                                }
                            }
                        }
                    }
                }
            }

            return(bCollide);
        }
Пример #12
0
 public void AddChild(Object3D child)
 {
     m_Children.Add(child.Name, child);
     child.m_Parent = this;
 }
Пример #13
0
 public virtual bool CollideSphere(Object3D other)
 {
     return(false);
 }
Пример #14
0
 public virtual bool Collide(Object3D Other)
 {
     return(false);
 }