Beispiel #1
0
        /// <summary>
        /// Initiailizes the scene
        /// Sets many properties that ODE requires to be stable
        /// These settings need to be tweaked 'exactly' right or weird stuff happens.
        /// </summary>
        private void Initialise(Vector3 regionExtent)
        {
			WorldExtents.X = regionExtent.X;
            m_regionWidth = (uint)regionExtent.X;
            WorldExtents.Y = regionExtent.Y;
            m_regionHeight = (uint)regionExtent.Y;
			
            m_suportCombine = false;
			
            nearCallback = near;
            triCallback = TriCallback;
            triArrayCallback = TriArrayCallback;
            m_rayCastManager = new ODERayCastRequestManager(this);

            // Create the world and the first space
            world = d.WorldCreate();
            space = d.HashSpaceCreate(IntPtr.Zero);

            contactgroup = d.JointGroupCreate(0);

            d.WorldSetAutoDisableFlag(world, false);

            #if USE_DRAWSTUFF
            Thread viewthread = new Thread(new ParameterizedThreadStart(startvisualization));
            viewthread.Start();
            #endif

 //           _watermap = new float[258 * 258];

            // Zero out the prim spaces array (we split our space into smaller spaces so
            // we can hit test less.
        }
Beispiel #2
0
        /// <summary>
        /// Initiailizes the scene
        /// Sets many properties that ODE requires to be stable
        /// These settings need to be tweaked 'exactly' right or weird stuff happens.
        /// </summary>
        private void Initialise(Vector3 regionExtent)
        {
			WorldExtents.X = regionExtent.X;
            m_regionWidth = (uint)regionExtent.X;
            WorldExtents.Y = regionExtent.Y;
            m_regionHeight = (uint)regionExtent.Y;
			
            m_suportCombine = false;
			
            nearCallback = near;
            m_rayCastManager = new ODERayCastRequestManager(this);

            // Create the world and the first space
            world = d.WorldCreate();
            space = d.HashSpaceCreate(IntPtr.Zero);

            contactgroup = d.JointGroupCreate(0);

            d.WorldSetAutoDisableFlag(world, false);
        }
Beispiel #3
0
/*
        private void randomizeWater(float baseheight)
        {
            uint heightmapWidth = m_regionWidth + 2;
            uint heightmapHeight = m_regionHeight + 2;
            uint heightmapWidthSamples = m_regionWidth + 2;
            uint heightmapHeightSamples = m_regionHeight + 2;
            float scale = 1.0f;
            float offset = 0.0f;
            float thickness = 2.9f;
            int wrap = 0;

            for (int i = 0; i < (258 * 258); i++)
            {
                _watermap[i] = (baseheight-0.1f) + ((float)fluidRandomizer.Next(1,9) / 10f);
                // m_log.Info((baseheight - 0.1f) + ((float)fluidRandomizer.Next(1, 9) / 10f));
            }

            lock (OdeLock)
            {
                if (WaterGeom != IntPtr.Zero)
                {
                    d.SpaceRemove(space, WaterGeom);
                }
                IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
                d.GeomHeightfieldDataBuildSingle(HeightmapData, _watermap, 0, heightmapWidth, heightmapHeight,
                                                    (int)heightmapWidthSamples, (int)heightmapHeightSamples, scale,
                                                    offset, thickness, wrap);
                d.GeomHeightfieldDataSetBounds(HeightmapData, m_regionWidth, m_regionHeight);
                WaterGeom = d.CreateHeightfield(space, HeightmapData, 1);
                if (WaterGeom != IntPtr.Zero)
                {
                    d.GeomSetCategoryBits(WaterGeom, (int)(CollisionCategories.Water));
                    d.GeomSetCollideBits(WaterGeom, (int)(CollisionCategories.Space));
                }

                geom_name_map[WaterGeom] = "Water";

                d.Matrix3 R = new d.Matrix3();

                Quaternion q1 = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), 1.5707f);
                Quaternion q2 = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), 1.5707f);
                //Axiom.Math.Quaternion q3 = Axiom.Math.Quaternion.FromAngleAxis(3.14f, new Axiom.Math.Vector3(0, 0, 1));

                q1 = q1 * q2;
                //q1 = q1 * q3;
                Vector3 v3;
                float angle;
                q1.GetAxisAngle(out v3, out angle);

                d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle);
                d.GeomSetRotation(WaterGeom, ref R);
                d.GeomSetPosition(WaterGeom, 128, 128, 0);
            }
        }
*/
        public override void Dispose()
        {
            _worldInitialized = false;

            m_rayCastManager.Dispose();
            m_rayCastManager = null;

            lock (OdeLock)
            {
                lock (_prims)
                {
                    foreach (OdePrim prm in _prims)
                    {
                        RemovePrim(prm);
                    }
                }

                //foreach (OdeCharacter act in _characters)
                //{
                    //RemoveAvatar(act);
                //}
                d.WorldDestroy(world);
                //d.CloseODE();
            }

        }
Beispiel #4
0
        public override void Dispose()
        {
            lock(SimulationLock)
                lock(OdeLock)
            {
                if(world == IntPtr.Zero)
                    return;

                _worldInitialized = false;

                d.AllocateODEDataForThread(~0U);

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

                lock (_prims)
                {
                    foreach (OdePrim prm in _prims)
                    {
                        RemovePrim(prm);
                    }
                }

                //foreach (OdeCharacter act in _characters)
                //{
                    //RemoveAvatar(act);
                //}
                IntPtr GroundGeom = IntPtr.Zero;
                if (RegionTerrain.TryGetValue(m_worldOffset, out GroundGeom))
                {
                    RegionTerrain.Remove(m_worldOffset);
                    if (GroundGeom != IntPtr.Zero)
                    {
                        if (TerrainHeightFieldHeights.ContainsKey(GroundGeom))
                            TerrainHeightFieldHeights.Remove(GroundGeom);
                        d.GeomDestroy(GroundGeom);
                    }
                 }

                try
                {
                    d.WorldDestroy(world);
                    world = IntPtr.Zero;
                }
                catch (AccessViolationException e)
                {
                    m_log.ErrorFormat("[ODE SCENE]: exception {0}", e.Message);
                }
            }
        }