Ticket #1988: anchor_no_floats.diff
File anchor_no_floats.diff, 31.9 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; … … 72 74 entity_pos_t m_YOffset; 73 75 bool m_RelativeToGround; // whether m_YOffset is relative to terrain/water plane, or an absolute height 74 76 75 entity_angle_t m_RotX, m_RotY, m_RotZ ;77 entity_angle_t m_RotX, m_RotY, m_RotZ, m_LastRotX, m_LastRotZ; 76 78 float m_InterpolatedRotY; // not serialized 77 79 80 bool recalculateXZRotation; 81 78 82 static std::string GetSchema() 79 83 { 80 84 return … … 89 93 "<choice>" 90 94 "<value a:help='Always stand straight up'>upright</value>" 91 95 "<value a:help='Rotate backwards and forwards to follow the terrain'>pitch</value>" 96 "<value a:help='Rotate sidewards to follow the terrain'>roll</value>" 92 97 "<value a:help='Rotate in all direction to follow the terrain'>pitch-roll</value>" 93 98 "</choice>" 94 99 "</element>" … … 110 115 m_AnchorType = PITCH; 111 116 else if (anchor == L"pitch-roll") 112 117 m_AnchorType = PITCH_ROLL; 118 else if (anchor == L"roll") 119 m_AnchorType = ROLL; 113 120 else 114 121 m_AnchorType = UPRIGHT; 115 122 … … 123 130 124 131 m_RotX = m_RotY = m_RotZ = entity_angle_t::FromInt(0); 125 132 m_InterpolatedRotY = 0; 133 134 m_LastRotX = entity_angle_t::Zero(); 135 m_LastRotZ = entity_angle_t::Zero(); 136 137 recalculateXZRotation = true; 126 138 } 127 139 128 140 virtual void Deinit() … … 152 164 const char* anchor = "???"; 153 165 switch (m_AnchorType) 154 166 { 155 case UPRIGHT: anchor = "upright"; break; 156 case PITCH: anchor = "pitch"; break; 157 case PITCH_ROLL: anchor = "pitch-roll"; break; 167 case PITCH: 168 anchor = "pitch"; 169 break; 170 171 case PITCH_ROLL: 172 anchor = "pitch-roll"; 173 break; 174 175 case ROLL: 176 anchor = "roll"; 177 break; 178 179 case UPRIGHT: // upright is the default 180 default: 181 anchor = "upright"; 182 break; 158 183 } 159 184 serialize.StringASCII("anchor", anchor, 0, 16); 160 185 serialize.Bool("floating", m_Floating); … … 197 222 198 223 virtual void MoveTo(entity_pos_t x, entity_pos_t z) 199 224 { 225 200 226 m_X = x; 201 227 m_Z = z; 202 228 … … 207 233 m_LastZ = m_PrevZ = m_Z; 208 234 } 209 235 236 UpdateXZRotation(); 237 210 238 AdvertisePositionChanges(); 211 239 } 212 240 … … 216 244 m_LastZ = m_PrevZ = m_Z = z; 217 245 m_InWorld = true; 218 246 247 recalculateXZRotation = true; 248 219 249 AdvertisePositionChanges(); 220 250 } 221 251 … … 319 349 320 350 virtual void TurnTo(entity_angle_t y) 321 351 { 352 322 353 m_RotY = y; 323 354 355 UpdateXZRotation(); 356 324 357 AdvertisePositionChanges(); 325 358 } 326 359 … … 329 362 m_RotY = y; 330 363 m_InterpolatedRotY = m_RotY.ToFloat(); 331 364 365 recalculateXZRotation = true; 366 332 367 AdvertisePositionChanges(); 333 368 } 334 369 … … 370 405 rotY = m_InterpolatedRotY; 371 406 } 372 407 408 409 virtual void UpdateXZRotation() 410 { 411 412 if (m_AnchorType == UPRIGHT) 413 // change nothing if anchor is upright 414 return; 415 416 CmpPtr<ICmpTerrain> cmpTerrain(GetSimContext(), SYSTEM_ENTITY); 417 if (!cmpTerrain) 418 return; 419 420 // TODO average normal (average all the tiles?) for big units or for buildings 421 CFixedVector3D normal = cmpTerrain->CalcNormal(m_X, m_Z); 422 423 // rotate the normal so the positive x direction is in the direction of the unit 424 CFixedVector2D projected = CFixedVector2D(normal.X, normal.Z); 425 projected = projected.Rotate(-m_RotY); 426 427 normal.X = projected.X; 428 normal.Z = projected.Y; 429 430 if (m_AnchorType == PITCH || m_AnchorType == PITCH_ROLL) 431 // project and calculate the angle 432 m_RotX = -atan2_approx(normal.Z, normal.Y); 433 434 if (m_AnchorType == ROLL || m_AnchorType == PITCH_ROLL) 435 // project and calculate the angle 436 m_RotZ = atan2_approx(normal.X,normal.Y); 437 438 return; 439 } 440 373 441 virtual CMatrix3D GetInterpolatedTransform(float frameOffset, bool forceFloating) 374 442 { 443 444 375 445 if (!m_InWorld) 376 446 { 377 447 LOGERROR(L"CCmpPosition::GetInterpolatedTransform called on entity when IsInWorld is false"); … … 400 470 401 471 float y = baseY + m_YOffset.ToFloat(); 402 472 403 // TODO: do something with m_AnchorType404 473 405 CMatrix3D m; 406 m.SetXRotation(m_RotX.ToFloat()); 407 m.RotateZ(m_RotZ.ToFloat()); 474 CMatrix3D m; 475 476 // linear interpolation is good enough (for RotX/Z). 477 // As you always stay close to zero angle. 478 m.SetXRotation(Interpolate(m_LastRotX.ToFloat(), m_RotX.ToFloat(), frameOffset)); 479 m.RotateZ(Interpolate(m_LastRotZ.ToFloat(), m_RotZ.ToFloat(), frameOffset)); 480 408 481 m.RotateY(rotY + (float)M_PI); 409 482 m.Translate(CVector3D(x, y, z)); 410 483 … … 417 490 { 418 491 case MT_Interpolate: 419 492 { 493 420 494 const CMessageInterpolate& msgData = static_cast<const CMessageInterpolate&> (msg); 421 495 422 496 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; 497 if (rotY != m_InterpolatedRotY) 498 { 499 float delta = rotY - m_InterpolatedRotY; 500 // Wrap delta to -M_PI..M_PI 501 delta = fmodf(delta + (float)M_PI, 2*(float)M_PI); // range -2PI..2PI 502 if (delta < 0) delta += 2*(float)M_PI; // range 0..2PI 503 delta -= (float)M_PI; // range -M_PI..M_PI 504 // Clamp to max rate 505 float deltaClamped = clamp(delta, -m_RotYSpeed*msgData.deltaSimTime, +m_RotYSpeed*msgData.deltaSimTime); 506 // Calculate new orientation, in a peculiar way in order to make sure the 507 // result gets close to m_orientation (rather than being n*2*M_PI out) 508 m_InterpolatedRotY = rotY + deltaClamped - delta; 509 recalculateXZRotation = true; 510 } 433 511 512 513 434 514 break; 435 515 } 436 516 case MT_TurnStart: 437 {438 517 // Store the positions from the turn before 439 518 m_PrevX = m_LastX; 440 519 m_PrevZ = m_LastZ; 441 520 442 521 m_LastX = m_X; 443 522 m_LastZ = m_Z; 523 524 m_LastRotX = m_RotX; 525 m_LastRotZ = m_RotZ; 444 526 527 if (recalculateXZRotation) 528 { 529 UpdateXZRotation(); 530 531 recalculateXZRotation = false; 532 } 533 445 534 break; 446 }447 }448 535 } 536 }; 449 537 450 538 private: 451 539 void AdvertisePositionChanges()