Rise
The Vieneo Province
StreetView.cpp
Go to the documentation of this file.
1 #include "Instrument.h"
2 #include "../Bus.h"
3 #include "../Viewscreen/Viewscreen.h"
4 
5 StreetView::StreetView(int prmX, int prmY, float prmXScale, float prmYScale, Bus* prmBus, Logger* prmLogger, DeviceObject* prmDevice, std::vector<Font*> prmFonts) :
6  Instrument(prmX, prmY, prmXScale, prmYScale, prmBus, prmLogger, prmDevice, prmFonts)
7 {
8  logger->AddToCallStack("StreetView::ctor");
9  defaultFont = 1;
10 
11  width = 137.0f;
12  height = 64.0f;
13 
14  cityMap = new Sprite(logger, pDevice, "Textures/Instruments/citymap.dds", prmX, prmY, 0.0f, 0, 0, 2048, 2048, 0xFFFFFFFF);
15  airplane = new Sprite(logger, pDevice, "Textures/Instruments/icon-vehicle.png", prmX + static_cast<int>(width * 0.5f - 3.5f), prmY + static_cast<int>(height * 0.5f - 3.5f), 0.1f, 0, 0, 7, 15, 0xFFFFFFFF);
16  navTarget = new Sprite(logger, pDevice, "Textures/Instruments/navtarget.png", prmX, prmY, 0.2f, 0, 0, 7, 7, 0xFFFFFFFF);
17 }
18 
20 {
21  cityMap->Draw();
22 
23  airplane->Draw();
24 
25  navTarget->Draw();
26 }
27 
28 void StreetView::FrameMove(float fElapsed)
29 {
30 
31  const float lnguv = (static_cast<float>(newdepthpos.u) / static_cast<float>(depthFloorResolutionC) + (static_cast<float>(bus->tcp.u) - 519.0f))*2048.0f*0.3333333f;
32  const float latuv = (static_cast<float>(newdepthpos.v) / static_cast<float>(depthFloorResolutionC) + (static_cast<float>(bus->tcp.v) - 1101.0f))*2048.0f*0.3333333f;
33 
34  // so mag is 1 at 10km scale ... but that is actually 138/2048 or 0.673828125km across, 0.3369140625 from the center to edge
35  cityMap->mag = 10.0f / bus->MapScaleInnerRingKm;
36  RECT rect;
37  rect.top = static_cast<long>(latuv - 0.5f * height / cityMap->mag);
38  rect.left = static_cast<long>(lnguv - 0.5f * width / cityMap->mag);
39  rect.right = static_cast<long>(lnguv + 0.5f * width / cityMap->mag);
40  rect.bottom = static_cast<long>(latuv + 0.5f * height / cityMap->mag);
41  cityMap->SetRectangle(rect.top, rect.left, rect.right, rect.bottom);
42  cityMap->Update();
43 
44  airplane->rotate = -D3DXToRadian(bus->HeadingTrueDegrees);
45  airplane->Update();
46 
47  // so we sin and cos based on insthdg and clamp to coords
48  const float f_temp = bus->TargetDistanceKm * cityMap->mag / 0.3369140625f * cosf(D3DXToRadian(mark)); // forces it on ground plane
49  D3DXVECTOR2 result;
50  result.x = width * 0.5f - 3.5f + width * 0.5f*sinf(D3DXToRadian(bus->HeadingTrueDegrees + bear))* f_temp;
51  result.y = height * 0.5f - 3.5f - height * 0.5f*cosf(D3DXToRadian(bus->HeadingTrueDegrees + bear))* f_temp;
52 
53  if (result.x < -3.0f)
54  result.x = -3.0f;
55  else if (result.x > width - 5)
56  result.x = width - 5;
57  if (result.y < -3.0f)
58  result.y = -3.0f;
59  else if (result.y > height - 4)
60  result.y = height - 4;
61  navTarget->SetLocation(static_cast<int>(x + result.x), static_cast<int>(y + result.y));
62  navTarget->Update();
63 }
void SetLocation(int absoluteX, int absoluteY)
Definition: Sprite.cpp:90
float mag
Definition: Sprite.h:31
float HeadingTrueDegrees
Definition: Bus.h:30
void SetRectangle(int top, int left, int right, int bottom)
Definition: Sprite.cpp:96
Definition: Logger.h:9
void Render() override
Definition: StreetView.cpp:19
DeviceObject * pDevice
Definition: Instrument.h:17
void Update()
Definition: Sprite.cpp:41
float TargetDistanceKm
Definition: Bus.h:393
float rotate
Definition: Sprite.h:30
void Draw(D3DXCOLOR prmColor)
Definition: Sprite.cpp:66
float mark
Definition: globals.cpp:59
Definition: Bus.h:16
Sprite * cityMap
Definition: Instrument.h:401
Definition: Sprite.h:7
float width
Definition: Instrument.h:404
Bus * bus
Definition: Instrument.h:18
UINT defaultFont
Definition: Instrument.h:20
float bear
Definition: globals.cpp:58
float MapScaleInnerRingKm
Definition: Bus.h:381
#define depthFloorResolutionC
Definition: Viewscreen.h:28
VECTOR2SHORT newdepthpos
Definition: globals.cpp:140
StreetView(int prmX, int prmY, float prmXScale, float prmYScale, Bus *prmBus, Logger *prmLogger, DeviceObject *prmDevice, std::vector< Font *> prmFonts)
Definition: StreetView.cpp:5
float height
Definition: Instrument.h:404
Logger * logger
Definition: Instrument.h:19
Sprite * airplane
Definition: Instrument.h:402
void AddToCallStack(const char *msg)
Definition: Logger.cpp:86
void FrameMove(float fElapsed) override
Definition: StreetView.cpp:28
VECTOR2SHORT tcp
Definition: Bus.h:236
Sprite * navTarget
Definition: Instrument.h:403