Ticket #1988: anchor_hybrid.diff
File anchor_hybrid.diff, 37.8 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/simulation/templates/gaia/fauna_bear.xml
18 18 <SpecificName>Bear</SpecificName> 19 19 <Icon>gaia/fauna_bear.png</Icon> 20 20 </Identity> 21 <Position> 22 <Anchor>pitch</Anchor> 23 </Position> 21 24 <Sound> 22 25 <SoundGroups> 23 26 <select>actor/fauna/animal/lion_select.xml</select> -
binaries/data/mods/public/simulation/templates/gaia/fauna_boar.xml
18 18 <SpecificName>Boar</SpecificName> 19 19 <Icon>gaia/fauna_boar.png</Icon> 20 20 </Identity> 21 <Position> 22 <Anchor>pitch</Anchor> 23 </Position> 21 24 <ResourceSupply> 22 25 <Amount>150</Amount> 23 26 <Type>food.meat</Type> -
binaries/data/mods/public/simulation/templates/gaia/fauna_camel.xml
12 12 <Obstruction> 13 13 <Unit radius="1.5"/> 14 14 </Obstruction> 15 <Position> 16 <Anchor>pitch</Anchor> 17 </Position> 15 18 <Sound> 16 19 <SoundGroups> 17 20 <select>actor/fauna/animal/camel.xml</select> -
binaries/data/mods/public/simulation/templates/gaia/fauna_deer.xml
5 5 <SpecificName>Deer</SpecificName> 6 6 <Icon>gaia/fauna_deer.png</Icon> 7 7 </Identity> 8 <Position> 9 <Anchor>pitch</Anchor> 10 </Position> 8 11 <UnitMotion> 9 12 <WalkSpeed>2.0</WalkSpeed> 10 13 <Run> -
binaries/data/mods/public/simulation/templates/gaia/fauna_elephant.xml
14 14 <SpecificName>Elephant</SpecificName> 15 15 <Icon>gaia/fauna_elephant.png</Icon> 16 16 </Identity> 17 <Position> 18 <Anchor>pitch</Anchor> 19 </Position> 17 20 <Sound> 18 21 <SoundGroups> 19 22 <select>actor/fauna/animal/elephant_select.xml</select> -
binaries/data/mods/public/simulation/templates/gaia/fauna_elephant_african_bush.xml
53 53 <Obstruction> 54 54 <Unit radius="3.5"/> 55 55 </Obstruction> 56 <Position> 57 <Anchor>pitch</Anchor> 58 </Position> 56 59 <ResourceSupply> 57 60 <Amount>800</Amount> 58 61 <Type>food.meat</Type> -
binaries/data/mods/public/simulation/templates/gaia/fauna_elephant_african_infant.xml
18 18 <Obstruction> 19 19 <Unit radius="1.5"/> 20 20 </Obstruction> 21 <Position> 22 <Anchor>pitch</Anchor> 23 </Position> 21 24 <ResourceSupply> 22 25 <Amount>100</Amount> 23 26 <Type>food.meat</Type> -
binaries/data/mods/public/simulation/templates/gaia/fauna_elephant_asian.xml
53 53 <Obstruction> 54 54 <Unit radius="2.7"/> 55 55 </Obstruction> 56 <Position> 57 <Anchor>pitch</Anchor> 58 </Position> 56 59 <ResourceSupply> 57 60 <Amount>650</Amount> 58 61 <Type>food.meat</Type> -
binaries/data/mods/public/simulation/templates/gaia/fauna_gazelle.xml
5 5 <SpecificName>Gazelle</SpecificName> 6 6 <Icon>gaia/fauna_gazelle.png</Icon> 7 7 </Identity> 8 <Position> 9 <Anchor>pitch</Anchor> 10 </Position> 8 11 <UnitMotion> 9 12 <Run> 10 13 <Range>600.0</Range> -
binaries/data/mods/public/simulation/templates/gaia/fauna_giraffe.xml
16 16 <Obstruction> 17 17 <Unit radius="2.0"/> 18 18 </Obstruction> 19 <Position> 20 <Anchor>pitch</Anchor> 21 </Position> 19 22 <ResourceSupply> 20 23 <Amount>350</Amount> 21 24 <Type>food.meat</Type> -
binaries/data/mods/public/simulation/templates/gaia/fauna_giraffe_infant.xml
12 12 <Obstruction> 13 13 <Unit radius="1.5"/> 14 14 </Obstruction> 15 <Position> 16 <Anchor>pitch</Anchor> 17 </Position> 15 18 <ResourceSupply> 16 19 <Amount>150</Amount> 17 20 <Type>food.meat</Type> -
binaries/data/mods/public/simulation/templates/gaia/fauna_goat.xml
11 11 <SpecificName>Goat</SpecificName> 12 12 <Icon>gaia/fauna_goat.png</Icon> 13 13 </Identity> 14 <Position> 15 <Anchor>pitch</Anchor> 16 </Position> 14 17 <ResourceSupply> 15 18 <Amount>120</Amount> 16 19 <Type>food.meat</Type> -
binaries/data/mods/public/simulation/templates/gaia/fauna_horse.xml
12 12 <Obstruction> 13 13 <Unit radius="1.5"/> 14 14 </Obstruction> 15 <Position> 16 <Anchor>pitch</Anchor> 17 </Position> 15 18 <ResourceSupply> 16 19 <Amount>200</Amount> 17 20 </ResourceSupply> -
binaries/data/mods/public/simulation/templates/gaia/fauna_lion.xml
18 18 <SpecificName>Lion</SpecificName> 19 19 <Icon>gaia/fauna_lion.png</Icon> 20 20 </Identity> 21 <Position> 22 <Anchor>pitch</Anchor> 23 </Position> 21 24 <Sound> 22 25 <SoundGroups> 23 26 <select>actor/fauna/animal/lion_select.xml</select> -
binaries/data/mods/public/simulation/templates/gaia/fauna_lioness.xml
18 18 <SpecificName>Lion</SpecificName> 19 19 <Icon>gaia/fauna_lion.png</Icon> 20 20 </Identity> 21 <Position> 22 <Anchor>pitch</Anchor> 23 </Position> 21 24 <Sound> 22 25 <SoundGroups> 23 26 <select>actor/fauna/animal/lion_select.xml</select> -
binaries/data/mods/public/simulation/templates/gaia/fauna_muskox.xml
9 9 <SpecificName>Muskox</SpecificName> 10 10 <Icon>gaia/fauna_muskox.png</Icon> 11 11 </Identity> 12 <Position> 13 <Anchor>pitch</Anchor> 14 </Position> 12 15 <ResourceSupply> 13 16 <Amount>200</Amount> 14 17 <Type>food.meat</Type> -
binaries/data/mods/public/simulation/templates/gaia/fauna_pig.xml
5 5 <SpecificName>Pig</SpecificName> 6 6 <Icon>gaia/fauna_pig.png</Icon> 7 7 </Identity> 8 <Position> 9 <Anchor>pitch</Anchor> 10 </Position> 8 11 <StatusBars> 9 12 <HeightOffset>5.0</HeightOffset> 10 13 </StatusBars> -
binaries/data/mods/public/simulation/templates/gaia/fauna_rabbit.xml
9 9 <SpecificName>Rabbit</SpecificName> 10 10 <Icon>gaia/fauna_rabbit.png</Icon> 11 11 </Identity> 12 <Position> 13 <Anchor>pitch</Anchor> 14 </Position> 12 15 <ResourceSupply> 13 16 <Amount>50</Amount> 14 17 <Type>food.meat</Type> -
binaries/data/mods/public/simulation/templates/gaia/fauna_sheep.xml
12 12 <Classes datatype="tokens">Domestic</Classes> 13 13 <Icon>gaia/fauna_sheep.png</Icon> 14 14 </Identity> 15 <Position> 16 <Anchor>pitch</Anchor> 17 </Position> 15 18 <Sound> 16 19 <SoundGroups> 17 20 <select>actor/fauna/animal/sheep.xml</select> -
binaries/data/mods/public/simulation/templates/gaia/fauna_tiger.xml
18 18 <SpecificName>Tiger</SpecificName> 19 19 <Icon>gaia/fauna_tiger.png</Icon> 20 20 </Identity> 21 <Position> 22 <Anchor>pitch</Anchor> 23 </Position> 21 24 <Sound> 22 25 <SoundGroups> 23 26 <select>actor/fauna/animal/lion_select.xml</select> -
binaries/data/mods/public/simulation/templates/gaia/fauna_walrus.xml
23 23 <SpecificName>Walrus</SpecificName> 24 24 <Icon>gaia/fauna_walrus.png</Icon> 25 25 </Identity> 26 <Position> 27 <Anchor>pitch</Anchor> 28 </Position> 26 29 <ResourceSupply> 27 30 <Amount>300</Amount> 28 31 <Type>food.meat</Type> -
binaries/data/mods/public/simulation/templates/gaia/fauna_wildebeest.xml
10 10 <History>The wildebeest (plural wildebeest, wildebeests or wildebai), also called the gnu, is an antelope of the genus Connochaetes. It is a hooved (ungulate) mammal. Wildebeest are well known for their annual migration to new pastures in which vast numbers of wildebeest can be seen crossing rivers, such as the Mara River and dying in large numbers as they attempt to reach the other side. Many of them are eaten by crocodiles while others simply drown. Herds of wildebeest possesses what is known as "swarm intelligence", whereby the animals systematically explore and overcome obstacles as one when, for instance, crossing a river or defending against predator attacks.</History> 11 11 <Icon>gaia/fauna_wildebeest.png</Icon> 12 12 </Identity> 13 <Position> 14 <Anchor>pitch</Anchor> 15 </Position> 13 16 <ResourceSupply> 14 17 <Amount>150</Amount> 15 18 <Type>food.meat</Type> -
binaries/data/mods/public/simulation/templates/gaia/fauna_wolf.xml
18 18 <SpecificName>Wolf</SpecificName> 19 19 <Icon>gaia/fauna_wolf.png</Icon> 20 20 </Identity> 21 <Position> 22 <Anchor>pitch</Anchor> 23 </Position> 21 24 <VisualActor> 22 25 <Actor>fauna/wolf.xml</Actor> 23 26 </VisualActor> -
binaries/data/mods/public/simulation/templates/gaia/fauna_wolf_snow.xml
18 18 <SpecificName>Snow Wolf</SpecificName> 19 19 <Icon>gaia/fauna_wolf_snow.png</Icon> 20 20 </Identity> 21 <Position> 22 <Anchor>pitch</Anchor> 23 </Position> 21 24 <VisualActor> 22 25 <Actor>fauna/wolf_snow.xml</Actor> 23 26 </VisualActor> -
binaries/data/mods/public/simulation/templates/gaia/fauna_zebra.xml
9 9 <SpecificName>Zebra</SpecificName> 10 10 <Icon>gaia/fauna_zebra.png</Icon> 11 11 </Identity> 12 <Position> 13 <Anchor>pitch</Anchor> 14 </Position> 12 15 <ResourceSupply> 13 16 <Amount>150</Amount> 14 17 <Type>food.meat</Type> -
binaries/data/mods/public/simulation/templates/gaia/geology_metal_alpine.xml
1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <Entity parent="template_gaia_geo_mineral"> 3 <Position>4 <Anchor>pitch-roll</Anchor>5 </Position>6 3 <VisualActor> 7 4 <Actor>geology/metalmine_alpine.xml</Actor> 8 5 </VisualActor> -
binaries/data/mods/public/simulation/templates/gaia/geology_metal_desert_small.xml
1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <Entity parent="template_gaia_geo_mineral"> 3 <Position>4 <Anchor>pitch-roll</Anchor>5 </Position>6 3 <VisualActor> 7 4 <Actor>geology/metalmine_desert_small.xml</Actor> 8 5 </VisualActor> -
binaries/data/mods/public/simulation/templates/gaia/geology_metal_greek.xml
1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <Entity parent="template_gaia_geo_mineral"> 3 <Position>4 <Anchor>pitch-roll</Anchor>5 </Position>6 3 <VisualActor> 7 4 <Actor>geology/metalmine_granite_greek.xml</Actor> 8 5 </VisualActor> -
binaries/data/mods/public/simulation/templates/gaia/geology_metal_mediterranean.xml
1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <Entity parent="template_gaia_geo_mineral"> 3 <Position>4 <Anchor>pitch-roll</Anchor>5 </Position>6 3 <VisualActor> 7 4 <Actor>geology/metalmine_mediterranean.xml</Actor> 8 5 </VisualActor> -
binaries/data/mods/public/simulation/templates/gaia/geology_metal_temperate.xml
1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <Entity parent="template_gaia_geo_mineral"> 3 <Position>4 <Anchor>pitch-roll</Anchor>5 </Position>6 3 <VisualActor> 7 4 <Actor>geology/metalmine_granite_temperate.xml</Actor> 8 5 </VisualActor> -
binaries/data/mods/public/simulation/templates/gaia/geology_metal_tropic.xml
1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <Entity parent="template_gaia_geo_mineral"> 3 <Position>4 <Anchor>pitch-roll</Anchor>5 </Position>6 3 <VisualActor> 7 4 <Actor>geology/metalmine_tropic.xml</Actor> 8 5 </VisualActor> -
binaries/data/mods/public/simulation/templates/gaia/geology_stone_alpine_a.xml
1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <Entity parent="template_gaia_geo_rock"> 3 <Position>4 <Anchor>pitch-roll</Anchor>5 </Position>6 3 <VisualActor> 7 4 <Actor>geology/stonemine_alpine_a.xml</Actor> 8 5 </VisualActor> -
binaries/data/mods/public/simulation/templates/gaia/geology_stone_desert_small.xml
7 7 <Identity> 8 8 <Icon>gaia/geology_stone_2.png</Icon> 9 9 </Identity> 10 <Position>11 <Anchor>pitch-roll</Anchor>12 </Position>13 10 <VisualActor> 14 11 <Actor>geology/stonemine_desert_small.xml</Actor> 15 12 </VisualActor> -
binaries/data/mods/public/simulation/templates/gaia/geology_stone_greek.xml
1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <Entity parent="template_gaia_geo_rock"> 3 <Position>4 <Anchor>pitch-roll</Anchor>5 </Position>6 3 <VisualActor> 7 4 <Actor>geology/stonemine_granite_greek.xml</Actor> 8 5 </VisualActor> -
binaries/data/mods/public/simulation/templates/gaia/geology_stone_mediterranean.xml
1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <Entity parent="template_gaia_geo_rock"> 3 <Position>4 <Anchor>pitch-roll</Anchor>5 </Position>6 3 <VisualActor> 7 4 <Actor>geology/stonemine_mediterranean.xml</Actor> 8 5 </VisualActor> -
binaries/data/mods/public/simulation/templates/gaia/geology_stone_savanna_small.xml
7 7 <Identity> 8 8 <Icon>gaia/geology_stone_2.png</Icon> 9 9 </Identity> 10 <Position>11 <Anchor>pitch-roll</Anchor>12 </Position>13 10 <VisualActor> 14 11 <Actor>geology/stonemine_savanna_small.xml</Actor> 15 12 </VisualActor> -
binaries/data/mods/public/simulation/templates/gaia/geology_stone_temperate.xml
1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <Entity parent="template_gaia_geo_rock"> 3 <Position>4 <Anchor>pitch-roll</Anchor>5 </Position>6 3 <VisualActor> 7 4 <Actor>geology/stonemine_granite.xml</Actor> 8 5 </VisualActor> -
binaries/data/mods/public/simulation/templates/gaia/geology_stone_tropic_a.xml
1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <Entity parent="template_gaia_geo_rock"> 3 <Position>4 <Anchor>pitch-roll</Anchor>5 </Position>6 3 <VisualActor> 7 4 <Actor>geology/stonemine_tropic.xml</Actor> 8 5 </VisualActor> -
binaries/data/mods/public/simulation/templates/template_gaia_geo.xml
10 10 <Obstruction> 11 11 <Static width="7.0" depth="7.0"/> 12 12 </Obstruction> 13 <Position> 14 <Anchor>pitch-roll</Anchor> 15 </Position> 13 16 <Selectable> 14 17 <EditorOnly disable=""/> 15 18 <Overlay> -
binaries/data/mods/public/simulation/templates/template_gaia_geo_mineral_slabs.xml
7 7 <Obstruction> 8 8 <Static width="13.0" depth="13.0"/> 9 9 </Obstruction> 10 <Position>11 <Anchor>pitch-roll</Anchor>12 </Position>13 10 <ResourceSupply> 14 11 <Amount>5000</Amount> 15 12 <MaxGatherers>24</MaxGatherers> -
binaries/data/mods/public/simulation/templates/template_gaia_geo_rock_slabs.xml
7 7 <Obstruction> 8 8 <Static width="13.0" depth="13.0"/> 9 9 </Obstruction> 10 <Position>11 <Anchor>pitch-roll</Anchor>12 </Position>13 10 <ResourceSupply> 14 11 <Amount>5000</Amount> 15 12 <MaxGatherers>24</MaxGatherers> -
binaries/data/mods/public/simulation/templates/template_unit_champion_cavalry.xml
42 42 <Obstruction> 43 43 <Unit radius="1.0"/> 44 44 </Obstruction> 45 <Position> 46 <Anchor>pitch</Anchor> 47 </Position> 45 48 <Selectable> 46 49 <Overlay> 47 50 <Texture> -
binaries/data/mods/public/simulation/templates/template_unit_champion_elephant.xml
31 31 <Obstruction> 32 32 <Unit radius="4.0"/> 33 33 </Obstruction> 34 <Position> 35 <Anchor>pitch</Anchor> 36 </Position> 34 37 <Selectable> 35 38 <Overlay> 36 39 <Texture> -
binaries/data/mods/public/simulation/templates/units/maur_support_elephant.xml
38 38 <stone>10</stone> 39 39 <metal>10</metal> 40 40 </Loot> 41 <Position> 42 <Anchor>pitch</Anchor> 43 </Position> 41 44 <ResourceDropsite> 42 45 <Types>food wood stone metal</Types> 43 46 </ResourceDropsite> -
source/simulation2/components/CCmpPosition.cpp
30 30 #include "maths/MathUtil.h" 31 31 #include "maths/Matrix3D.h" 32 32 #include "maths/Vector3D.h" 33 #include "maths/Vector2D.h" 33 34 #include "ps/CLogger.h" 34 35 36 #include "graphics/Terrain.h" 37 #include "math.h" 38 35 39 /** 36 40 * Basic ICmpPosition implementation. 37 41 */ … … 58 62 UPRIGHT = 0, 59 63 PITCH = 1, 60 64 PITCH_ROLL = 2, 65 ROLL=3, 61 66 } m_AnchorType; 62 67 63 68 bool m_Floating; … … 73 78 bool m_RelativeToGround; // whether m_YOffset is relative to terrain/water plane, or an absolute height 74 79 75 80 entity_angle_t m_RotX, m_RotY, m_RotZ; 76 float m_InterpolatedRotY; // not serialized77 81 82 CTerrain* m_Terrain; // not null 83 84 // not serialized; 85 float m_InterpolatedRotX, m_InterpolatedRotY, m_InterpolatedRotZ; 86 float m_LastInterpolatedRotX, m_LastInterpolatedRotZ; // not serialized 87 88 bool recalculateXZRotation, recalculateVisualXZRotation; 89 bool m_ManualXZRotation; 90 78 91 static std::string GetSchema() 79 92 { 80 93 return … … 89 102 "<choice>" 90 103 "<value a:help='Always stand straight up'>upright</value>" 91 104 "<value a:help='Rotate backwards and forwards to follow the terrain'>pitch</value>" 105 "<value a:help='Rotate sidewards to follow the terrain'>roll</value>" 92 106 "<value a:help='Rotate in all direction to follow the terrain'>pitch-roll</value>" 93 107 "</choice>" 94 108 "</element>" … … 110 124 m_AnchorType = PITCH; 111 125 else if (anchor == L"pitch-roll") 112 126 m_AnchorType = PITCH_ROLL; 127 else if (anchor == L"roll") 128 m_AnchorType = ROLL; 113 129 else 114 130 m_AnchorType = UPRIGHT; 115 131 … … 123 139 124 140 m_RotX = m_RotY = m_RotZ = entity_angle_t::FromInt(0); 125 141 m_InterpolatedRotY = 0; 142 m_ManualXZRotation = false; 143 144 m_Terrain = &GetSimContext().GetTerrain(); 145 126 146 } 127 147 128 148 virtual void Deinit() … … 146 166 serialize.NumberFixed_Unbounded("rot z", m_RotZ); 147 167 serialize.NumberFixed_Unbounded("altitude", m_YOffset); 148 168 serialize.Bool("relative", m_RelativeToGround); 169 serialize.Bool("manual rotation",m_ManualXZRotation); 149 170 150 171 if (serialize.IsDebug()) 151 172 { 152 173 const char* anchor = "???"; 153 174 switch (m_AnchorType) 154 175 { 155 case UPRIGHT: anchor = "upright"; break; 156 case PITCH: anchor = "pitch"; break; 157 case PITCH_ROLL: anchor = "pitch-roll"; break; 176 case PITCH: 177 anchor = "pitch"; 178 break; 179 180 case PITCH_ROLL: 181 anchor = "pitch-roll"; 182 break; 183 184 case ROLL: 185 anchor = "roll"; 186 break; 187 188 case UPRIGHT: // upright is the default 189 default: 190 anchor = "upright"; 191 break; 158 192 } 159 193 serialize.StringASCII("anchor", anchor, 0, 16); 160 194 serialize.Bool("floating", m_Floating); … … 178 212 deserialize.NumberFixed_Unbounded("rot z", m_RotZ); 179 213 deserialize.NumberFixed_Unbounded("altitude", m_YOffset); 180 214 deserialize.Bool("relative", m_RelativeToGround); 215 deserialize.Bool("manual rotation",m_ManualXZRotation); 181 216 // TODO: should there be range checks on all these values? 182 217 183 218 m_InterpolatedRotY = m_RotY.ToFloat(); 219 220 UpdateXZRotation(m_X,m_Z,m_RotY); 221 222 m_LastInterpolatedRotX = m_InterpolatedRotX; 223 m_LastInterpolatedRotZ = m_InterpolatedRotZ; 224 184 225 } 185 226 186 227 virtual bool IsInWorld() … … 197 238 198 239 virtual void MoveTo(entity_pos_t x, entity_pos_t z) 199 240 { 241 200 242 m_X = x; 201 243 m_Z = z; 202 244 … … 216 258 m_LastZ = m_PrevZ = m_Z = z; 217 259 m_InWorld = true; 218 260 261 UpdateXZRotation(x,z,m_RotY); 262 263 m_LastInterpolatedRotX = m_InterpolatedRotX; 264 m_LastInterpolatedRotZ = m_InterpolatedRotZ; 265 219 266 AdvertisePositionChanges(); 220 267 } 221 268 … … 319 366 320 367 virtual void TurnTo(entity_angle_t y) 321 368 { 369 322 370 m_RotY = y; 323 371 324 372 AdvertisePositionChanges(); … … 329 377 m_RotY = y; 330 378 m_InterpolatedRotY = m_RotY.ToFloat(); 331 379 380 UpdateXZRotation(m_X,m_Z,m_RotY); 381 382 m_LastInterpolatedRotX = m_InterpolatedRotX; 383 m_LastInterpolatedRotZ = m_InterpolatedRotZ; 384 332 385 AdvertisePositionChanges(); 333 386 } 334 387 … … 336 389 { 337 390 m_RotX = x; 338 391 m_RotZ = z; 392 393 m_ManualXZRotation = true; 339 394 395 UpdateXZRotation(m_X,m_Z,m_RotY); 396 397 m_LastInterpolatedRotX = m_InterpolatedRotX; 398 m_LastInterpolatedRotZ = m_InterpolatedRotZ; 399 340 400 AdvertisePositionChanges(); 341 401 } 342 402 403 virtual void UnSetXZRotation() 404 { 405 m_ManualXZRotation = false; 406 407 UpdateXZRotation(m_X,m_Z,m_RotY); 408 409 m_LastInterpolatedRotX = m_InterpolatedRotX; 410 m_LastInterpolatedRotZ = m_InterpolatedRotZ; 411 412 AdvertisePositionChanges(); 413 414 } 415 343 416 virtual CFixedVector3D GetRotation() 344 417 { 345 418 return CFixedVector3D(m_RotX, m_RotY, m_RotZ); … … 370 443 rotY = m_InterpolatedRotY; 371 444 } 372 445 446 virtual void UpdateXZRotation(entity_pos_t x, entity_pos_t z, entity_angle_t rotY) 447 { 448 UpdateVisualXZRotation(x.ToFloat(), z.ToFloat(), rotY.ToFloat()); 449 450 if(m_ManualXZRotation) 451 return; 452 453 if(m_AnchorType == UPRIGHT) 454 { 455 m_RotX = m_RotZ = entity_pos_t::Zero(); 456 return; 457 } 458 459 CmpPtr<ICmpTerrain> cmpTerrain(GetSimContext(), SYSTEM_ENTITY); 460 if (!cmpTerrain || !cmpTerrain->IsLoaded()) 461 { 462 // try again when terrain is loaded 463 recalculateXZRotation = true; 464 recalculateVisualXZRotation = true; 465 return; 466 } 467 468 CFixedVector3D normal = cmpTerrain->CalcNormal(x,z); 469 470 CFixedVector2D projected = CFixedVector2D(normal.X, normal.Z); 471 projected = projected.Rotate(-rotY); 472 473 normal.X = projected.X; 474 normal.Z = projected.Y; 475 476 if (m_AnchorType == PITCH || m_AnchorType == PITCH_ROLL) 477 // project and calculate the angle 478 m_RotX = -atan2_approx(normal.Z, normal.Y); 479 480 if (m_AnchorType == ROLL || m_AnchorType == PITCH_ROLL) 481 // project and calculate the angle 482 m_RotZ = atan2_approx(normal.X,normal.Y); 483 484 recalculateXZRotation = false; 485 486 return; 487 } 488 489 virtual void UpdateVisualXZRotation(float x, float z, float rotY) 490 { 491 492 493 if (m_ManualXZRotation) 494 { 495 // set the visual rotations to the ones fixed by the interface 496 m_InterpolatedRotX = m_RotX.ToFloat(); 497 m_InterpolatedRotZ = m_RotZ.ToFloat(); 498 return; 499 } 500 501 if (m_AnchorType == UPRIGHT) 502 { 503 m_InterpolatedRotX = m_InterpolatedRotZ = 0.f; 504 return; 505 } 506 507 if (m_Terrain->GetVerticesPerSide() == 0) 508 { 509 // try again when terrain is loaded 510 recalculateVisualXZRotation = true; 511 return; 512 } 513 514 // TODO average normal (average all the tiles?) for big units or for buildings 515 CVector3D normal = m_Terrain->CalcExactNormal(x, z); 516 517 // rotate the normal so the positive x direction is in the direction of the unit 518 CVector2D projected = CVector2D(normal.X, normal.Z); 519 projected.Rotate(rotY); 520 521 normal.X = projected.X; 522 normal.Z = projected.Y; 523 524 if (m_AnchorType == PITCH || m_AnchorType == PITCH_ROLL) 525 // project and calculate the angle 526 m_InterpolatedRotX = -atan2(normal.Z, normal.Y); 527 528 if (m_AnchorType == ROLL || m_AnchorType == PITCH_ROLL) 529 // project and calculate the angle 530 m_InterpolatedRotZ = atan2(normal.X,normal.Y); 531 532 recalculateVisualXZRotation = false; 533 534 return; 535 } 536 373 537 virtual CMatrix3D GetInterpolatedTransform(float frameOffset, bool forceFloating) 374 538 { 539 540 375 541 if (!m_InWorld) 376 542 { 377 543 LOGERROR(L"CCmpPosition::GetInterpolatedTransform called on entity when IsInWorld is false"); … … 400 566 401 567 float y = baseY + m_YOffset.ToFloat(); 402 568 403 // TODO: do something with m_AnchorType404 569 405 CMatrix3D m; 406 m.SetXRotation(m_RotX.ToFloat()); 407 m.RotateZ(m_RotZ.ToFloat()); 570 CMatrix3D m; 571 572 // linear interpolation is good enough (for RotX/Z). 573 // As you always stay close to zero angle. 574 m.SetXRotation(Interpolate(m_LastInterpolatedRotX,m_InterpolatedRotX,frameOffset)); 575 m.RotateZ(Interpolate(m_LastInterpolatedRotZ,m_InterpolatedRotZ,frameOffset)); 576 408 577 m.RotateY(rotY + (float)M_PI); 409 578 m.Translate(CVector3D(x, y, z)); 410 579 … … 417 586 { 418 587 case MT_Interpolate: 419 588 { 589 420 590 const CMessageInterpolate& msgData = static_cast<const CMessageInterpolate&> (msg); 421 591 422 592 float rotY = m_RotY.ToFloat(); 423 float delta = rotY - m_InterpolatedRotY; 424 // Wrap delta to -M_PI..M_PI 425 delta = fmodf(delta + (float)M_PI, 2*(float)M_PI); // range -2PI..2PI 426 if (delta < 0) delta += 2*(float)M_PI; // range 0..2PI 427 delta -= (float)M_PI; // range -M_PI..M_PI 428 // Clamp to max rate 429 float deltaClamped = clamp(delta, -m_RotYSpeed*msgData.deltaSimTime, +m_RotYSpeed*msgData.deltaSimTime); 430 // Calculate new orientation, in a peculiar way in order to make sure the 431 // result gets close to m_orientation (rather than being n*2*M_PI out) 432 m_InterpolatedRotY = rotY + deltaClamped - delta; 593 433 594 595 if (rotY != m_InterpolatedRotY) 596 { 597 float delta = rotY - m_InterpolatedRotY; 598 // Wrap delta to -M_PI..M_PI 599 delta = fmodf(delta + (float)M_PI, 2*(float)M_PI); // range -2PI..2PI 600 if (delta < 0) delta += 2*(float)M_PI; // range 0..2PI 601 delta -= (float)M_PI; // range -M_PI..M_PI 602 // Clamp to max rate 603 float deltaClamped = clamp(delta, -m_RotYSpeed*msgData.deltaSimTime, +m_RotYSpeed*msgData.deltaSimTime); 604 // Calculate new orientation, in a peculiar way in order to make sure the 605 // result gets close to m_orientation (rather than being n*2*M_PI out) 606 m_InterpolatedRotY = rotY + deltaClamped - delta; 607 608 m_LastInterpolatedRotX = m_InterpolatedRotX; 609 m_LastInterpolatedRotZ = m_InterpolatedRotZ; 610 611 // update the visual XZ rotation 612 UpdateVisualXZRotation(m_X.ToFloat(),m_Z.ToFloat(),m_InterpolatedRotY); 613 } 614 615 if (recalculateVisualXZRotation) 616 { 617 // something went wrong with the previous calculation (terrain not loaded), we need to update the rotation without interpolation 618 UpdateVisualXZRotation(m_X.ToFloat(), m_Z.ToFloat(),rotY); 619 m_LastInterpolatedRotX = m_InterpolatedRotX; 620 m_LastInterpolatedRotZ = m_InterpolatedRotZ; 621 } 622 434 623 break; 435 624 } 436 625 case MT_TurnStart: 437 { 626 627 m_LastInterpolatedRotX = m_InterpolatedRotX; 628 m_LastInterpolatedRotZ = m_InterpolatedRotZ; 629 630 if (m_LastX != m_X || m_LastZ != m_Z || recalculateXZRotation) 631 { 632 UpdateXZRotation(m_X, m_Z,m_RotY); 633 } 634 438 635 // Store the positions from the turn before 439 636 m_PrevX = m_LastX; 440 637 m_PrevZ = m_LastZ; 441 638 442 639 m_LastX = m_X; 443 640 m_LastZ = m_Z; 444 641 445 642 break; 446 }447 }448 643 } 644 }; 449 645 450 646 private: 451 647 void AdvertisePositionChanges() -
source/simulation2/components/ICmpPosition.cpp
37 37 DEFINE_INTERFACE_METHOD_1("TurnTo", void, ICmpPosition, TurnTo, entity_angle_t) 38 38 DEFINE_INTERFACE_METHOD_1("SetYRotation", void, ICmpPosition, SetYRotation, entity_angle_t) 39 39 DEFINE_INTERFACE_METHOD_2("SetXZRotation", void, ICmpPosition, SetXZRotation, entity_angle_t, entity_angle_t) 40 DEFINE_INTERFACE_METHOD_0("UnSetXZRotation", void, ICmpPosition, UnSetXZRotation) 40 41 DEFINE_INTERFACE_METHOD_0("GetRotation", CFixedVector3D, ICmpPosition, GetRotation) 41 42 // Excluded: GetInterpolatedTransform (not safe for scripts) 42 43 END_INTERFACE_WRAPPER(Position) -
source/simulation2/components/ICmpPosition.h
140 140 */ 141 141 virtual void SetXZRotation(entity_angle_t x, entity_angle_t z) = 0; 142 142 143 /** 144 * Unset the XZ rotation (let it handle by the Anchor and terrain) 145 */ 146 virtual void UnSetXZRotation() = 0; 147 148 143 149 // NOTE: we separate Y from XZ because most code will only ever change Y; 144 150 // XZ are typically just used in the editor, and other code should never 145 151 // worry about them -
source/simulation2/components/tests/test_RangeManager.h
55 55 virtual void TurnTo(entity_angle_t UNUSED(y)) { } 56 56 virtual void SetYRotation(entity_angle_t UNUSED(y)) { } 57 57 virtual void SetXZRotation(entity_angle_t UNUSED(x), entity_angle_t UNUSED(z)) { } 58 virtual void UnSetXZRotation() { } 58 59 virtual CFixedVector3D GetRotation() { return CFixedVector3D(); } 59 60 virtual fixed GetDistanceTravelled() { return fixed::Zero(); } 60 61 virtual void GetInterpolatedPosition2D(float UNUSED(frameOffset), float& x, float& z, float& rotY) { x = z = rotY = 0; }