Ticket #1988: anchor_only_visual.diff
File anchor_only_visual.diff, 33.5 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 35 36 /** … … 58 59 UPRIGHT = 0, 59 60 PITCH = 1, 60 61 PITCH_ROLL = 2, 62 ROLL=3, 61 63 } m_AnchorType; 62 64 63 65 bool m_Floating; … … 73 75 bool m_RelativeToGround; // whether m_YOffset is relative to terrain/water plane, or an absolute height 74 76 75 77 entity_angle_t m_RotX, m_RotY, m_RotZ; 76 float m_InterpolatedRotY; // not serialized77 78 79 // not serialized; 80 float m_InterpolatedRotX, m_InterpolatedRotY, m_InterpolatedRotZ; 81 float m_LastInterpolatedRotX, m_LastInterpolatedRotZ; // not serialized 82 83 bool recalculateXZRotation; 84 85 CTerrain* m_Terrain; 86 78 87 static std::string GetSchema() 79 88 { 80 89 return … … 89 98 "<choice>" 90 99 "<value a:help='Always stand straight up'>upright</value>" 91 100 "<value a:help='Rotate backwards and forwards to follow the terrain'>pitch</value>" 101 "<value a:help='Rotate sidewards to follow the terrain'>roll</value>" 92 102 "<value a:help='Rotate in all direction to follow the terrain'>pitch-roll</value>" 93 103 "</choice>" 94 104 "</element>" … … 110 120 m_AnchorType = PITCH; 111 121 else if (anchor == L"pitch-roll") 112 122 m_AnchorType = PITCH_ROLL; 123 else if (anchor == L"roll") 124 m_AnchorType = ROLL; 113 125 else 114 126 m_AnchorType = UPRIGHT; 115 127 … … 123 135 124 136 m_RotX = m_RotY = m_RotZ = entity_angle_t::FromInt(0); 125 137 m_InterpolatedRotY = 0; 138 139 m_Terrain = &GetSimContext().GetTerrain(); 140 126 141 } 127 142 128 143 virtual void Deinit() … … 152 167 const char* anchor = "???"; 153 168 switch (m_AnchorType) 154 169 { 155 case UPRIGHT: anchor = "upright"; break; 156 case PITCH: anchor = "pitch"; break; 157 case PITCH_ROLL: anchor = "pitch-roll"; break; 170 case PITCH: 171 anchor = "pitch"; 172 break; 173 174 case PITCH_ROLL: 175 anchor = "pitch-roll"; 176 break; 177 178 case ROLL: 179 anchor = "roll"; 180 break; 181 182 case UPRIGHT: // upright is the default 183 default: 184 anchor = "upright"; 185 break; 158 186 } 159 187 serialize.StringASCII("anchor", anchor, 0, 16); 160 188 serialize.Bool("floating", m_Floating); … … 181 209 // TODO: should there be range checks on all these values? 182 210 183 211 m_InterpolatedRotY = m_RotY.ToFloat(); 212 213 m_Terrain = &GetSimContext().GetTerrain(); 214 215 UpdateXZRotation(m_X.ToFloat(), m_Z.ToFloat(), m_InterpolatedRotY); 184 216 } 185 217 186 218 virtual bool IsInWorld() … … 197 229 198 230 virtual void MoveTo(entity_pos_t x, entity_pos_t z) 199 231 { 232 200 233 m_X = x; 201 234 m_Z = z; 202 235 … … 216 249 m_LastZ = m_PrevZ = m_Z = z; 217 250 m_InWorld = true; 218 251 252 UpdateXZRotation(x.ToFloat(),z.ToFloat(),m_RotY.ToFloat()); 253 254 m_LastInterpolatedRotX = m_InterpolatedRotX; 255 m_LastInterpolatedRotZ = m_InterpolatedRotZ; 256 219 257 AdvertisePositionChanges(); 220 258 } 221 259 … … 319 357 320 358 virtual void TurnTo(entity_angle_t y) 321 359 { 360 322 361 m_RotY = y; 323 362 324 363 AdvertisePositionChanges(); … … 329 368 m_RotY = y; 330 369 m_InterpolatedRotY = m_RotY.ToFloat(); 331 370 371 UpdateXZRotation(m_X.ToFloat(),m_Z.ToFloat(),m_InterpolatedRotY); 372 373 m_LastInterpolatedRotX = m_InterpolatedRotX; 374 m_LastInterpolatedRotZ = m_InterpolatedRotZ; 375 332 376 AdvertisePositionChanges(); 333 377 } 334 378 … … 337 381 m_RotX = x; 338 382 m_RotZ = z; 339 383 384 UpdateXZRotation(m_X.ToFloat(),m_Z.ToFloat(),m_RotY.ToFloat()); 385 386 m_LastInterpolatedRotX = m_InterpolatedRotX; 387 m_LastInterpolatedRotZ = m_InterpolatedRotZ; 388 340 389 AdvertisePositionChanges(); 341 390 } 342 391 … … 370 419 rotY = m_InterpolatedRotY; 371 420 } 372 421 422 423 virtual void UpdateXZRotation(float x, float z, float rotY) 424 { 425 426 427 if (!m_RotZ.IsZero() || !m_RotX.IsZero()) 428 { 429 // set the visual rotations to the ones fixed by the interface 430 m_InterpolatedRotX = m_RotX.ToFloat(); 431 m_InterpolatedRotZ = m_RotZ.ToFloat(); 432 return; 433 } 434 435 if (m_AnchorType == UPRIGHT) 436 // change nothing if anchor is upright 437 return; 438 439 if (m_Terrain->GetVerticesPerSide() == 0) 440 { 441 // try again when terrain is loaded 442 recalculateXZRotation = true; 443 return; 444 } 445 446 // TODO average normal (average all the tiles?) for big units or for buildings 447 CVector3D normal = m_Terrain->CalcExactNormal(x, z); 448 449 // rotate the normal so the positive x direction is in the direction of the unit 450 CVector2D projected = CVector2D(normal.X, normal.Z); 451 projected.Rotate(rotY); 452 453 normal.X = projected.X; 454 normal.Z = projected.Y; 455 456 if (m_AnchorType == PITCH || m_AnchorType == PITCH_ROLL) 457 // project and calculate the angle 458 m_InterpolatedRotX = -atan2(normal.Z, normal.Y); 459 460 if (m_AnchorType == ROLL || m_AnchorType == PITCH_ROLL) 461 // project and calculate the angle 462 m_InterpolatedRotZ = atan2(normal.X,normal.Y); 463 464 recalculateXZRotation = false; 465 466 return; 467 } 468 373 469 virtual CMatrix3D GetInterpolatedTransform(float frameOffset, bool forceFloating) 374 470 { 471 472 375 473 if (!m_InWorld) 376 474 { 377 475 LOGERROR(L"CCmpPosition::GetInterpolatedTransform called on entity when IsInWorld is false"); … … 400 498 401 499 float y = baseY + m_YOffset.ToFloat(); 402 500 403 // TODO: do something with m_AnchorType404 501 405 CMatrix3D m; 406 m.SetXRotation(m_RotX.ToFloat()); 407 m.RotateZ(m_RotZ.ToFloat()); 502 CMatrix3D m; 503 504 // linear interpolation is good enough (for RotX/Z). 505 // As you always stay close to zero angle. 506 m.SetXRotation(Interpolate(m_LastInterpolatedRotX,m_InterpolatedRotX,frameOffset)); 507 m.RotateZ(Interpolate(m_LastInterpolatedRotZ,m_InterpolatedRotZ,frameOffset)); 508 408 509 m.RotateY(rotY + (float)M_PI); 409 510 m.Translate(CVector3D(x, y, z)); 410 511 … … 417 518 { 418 519 case MT_Interpolate: 419 520 { 521 420 522 const CMessageInterpolate& msgData = static_cast<const CMessageInterpolate&> (msg); 421 523 422 524 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; 525 433 526 527 if (rotY != m_InterpolatedRotY) 528 { 529 float delta = rotY - m_InterpolatedRotY; 530 // Wrap delta to -M_PI..M_PI 531 delta = fmodf(delta + (float)M_PI, 2*(float)M_PI); // range -2PI..2PI 532 if (delta < 0) delta += 2*(float)M_PI; // range 0..2PI 533 delta -= (float)M_PI; // range -M_PI..M_PI 534 // Clamp to max rate 535 float deltaClamped = clamp(delta, -m_RotYSpeed*msgData.deltaSimTime, +m_RotYSpeed*msgData.deltaSimTime); 536 // Calculate new orientation, in a peculiar way in order to make sure the 537 // result gets close to m_orientation (rather than being n*2*M_PI out) 538 m_InterpolatedRotY = rotY + deltaClamped - delta; 539 540 m_LastInterpolatedRotX = m_InterpolatedRotX; 541 m_LastInterpolatedRotZ = m_InterpolatedRotZ; 542 543 // update the visual XZ rotation 544 UpdateXZRotation(m_X.ToFloat(),m_Z.ToFloat(),m_InterpolatedRotY); 545 } 546 547 if (recalculateXZRotation) 548 { 549 // something went wrong with the previous calculation (terrain not loaded), we need to update the rotation without interpolation 550 UpdateXZRotation(m_X.ToFloat(), m_Z.ToFloat(),m_RotY.ToFloat()); 551 m_LastInterpolatedRotX = m_InterpolatedRotX; 552 m_LastInterpolatedRotZ = m_InterpolatedRotZ; 553 } 554 434 555 break; 435 556 } 436 557 case MT_TurnStart: 437 { 558 559 m_LastInterpolatedRotX = m_InterpolatedRotX; 560 m_LastInterpolatedRotZ = m_InterpolatedRotZ; 561 562 if (m_LastX != m_X || m_LastZ != m_Z) 563 { 564 UpdateXZRotation(m_X.ToFloat(), m_Z.ToFloat(),m_RotY.ToFloat()); 565 } 566 438 567 // Store the positions from the turn before 439 568 m_PrevX = m_LastX; 440 569 m_PrevZ = m_LastZ; 441 570 442 571 m_LastX = m_X; 443 572 m_LastZ = m_Z; 444 573 445 574 break; 446 }447 }448 575 } 576 }; 449 577 450 578 private: 451 579 void AdvertisePositionChanges()