diff options
author | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
---|---|---|
committer | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
commit | 134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch) | |
tree | 216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs | |
parent | More changing to production grid. Double oops. (diff) | |
download | opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2 opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz |
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs | 171 |
1 files changed, 0 insertions, 171 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs deleted file mode 100755 index e4fecc3..0000000 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs +++ /dev/null | |||
@@ -1,171 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyrightD | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Text; | ||
30 | |||
31 | using OpenSim.Framework; | ||
32 | using OpenSim.Region.Framework; | ||
33 | using OpenSim.Region.CoreModules; | ||
34 | using OpenSim.Region.Physics.Manager; | ||
35 | |||
36 | using Nini.Config; | ||
37 | using log4net; | ||
38 | |||
39 | using OpenMetaverse; | ||
40 | |||
41 | namespace OpenSim.Region.Physics.BulletSPlugin | ||
42 | { | ||
43 | public sealed class BSTerrainHeightmap : BSTerrainPhys | ||
44 | { | ||
45 | static string LogHeader = "[BULLETSIM TERRAIN HEIGHTMAP]"; | ||
46 | |||
47 | BulletHMapInfo m_mapInfo = null; | ||
48 | |||
49 | // Constructor to build a default, flat heightmap terrain. | ||
50 | public BSTerrainHeightmap(BSScene physicsScene, Vector3 regionBase, uint id, Vector3 regionSize) | ||
51 | : base(physicsScene, regionBase, id) | ||
52 | { | ||
53 | Vector3 minTerrainCoords = new Vector3(0f, 0f, BSTerrainManager.HEIGHT_INITIALIZATION - BSTerrainManager.HEIGHT_EQUAL_FUDGE); | ||
54 | Vector3 maxTerrainCoords = new Vector3(regionSize.X, regionSize.Y, BSTerrainManager.HEIGHT_INITIALIZATION); | ||
55 | int totalHeights = (int)maxTerrainCoords.X * (int)maxTerrainCoords.Y; | ||
56 | float[] initialMap = new float[totalHeights]; | ||
57 | for (int ii = 0; ii < totalHeights; ii++) | ||
58 | { | ||
59 | initialMap[ii] = BSTerrainManager.HEIGHT_INITIALIZATION; | ||
60 | } | ||
61 | m_mapInfo = new BulletHMapInfo(id, initialMap); | ||
62 | m_mapInfo.minCoords = minTerrainCoords; | ||
63 | m_mapInfo.maxCoords = maxTerrainCoords; | ||
64 | m_mapInfo.terrainRegionBase = TerrainBase; | ||
65 | // Don't have to free any previous since we just got here. | ||
66 | BuildHeightmapTerrain(); | ||
67 | } | ||
68 | |||
69 | // This minCoords and maxCoords passed in give the size of the terrain (min and max Z | ||
70 | // are the high and low points of the heightmap). | ||
71 | public BSTerrainHeightmap(BSScene physicsScene, Vector3 regionBase, uint id, float[] initialMap, | ||
72 | Vector3 minCoords, Vector3 maxCoords) | ||
73 | : base(physicsScene, regionBase, id) | ||
74 | { | ||
75 | m_mapInfo = new BulletHMapInfo(id, initialMap); | ||
76 | m_mapInfo.minCoords = minCoords; | ||
77 | m_mapInfo.maxCoords = maxCoords; | ||
78 | m_mapInfo.minZ = minCoords.Z; | ||
79 | m_mapInfo.maxZ = maxCoords.Z; | ||
80 | m_mapInfo.terrainRegionBase = TerrainBase; | ||
81 | |||
82 | // Don't have to free any previous since we just got here. | ||
83 | BuildHeightmapTerrain(); | ||
84 | } | ||
85 | |||
86 | public override void Dispose() | ||
87 | { | ||
88 | ReleaseHeightMapTerrain(); | ||
89 | } | ||
90 | |||
91 | // Using the information in m_mapInfo, create the physical representation of the heightmap. | ||
92 | private void BuildHeightmapTerrain() | ||
93 | { | ||
94 | // Create the terrain shape from the mapInfo | ||
95 | m_mapInfo.terrainShape = PhysicsScene.PE.CreateTerrainShape( m_mapInfo.ID, | ||
96 | new Vector3(m_mapInfo.sizeX, m_mapInfo.sizeY, 0), m_mapInfo.minZ, m_mapInfo.maxZ, | ||
97 | m_mapInfo.heightMap, 1f, BSParam.TerrainCollisionMargin); | ||
98 | |||
99 | |||
100 | // The terrain object initial position is at the center of the object | ||
101 | Vector3 centerPos; | ||
102 | centerPos.X = m_mapInfo.minCoords.X + (m_mapInfo.sizeX / 2f); | ||
103 | centerPos.Y = m_mapInfo.minCoords.Y + (m_mapInfo.sizeY / 2f); | ||
104 | centerPos.Z = m_mapInfo.minZ + ((m_mapInfo.maxZ - m_mapInfo.minZ) / 2f); | ||
105 | |||
106 | m_mapInfo.terrainBody = PhysicsScene.PE.CreateBodyWithDefaultMotionState(m_mapInfo.terrainShape, | ||
107 | m_mapInfo.ID, centerPos, Quaternion.Identity); | ||
108 | |||
109 | // Set current terrain attributes | ||
110 | PhysicsScene.PE.SetFriction(m_mapInfo.terrainBody, BSParam.TerrainFriction); | ||
111 | PhysicsScene.PE.SetHitFraction(m_mapInfo.terrainBody, BSParam.TerrainHitFraction); | ||
112 | PhysicsScene.PE.SetRestitution(m_mapInfo.terrainBody, BSParam.TerrainRestitution); | ||
113 | PhysicsScene.PE.SetCollisionFlags(m_mapInfo.terrainBody, CollisionFlags.CF_STATIC_OBJECT); | ||
114 | |||
115 | // Return the new terrain to the world of physical objects | ||
116 | PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, m_mapInfo.terrainBody); | ||
117 | |||
118 | // redo its bounding box now that it is in the world | ||
119 | PhysicsScene.PE.UpdateSingleAabb(PhysicsScene.World, m_mapInfo.terrainBody); | ||
120 | |||
121 | m_mapInfo.terrainBody.collisionType = CollisionType.Terrain; | ||
122 | m_mapInfo.terrainBody.ApplyCollisionMask(PhysicsScene); | ||
123 | |||
124 | // Make it so the terrain will not move or be considered for movement. | ||
125 | PhysicsScene.PE.ForceActivationState(m_mapInfo.terrainBody, ActivationState.DISABLE_SIMULATION); | ||
126 | |||
127 | return; | ||
128 | } | ||
129 | |||
130 | // If there is information in m_mapInfo pointing to physical structures, release same. | ||
131 | private void ReleaseHeightMapTerrain() | ||
132 | { | ||
133 | if (m_mapInfo != null) | ||
134 | { | ||
135 | if (m_mapInfo.terrainBody.HasPhysicalBody) | ||
136 | { | ||
137 | PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, m_mapInfo.terrainBody); | ||
138 | // Frees both the body and the shape. | ||
139 | PhysicsScene.PE.DestroyObject(PhysicsScene.World, m_mapInfo.terrainBody); | ||
140 | } | ||
141 | } | ||
142 | m_mapInfo = null; | ||
143 | } | ||
144 | |||
145 | // The passed position is relative to the base of the region. | ||
146 | public override float GetTerrainHeightAtXYZ(Vector3 pos) | ||
147 | { | ||
148 | float ret = BSTerrainManager.HEIGHT_GETHEIGHT_RET; | ||
149 | |||
150 | int mapIndex = (int)pos.Y * (int)m_mapInfo.sizeY + (int)pos.X; | ||
151 | try | ||
152 | { | ||
153 | ret = m_mapInfo.heightMap[mapIndex]; | ||
154 | } | ||
155 | catch | ||
156 | { | ||
157 | // Sometimes they give us wonky values of X and Y. Give a warning and return something. | ||
158 | PhysicsScene.Logger.WarnFormat("{0} Bad request for terrain height. terrainBase={1}, pos={2}", | ||
159 | LogHeader, m_mapInfo.terrainRegionBase, pos); | ||
160 | ret = BSTerrainManager.HEIGHT_GETHEIGHT_RET; | ||
161 | } | ||
162 | return ret; | ||
163 | } | ||
164 | |||
165 | // The passed position is relative to the base of the region. | ||
166 | public override float GetWaterLevelAtXYZ(Vector3 pos) | ||
167 | { | ||
168 | return PhysicsScene.SimpleWaterLevel; | ||
169 | } | ||
170 | } | ||
171 | } | ||