Commit MetaInfo

修订版51b5ec4a1033ec5089ce304afc75e7f1da9c55a8 (tree)
时间2019-11-05 11:08:42
作者 <jarmonik@c0f5...>

Log Message

- Branch unification

更改概述

差异

diff -r e20b4b8a0ac2 -r 51b5ec4a1033 Orbitersdk/D3D9Client/D3D9Client.cpp
--- a/Orbitersdk/D3D9Client/D3D9Client.cpp Tue Nov 05 00:28:42 2019 +0000
+++ b/Orbitersdk/D3D9Client/D3D9Client.cpp Tue Nov 05 02:08:42 2019 +0000
@@ -632,7 +632,7 @@
632632 //
633633 bRunning = false;
634634
635- // At fisrt, shutdown tile loaders -------------------------------------------------------
635+ // At first, shutdown tile loaders -------------------------------------------------------
636636 //
637637 if (TileBuffer::ShutDown()==false) LogErr("Failed to Shutdown TileBuffer()");
638638 if (TileManager2Base::ShutDown()==false) LogErr("Failed to Shutdown TileManager2Base()");
diff -r e20b4b8a0ac2 -r 51b5ec4a1033 Orbitersdk/D3D9Client/D3D9Pad.cpp
--- a/Orbitersdk/D3D9Client/D3D9Pad.cpp Tue Nov 05 00:28:42 2019 +0000
+++ b/Orbitersdk/D3D9Client/D3D9Pad.cpp Tue Nov 05 02:08:42 2019 +0000
@@ -37,17 +37,16 @@
3737 // ===============================================================================================
3838
3939 struct FontCache {
40- int height;
41- int orient;
42- bool prop;
43- char face[64];
40+ int height;
41+ int orient;
42+ bool prop;
43+ char face[64];
4444 Font::Style style;
45- class D3D9Text *pFont;
46-} fcache[256];
45+ D3D9TextPtr pFont;
46+};
47+std::vector<FontCache *> fcache;
4748
4849
49-int nfcache = 0;
50-
5150 oapi::Font * deffont = 0;
5251 oapi::Pen * defpen = 0;
5352
@@ -56,9 +55,6 @@
5655 //
5756 void D3D9Pad::D3D9TechInit(D3D9Client *_gc, LPDIRECT3DDEVICE9 pDevice)
5857 {
59- memset2(fcache, 0, 256*sizeof(FontCache));
60- nfcache = 0;
61-
6258 pDev = pDevice;
6359 gc = _gc;
6460
@@ -141,15 +137,16 @@
141137 //
142138 void D3D9Pad::GlobalExit()
143139 {
144- LogAlw("Clearing Font Cache... %d Fonts are stored in the cache",nfcache);
145- for (int i=0;i<nfcache;i++) if (fcache[i].pFont) delete fcache[i].pFont;
140+ LogAlw("Clearing Font Cache... %d Fonts are stored in the cache",fcache.size());
141+ for (auto it = fcache.begin(); it != fcache.end(); ++it) {
142+ delete *it;
143+ }
144+ fcache.clear();
146145
147146 SAFE_RELEASE(FX);
148147 SAFE_DELETEA(Idx);
149148 SAFE_DELETEA(Vtx);
150149 SAFE_DELETEA(pSinCos);
151-
152- memset2(fcache, 0, 256*sizeof(FontCache));
153150 }
154151
155152
@@ -366,6 +363,7 @@
366363 pDev->SetRenderState(D3DRS_ZWRITEENABLE, 0);
367364 }
368365
366+
369367 HR(FX->SetFloat(eRandom, float(oapiRand())));
370368 HR(FX->SetVector(eTarget, &vTarget));
371369
@@ -391,15 +389,13 @@
391389
392390 HR(FX->EndPass());
393391 HR(FX->End());
394-
395-
392+
396393 HR(pDev->SetRenderState(D3DRS_ALPHABLENDENABLE, bkALPHA));
397394 HR(pDev->SetRenderState(D3DRS_ZENABLE, bkZEN));
398395 HR(pDev->SetRenderState(D3DRS_ZWRITEENABLE, bkZW));
399396 HR(pDev->SetRenderState(D3DRS_CULLMODE, bkCULL));
400397 HR(pDev->SetRenderState(D3DRS_SCISSORTESTENABLE, 0));
401398
402-
403399 iI = vI = 0;
404400
405401 return true;
@@ -708,6 +704,17 @@
708704
709705 // ===============================================================================================
710706 //
707+DWORD D3D9Pad::GetLineHeight () // ... *with* "internal leading"
708+{
709+ TEXTMETRIC tm;
710+ if (cfont == NULL) return 0;
711+ static_cast<D3D9PadFont *>(cfont)->pFont->GetD3D9TextMetrics(&tm);
712+ return tm.tmHeight;
713+}
714+
715+
716+// ===============================================================================================
717+//
711718 DWORD D3D9Pad::GetTextWidth (const char *str, int len)
712719 {
713720 if (str) if (str[0] == '_') if (strcmp(str, "_SkpVerInfo") == 0) return 2;
@@ -790,7 +797,7 @@
790797 //
791798 void D3D9Pad::WrapOneLine (char* str, int len, int maxWidth)
792799 {
793- D3D9Text *pText = static_cast<D3D9PadFont *>(cfont)->pFont;
800+ D3D9TextPtr pText = static_cast<D3D9PadFont *>(cfont)->pFont;
794801 if (pText->Length2(str) > maxWidth) {
795802 char *pStr = str, // sub-string start
796803 *it = pStr, // 'iterator' char
@@ -854,7 +861,7 @@
854861
855862 if (cfont==NULL) return false;
856863
857- D3D9Text *pText = static_cast<D3D9PadFont *>(cfont)->pFont;
864+ D3D9TextPtr pText = static_cast<D3D9PadFont *>(cfont)->pFont;
858865
859866 switch(tah) {
860867 default:
@@ -1549,7 +1556,6 @@
15491556 }
15501557 else face++;
15511558
1552- pFont = NULL;
15531559 hFont = NULL;
15541560
15551561 if (orientation!=0) rotation = float(orientation) * 0.1f;
@@ -1558,12 +1564,12 @@
15581564 // Browse cache ---------------------------------------------------
15591565 //
15601566
1561- for (int i=0;i<nfcache;i++) {
1562- if (fcache[i].height!=height) continue;
1563- if (fcache[i].style!=style) continue;
1564- if (fcache[i].prop!=prop) continue;
1565- if (_stricmp(fcache[i].face,face)!=0) continue;
1566- pFont = fcache[i].pFont;
1567+ for (size_t i = 0; i < fcache.size(); ++i) {
1568+ if (fcache[i]->height!=height) continue;
1569+ if (fcache[i]->style!=style) continue;
1570+ if (fcache[i]->prop!=prop) continue;
1571+ if (_stricmp(fcache[i]->face,face)!=0) continue;
1572+ pFont = fcache[i]->pFont;
15671573 break;
15681574 }
15691575
@@ -1588,23 +1594,21 @@
15881594
15891595 HFONT hNew = CreateFont(height, 0, 0, 0, weight, italic, underline, 0, 0, 0, 2, Quality, 49, face);
15901596
1591- pFont = new D3D9Text(pDev);
1597+ pFont = std::make_shared<D3D9Text>(pDev);
15921598 pFont->Init(hNew);
15931599
15941600 DeleteObject(hNew);
15951601
15961602 pFont->SetRotation(rotation);
15971603
1598- if (nfcache>250) LogErr("Font Cache is Full.");
1599- else {
1600- // Fill the cache --------------------------------
1601- fcache[nfcache].pFont = pFont;
1602- fcache[nfcache].height = height;
1603- fcache[nfcache].style = style;
1604- fcache[nfcache].prop = prop;
1605- strcpy_s(fcache[nfcache].face, 64, face);
1606- nfcache++;
1607- }
1604+ // Fill the cache --------------------------------
1605+ FontCache *p = new FontCache();
1606+ p->pFont = pFont;
1607+ p->height = height;
1608+ p->style = style;
1609+ p->prop = prop;
1610+ strcpy_s(p->face, 64, face);
1611+ fcache.push_back(p);
16081612 }
16091613
16101614 // Create Rotated windows GDI Font for a use with GDIPad ---------------------------
@@ -1621,7 +1625,7 @@
16211625 //
16221626 D3D9PadFont::~D3D9PadFont ()
16231627 {
1624- if (pFont) pFont->SetRotation(0.0f);
1628+ if (pFont) pFont->SetRotation(0.0f), pFont.reset();
16251629 if (hFont) DeleteObject(hFont);
16261630 }
16271631
diff -r e20b4b8a0ac2 -r 51b5ec4a1033 Orbitersdk/D3D9Client/D3D9Pad.h
--- a/Orbitersdk/D3D9Client/D3D9Pad.h Tue Nov 05 00:28:42 2019 +0000
+++ b/Orbitersdk/D3D9Client/D3D9Pad.h Tue Nov 05 02:08:42 2019 +0000
@@ -26,6 +26,7 @@
2626 #include "Sketchpad2.h"
2727 #include <d3d9.h>
2828 #include <d3dx9.h>
29+#include <memory>
2930 #include <stack>
3031
3132 using namespace oapi;
@@ -58,7 +59,7 @@
5859 #define SKPSW_PENCOLOR 0x00000080 // Index 2
5960 #define SKPSW_TEXTURE 0x000000FF // Index 2
6061
61-// Specials:
62+// Specials:
6263 #define SKPSW_FONT 0x0000FF00 // Index 1
6364 #define SKPSW_COLORKEY 0x00008000 // Index 1
6465 #define SKPSW_LENGTH 0x00FF0000 // Index 0
@@ -85,6 +86,7 @@
8586 #define nQueueMax 2048
8687 #define nIndexMax (nQueueMax * 3)
8788
89+typedef std::shared_ptr<D3D9Text> D3D9TextPtr;
8890
8991 struct SkpColor {
9092
@@ -171,7 +173,7 @@
171173
172174 inline void SkpVtxFF(SkpVtx &v, float _x, float _y, float _tx, float _ty)
173175 {
174- // Note: -0.5f has been substarcted already from x,y data
176+ // Note: -0.5f has been substarcted already from x,y data
175177 v.x = _x;
176178 v.y = _y;
177179 v.nx = _tx;
@@ -557,7 +559,8 @@
557559 LPD3DXMATRIX WorldMatrix();
558560 void CopyRectNative(LPDIRECT3DTEXTURE9 pSrc, LPRECT s, int tx, int ty);
559561 void StretchRectNative(LPDIRECT3DTEXTURE9 pSrc, LPRECT s, LPRECT t);
560- const char *GetName() { return name; }
562+ DWORD GetLineHeight(); ///< Return height of a character in the currently selected font with "internal leading"
563+ const char *GetName() const { return name; }
561564 LPDIRECT3DSURFACE9 GetRenderTarget() const { return pTgt; }
562565 bool IsStillDrawing() const { return bBeginDraw; }
563566 void LoadDefaults();
@@ -627,13 +630,13 @@
627630 RECT src;
628631
629632 D3DSURFACE_DESC tgt_desc;
630- LPDIRECT3DSURFACE9 pTgt;
633+ LPDIRECT3DSURFACE9 pTgt;
631634 LPDIRECT3DSURFACE9 pDep;
632635 LPDIRECT3DTEXTURE9 hTexture;
633636 LPDIRECT3DTEXTURE9 hFontTex;
634637
635638
636-
639+
637640 // Sketchpad3 --------------------------------------------------------------
638641 DWORD RenderConfig;
639642 DWORD Enable;
@@ -669,7 +672,7 @@
669672 static D3DXHANDLE eDrawMesh;
670673 static D3DXHANDLE eSketch;
671674 static D3DXHANDLE eWVP; // Transformation matrix
672- static D3DXHANDLE eTex0;
675+ static D3DXHANDLE eTex0;
673676 static D3DXHANDLE eFnt0;
674677 static D3DXHANDLE eNoiseTex;
675678 static D3DXHANDLE eNoiseColor;
@@ -751,7 +754,7 @@
751754 int GetIndexByPosition(const char *pText, int pos, int len) const;
752755
753756 private:
754- class D3D9Text *pFont;
757+ D3D9TextPtr pFont;
755758 HFONT hFont;
756759 DWORD Quality;
757760 float rotation;
@@ -849,7 +852,7 @@
849852 void RenderGroup(DWORD idx);
850853 SURFHANDLE GetTexture(DWORD idx);
851854 D3DXCOLOR GetMaterial(DWORD idx);
852- DWORD GroupCount() { return nGrp; }
855+ DWORD GroupCount() const { return nGrp; }
853856
854857 private:
855858
@@ -919,7 +922,7 @@
919922 private:
920923 int style;
921924 WORD nPt;
922- LPDIRECT3DVERTEXBUFFER9 pVB;
925+ LPDIRECT3DVERTEXBUFFER9 pVB;
923926 };
924927
925928
diff -r e20b4b8a0ac2 -r 51b5ec4a1033 Orbitersdk/D3D9Client/D3D9Pad2.cpp
--- a/Orbitersdk/D3D9Client/D3D9Pad2.cpp Tue Nov 05 00:28:42 2019 +0000
+++ b/Orbitersdk/D3D9Client/D3D9Pad2.cpp Tue Nov 05 02:08:42 2019 +0000
@@ -25,6 +25,7 @@
2525 #include "Scene.h"
2626 #include "Mesh.h"
2727 #include <d3dx9.h>
28+#include <sstream>
2829
2930
3031
@@ -52,7 +53,7 @@
5253 if (QPen.bEnabled) {
5354 if ((QPen.style == style) && (QPen.width == width) && (QPen.color == color)) return;
5455 }
55-
56+
5657 Change |= SKPCHG_PEN;
5758
5859 cpen = NULL;
@@ -243,16 +244,33 @@
243244
244245
245246 // ===============================================================================================
246-// NOT APART OF ORBITER 2016
247-/*
248-bool D3D9Pad::TextW(int x, int y, const LPWSTR str, int len)
247+//
248+/* Not a part of 2016
249+bool D3D9Pad::TextW (int x, int y, const LPWSTR str, int len)
249250 {
250251 // No "Setup" here, done in PrintSkp()
252+
251253 if (!cfont) return false;
252254 if (len == -1) len = wcslen(str);
253255 if (!len) return true;
254-}*/
255256
257+ D3D9TextPtr pText = static_cast<D3D9PadFont *>(cfont)->pFont;
258+
259+ int lineSpace = pText->GetLineSpace();
260+
261+ std::wstring _str(str, str + len);
262+
263+ std::wistringstream f(_str);
264+ std::wstring s;
265+ int _y = y;
266+ while (getline(f, s, L'\n')) {
267+ pText->PrintSkp(this, x - 1.0f, _y - 1.0f, s.c_str(), -1);
268+ _y += lineSpace;
269+ }
270+
271+ return true;
272+}
273+*/
256274
257275 // ===============================================================================================
258276 //
@@ -262,7 +280,7 @@
262280
263281 if (cfont == NULL) return;
264282
265- D3D9Text *pText = static_cast<D3D9PadFont *>(cfont)->pFont;
283+ D3D9TextPtr pText = static_cast<D3D9PadFont *>(cfont)->pFont;
266284
267285 switch (tah) {
268286 default:
@@ -468,9 +486,9 @@
468486 }
469487 return;
470488 }
471-
489+
472490 TexChangeNative(SURFACE(hNew)->GetTexture());
473-
491+
474492 if (SURFACE(hNew)->IsColorKeyEnabled()) {
475493 bColorKey = true;
476494 cColorKey = SURFACE(hNew)->ClrKey;
@@ -503,7 +521,7 @@
503521 //
504522 hMesh->Init();
505523 pDev->SetVertexDeclaration(pNTVertexDecl);
506-
524+
507525 if (flags&MF_CULL_NONE) pDev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
508526 else pDev->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
509527
@@ -1060,4 +1078,4 @@
10601078 Vtx[i].fnc = SKPSW_CENTER | SKPSW_FRAGMENT;
10611079 }
10621080 HR(pVB->Unlock());
1063-}
\ No newline at end of file
1081+}
diff -r e20b4b8a0ac2 -r 51b5ec4a1033 Orbitersdk/D3D9Client/D3D9Util.cpp
--- a/Orbitersdk/D3D9Client/D3D9Util.cpp Tue Nov 05 00:28:42 2019 +0000
+++ b/Orbitersdk/D3D9Client/D3D9Util.cpp Tue Nov 05 02:08:42 2019 +0000
@@ -515,9 +515,9 @@
515515 }
516516
517517 // lowercase complete string
518-void toLower (std::string &s) {
519- std::transform(s.begin(), s.end(), s.begin(), std::tolower);
520-}
518+//void toLower (std::string &s) {
519+// std::transform(s.begin(), s.end(), s.begin(), std::tolower);
520+//}
521521
522522 // string to double (returns quiet_NaN if conversion failed)
523523 double toDoubleOrNaN (const std::string &str)
diff -r e20b4b8a0ac2 -r 51b5ec4a1033 Orbitersdk/D3D9Client/D3D9Util.h
--- a/Orbitersdk/D3D9Client/D3D9Util.h Tue Nov 05 00:28:42 2019 +0000
+++ b/Orbitersdk/D3D9Client/D3D9Util.h Tue Nov 05 02:08:42 2019 +0000
@@ -512,7 +512,7 @@
512512 void toUpper (std::string &s);
513513
514514 // lowercase complete string
515-void toLower (std::string &s);
515+//void toLower (std::string &s);
516516
517517 // string to double (returns quiet_NaN if conversion failed)
518518 double toDoubleOrNaN (const std::string &str);
diff -r e20b4b8a0ac2 -r 51b5ec4a1033 Orbitersdk/D3D9Client/Mesh.cpp
--- a/Orbitersdk/D3D9Client/Mesh.cpp Tue Nov 05 00:28:42 2019 +0000
+++ b/Orbitersdk/D3D9Client/Mesh.cpp Tue Nov 05 02:08:42 2019 +0000
@@ -222,7 +222,7 @@
222222 Grp = new GROUPREC[nGrp]; memset2(Grp, 0, sizeof(GROUPREC) * nGrp);
223223
224224 for (DWORD i=0;i<nGrp;i++) {
225- SetGroupRec(i, hGroup[i]);
225+ SetGroupRec(i, hGroup[i]);
226226 Grp[i].TexIdxEx[0] = SPEC_DEFAULT;
227227 Grp[i].TexMixEx[0] = 0.0f;
228228 Grp[i].TexIdx = i;
@@ -259,7 +259,7 @@
259259 D3D9Mesh::D3D9Mesh(const MESHGROUPEX *pGroup, const MATERIAL *pMat, D3D9ClientSurface *pTex) : D3D9Effect()
260260 {
261261 Null();
262-
262+
263263 // template meshes are stored in system memory
264264 nGrp = 1;
265265 Grp = new GROUPREC[nGrp]; memset2(Grp, 0, sizeof(GROUPREC) * nGrp);
@@ -271,7 +271,7 @@
271271 Mtrl = new D3D9MatExt[nMtrl];
272272 pGrpTF = new D3DXMATRIX[nGrp];
273273
274- SetGroupRec(0, pGroup);
274+ SetGroupRec(0, pGroup);
275275
276276 pBuf = new MeshBuffer(MaxVert, MaxFace, this);
277277
@@ -362,7 +362,7 @@
362362 void D3D9Mesh::Release()
363363 {
364364 SAFE_DELETEA(Locals);
365- SAFE_DELETEA(Grp);
365+ SAFE_DELETEA(Grp);
366366 SAFE_DELETEA(Tex);
367367 SAFE_DELETEA(Mtrl);
368368 SAFE_DELETEA(pGrpTF);
@@ -545,11 +545,7 @@
545545 }
546546 }
547547 }
548-
549- if (bPopUp) {
550- assert(false);
551- MessageBoxA(NULL, "Invalid Mesh Detected", "D3D9Client Error:", MB_OK);
552- }
548+ if (bPopUp) MessageBoxA(NULL, "Invalid Mesh Detected", "D3D9Client Error:",MB_OK);
553549 }
554550
555551
@@ -590,7 +586,7 @@
590586 if (!IsOK()) return;
591587
592588 if (bTextured) {
593-
589+
594590 XMVECTOR *ta = (XMVECTOR*)_aligned_malloc(sizeof(__m128)*(nVtx+1), 16);
595591 XMVECTOR zero = XMVectorSet(0, 0, 0, 0);
596592 for (DWORD i = 0; i < nVtx; i++) ta[i] = zero;
@@ -646,15 +642,14 @@
646642 }
647643
648644
645+
649646 // ===========================================================================================
650647 //
651648 void D3D9Mesh::SetGroupRec(DWORD i, const MESHGROUPEX *mg)
652649 {
653650 if (i>=nGrp) return;
654-
655651 memcpy2(Grp[i].TexIdxEx, mg->TexIdxEx, MAXTEX*sizeof(DWORD));
656652 memcpy2(Grp[i].TexMixEx, mg->TexMixEx, MAXTEX*sizeof(float));
657-
658653 Grp[i].TexIdx = mg->TexIdx;
659654 Grp[i].MtrlIdx = mg->MtrlIdx;
660655 Grp[i].IdexOff = MaxFace*3;
@@ -668,7 +663,7 @@
668663 D3DXMatrixIdentity(&Grp[i].Transform);
669664
670665 MaxFace += Grp[i].nFace;
671- MaxVert += Grp[i].nVert;
666+ MaxVert += Grp[i].nVert;
672667 }
673668
674669
@@ -703,7 +698,6 @@
703698
704699 pVert[i].u = pNT[i].tu;
705700 pVert[i].v = pNT[i].tv;
706-
707701 pVert[i].w = 1.0f;
708702 pVert[i].tx = 1.0f;
709703 pVert[i].ty = 0.0f;
@@ -814,7 +808,7 @@
814808 NTVERTEX Convert(NMVERTEX &v)
815809 {
816810 NTVERTEX n;
817- n.x = v.x; n.y = v.y; n.z = v.z;
811+ n.x = v.x; n.y = v.y; n.z = v.z;
818812 n.nx = v.nx; n.ny = v.ny; n.nz = v.nz;
819813 n.tu = v.u; n.tv = v.v;
820814 return n;
@@ -1039,42 +1033,42 @@
10391033 // SET ---------------------------------------------------------------
10401034 if (bSet && value) {
10411035 switch (mid) {
1042- case MESHM_DIFFUSE:
1043- Mtrl[idx].Diffuse = *((D3DXVECTOR4*)value);
1036+ case MESHM_DIFFUSE:
1037+ Mtrl[idx].Diffuse = *((D3DXVECTOR4*)value);
10441038 Mtrl[idx].ModFlags |= D3D9MATEX_DIFFUSE;
10451039 bMtrlModidied = true;
10461040 return 0;
1047- case MESHM_AMBIENT:
1048- Mtrl[idx].Ambient = *((D3DXVECTOR3*)value);
1041+ case MESHM_AMBIENT:
1042+ Mtrl[idx].Ambient = *((D3DXVECTOR3*)value);
10491043 Mtrl[idx].ModFlags |= D3D9MATEX_AMBIENT;
10501044 bMtrlModidied = true;
10511045 return 0;
1052- case MESHM_SPECULAR:
1053- Mtrl[idx].Specular = *((D3DXVECTOR4*)value);
1046+ case MESHM_SPECULAR:
1047+ Mtrl[idx].Specular = *((D3DXVECTOR4*)value);
10541048 Mtrl[idx].ModFlags |= D3D9MATEX_SPECULAR;
10551049 bMtrlModidied = true;
10561050 return 0;
10571051 case MESHM_EMISSION:
1058- Mtrl[idx].Emissive = *((D3DXVECTOR3*)value);
1052+ Mtrl[idx].Emissive = *((D3DXVECTOR3*)value);
10591053 Mtrl[idx].ModFlags |= D3D9MATEX_EMISSIVE;
10601054 bMtrlModidied = true;
10611055 return 0;
1062- case MESHM_EMISSION2:
1063- Mtrl[idx].Emission2 = *((D3DXVECTOR3*)value);
1056+ case MESHM_EMISSION2:
1057+ Mtrl[idx].Emission2 = *((D3DXVECTOR3*)value);
10641058 Mtrl[idx].ModFlags |= D3D9MATEX_EMISSION2;
10651059 bMtrlModidied = true;
10661060 return 0;
1067- case MESHM_REFLECT:
1068- Mtrl[idx].Reflect = *((D3DXVECTOR3*)value);
1061+ case MESHM_REFLECT:
1062+ Mtrl[idx].Reflect = *((D3DXVECTOR3*)value);
10691063 Mtrl[idx].ModFlags |= D3D9MATEX_REFLECT;
10701064 bMtrlModidied = true;
10711065 return 0;
10721066 case MESHM_ROUGHNESS:
1073- Mtrl[idx].Roughness = value->g;
1067+ Mtrl[idx].Roughness = value->g;
10741068 Mtrl[idx].ModFlags |= D3D9MATEX_ROUGHNESS;
10751069 bMtrlModidied = true;
10761070 return 0;
1077- case MESHM_FRESNEL:
1071+ case MESHM_FRESNEL:
10781072 Mtrl[idx].Fresnel = *((D3DXVECTOR3*)value);
10791073 Mtrl[idx].ModFlags |= D3D9MATEX_FRESNEL;
10801074 bMtrlModidied = true;
@@ -1141,24 +1135,24 @@
11411135 Mtrl[idx].ModFlags &= (~D3D9MATEX_EMISSIVE);
11421136 bMtrlModidied = true;
11431137 return 0;
1144- case MESHM_EMISSION2:
1145- Mtrl[idx].Emission2 = D3DXVECTOR3(1, 1, 1);
1146- Mtrl[idx].ModFlags &= (~D3D9MATEX_EMISSION2);
1138+ case MESHM_EMISSION2:
1139+ Mtrl[idx].Emission2 = D3DXVECTOR3(1, 1, 1);
1140+ Mtrl[idx].ModFlags &= (~D3D9MATEX_EMISSION2);
11471141 bMtrlModidied = true;
11481142 return 0;
1149- case MESHM_REFLECT:
1150- Mtrl[idx].Reflect = D3DXVECTOR3(0,0,0);
1151- Mtrl[idx].ModFlags &= (~D3D9MATEX_REFLECT);
1143+ case MESHM_REFLECT:
1144+ Mtrl[idx].Reflect = D3DXVECTOR3(0,0,0);
1145+ Mtrl[idx].ModFlags &= (~D3D9MATEX_REFLECT);
11521146 bMtrlModidied = true;
11531147 return 0;
1154- case MESHM_ROUGHNESS:
1155- Mtrl[idx].Roughness = 0.0f;
1156- Mtrl[idx].ModFlags &= (~D3D9MATEX_ROUGHNESS);
1148+ case MESHM_ROUGHNESS:
1149+ Mtrl[idx].Roughness = 0.0f;
1150+ Mtrl[idx].ModFlags &= (~D3D9MATEX_ROUGHNESS);
11571151 bMtrlModidied = true;
11581152 return 0;
1159- case MESHM_FRESNEL:
1160- Mtrl[idx].Fresnel = D3DXVECTOR3(1, 0, 1024.0f);
1161- Mtrl[idx].ModFlags &= (~D3D9MATEX_FRESNEL);
1153+ case MESHM_FRESNEL:
1154+ Mtrl[idx].Fresnel = D3DXVECTOR3(1, 0, 1024.0f);
1155+ Mtrl[idx].ModFlags &= (~D3D9MATEX_FRESNEL);
11621156 bMtrlModidied = true;
11631157 return 0;
11641158 }
@@ -1274,7 +1268,7 @@
12741268
12751269 Grp[g].Shader = SHADER_PBR;
12761270 Grp[g].PBRStatus = 0;
1277-
1271+
12781272 DWORD ti = Grp[g].TexIdx;
12791273
12801274 if (Tex[ti] != NULL) {
@@ -1353,11 +1347,11 @@
13531347 bool bMeshCull = true;
13541348 bool bTextured = true;
13551349 bool bGroupCull = true;
1356- bool bUpdateFlow = true;
1350+ bool bUpdateFlow = true;
13571351 bool bShadowProjection = false;
13581352
1359-
1360-
1353+
1354+
13611355 switch (iTech) {
13621356 case RENDER_VC:
13631357 EnablePlanetGlow(false);
@@ -1398,7 +1392,7 @@
13981392 }
13991393
14001394 D3DXMATRIX mWorldMesh;
1401-
1395+
14021396 if (bGlobalTF) D3DXMatrixMultiply(&mWorldMesh, &mTransform, pW);
14031397 else mWorldMesh = *pW;
14041398
@@ -1406,7 +1400,7 @@
14061400
14071401 D3D9MatExt *mat, *old_mat = NULL;
14081402 LPD3D9CLIENTSURFACE old_tex = NULL;
1409-
1403+
14101404 pDev->SetVertexDeclaration(pMeshVertexDecl);
14111405 pDev->SetStreamSource(0, pBuf->pVB, 0, sizeof(NMVERTEX));
14121406 pDev->SetIndices(pBuf->pIB);
@@ -1437,7 +1431,7 @@
14371431 int nMeshLights = 0;
14381432 D3DXVECTOR3 pos;
14391433 D3DXVec3TransformCoord(&pos, &D3DXVECTOR3f4(BBox.bs), pW);
1440-
1434+
14411435 // Find all local lights effecting this mesh ------------------------------------------
14421436 //
14431437 for (int i = 0; i < nSceneLights; i++) {
@@ -1452,21 +1446,21 @@
14521446
14531447 FX->SetBool(eLightsEnabled, true);
14541448
1455- // If any, Sort the list based on illuminance -------------------------------------------
1449+ // If any, Sort the list based on illuminance -------------------------------------------
14561450 qsort(LightList, nMeshLights, sizeof(_LightList), compare_lights);
14571451
14581452 nMeshLights = min(nMeshLights, Config->MaxLights());
14591453
14601454 // Create a list of N most effective lights ---------------------------------------------
1461- for (int i = 0; i < nMeshLights; i++) memcpy2(&Locals[i], &pLights[LightList[i].idx], sizeof(LightStruct));
1455+ for (int i = 0; i < nMeshLights; i++) memcpy2(&Locals[i], &pLights[LightList[i].idx], sizeof(LightStruct));
14621456 }
14631457 }
14641458
14651459 FX->SetValue(eLights, Locals, sizeof(LightStruct) * Config->MaxLights());
1466-
1460+
14671461
14681462 if (nEnv >= 1 && pEnv[0]) FX->SetTexture(eEnvMapA, pEnv[0]);
1469-
1463+
14701464
14711465 UINT numPasses = 0;
14721466 HR(FX->Begin(&numPasses, D3DXFX_DONOTSAVESTATE));
@@ -1480,10 +1474,10 @@
14801474
14811475 for (DWORD g=0; g<nGrp; g++) {
14821476
1483-
1477+
14841478 bool bHUD = (Grp[g].MFDScreenId == 0x100);
14851479
1486- // Inline engine renders HUD/MFDs in a separate rendering pass and flag 0x2 is used to disable rendering during the main rendering pass
1480+ // Inline engine renders HUD/MFDs in a separate rendering pass and flag 0x2 is used to disable rendering during the main rendering pass
14871481 if ((Grp[g].UsrFlag & 0x2) && (!bHUD)) continue;
14881482
14891483
@@ -1513,7 +1507,7 @@
15131507 HR(FX->BeginPass(Grp[g].Shader));
15141508 CurrentShader = Grp[g].Shader;
15151509 }
1516-
1510+
15171511
15181512
15191513 // Mesh Debugger -------------------------------------------------------------------------------------------
@@ -1570,7 +1564,7 @@
15701564
15711565 if (CurrentShader == SHADER_LEGACY) {
15721566 if (tni && Grp[g].TexMixEx[0] < 0.5f) tni = 0;
1573- if (tni && Tex[tni]) FX->SetTexture(eEmisMap, Tex[tni]->GetTexture());
1567+ if (tni && Tex[tni]) FX->SetTexture(eEmisMap, Tex[tni]->GetTexture());
15741568 }
15751569 else {
15761570
@@ -1635,14 +1629,14 @@
16351629 old_mat = NULL;
16361630 reset(FC);
16371631 bUpdateFlow = true;
1638-
1632+
16391633 SURFHANDLE hMFD;
16401634 if (bHUD) hMFD = gc->GetVCHUDSurface(&hudspec);
16411635 else hMFD = gc->GetMFDSurface(Grp[g].MFDScreenId - 1);
16421636
16431637 if (hMFD) FX->SetTexture(eTex0, SURFACE(hMFD)->GetTexture());
16441638 else FX->SetTexture(eTex0, gc->GetDefaultTexture()->GetTexture());
1645-
1639+
16461640 if (Grp[g].MtrlIdx==SPEC_DEFAULT) mat = &mfdmat;
16471641 else mat = &Mtrl[Grp[g].MtrlIdx];
16481642
@@ -1689,7 +1683,7 @@
16891683 bUpdateFlow = false;
16901684 HR(FX->SetValue(eFlow, &FC, sizeof(TexFlow)));
16911685 }
1692-
1686+
16931687 bool bPBR = (Grp[g].PBRStatus & 0xF) == (0x8 + 0x4);
16941688 bool bRGH = (Grp[g].PBRStatus & 0xE) == (0x8 + 0x2);
16951689 bool bNoL = (Grp[g].UsrFlag & 0x04) != 0;
@@ -1704,7 +1698,7 @@
17041698 FX->SetBool(eNoColor, bNoC);
17051699 FX->SetBool(eSwitch, bPBR);
17061700 FX->SetBool(eRghnSw, bRGH);
1707-
1701+
17081702
17091703 // Update envmap and fresnel status as required
17101704 if (bRefl) {
@@ -1944,17 +1938,17 @@
19441938
19451939 FX->SetBool(eLightsEnabled, true);
19461940
1947- // If any, Sort the list based on illuminance -------------------------------------------
1941+ // If any, Sort the list based on illuminance -------------------------------------------
19481942 qsort(LightList, nMeshLights, sizeof(_LightList), compare_lights);
19491943
19501944 nMeshLights = min(nMeshLights, Config->MaxLights());
19511945
19521946 // Create a list of N most effective lights ---------------------------------------------
19531947 int i;
1954- for (i = 0; i < nMeshLights; i++) memcpy2(&Locals[i], &pLights[LightList[i].idx], sizeof(LightStruct));
1948+ for (i = 0; i < nMeshLights; i++) memcpy2(&Locals[i], &pLights[LightList[i].idx], sizeof(LightStruct));
19551949 }
19561950 }
1957-
1951+
19581952 FX->SetValue(eLights, Locals, sizeof(LightStruct) * Config->MaxLights());
19591953
19601954 UINT numPasses = 0;
@@ -2022,7 +2016,7 @@
20222016 D3D9Stats.Mesh.TexChanges++;
20232017
20242018 if (DebugControls::IsActive()) if (pTune) FX->SetValue(eTune, &pTune[ti], sizeof(D3D9Tune));
2025-
2019+
20262020 old_tex = Tex[ti];
20272021 FX->SetTexture(eTex0, Tex[ti]->GetTexture());
20282022
@@ -2217,7 +2211,7 @@
22172211 D3D9MatExt *mat, *old_mat = NULL;
22182212 LPD3D9CLIENTSURFACE old_tex = NULL;
22192213 LPDIRECT3DTEXTURE9 pNorm = NULL;
2220-
2214+
22212215 pDev->SetVertexDeclaration(pMeshVertexDecl);
22222216 pDev->SetStreamSource(0, pBuf->pVB, 0, sizeof(NMVERTEX));
22232217 pDev->SetIndices(pBuf->pIB);
@@ -2231,8 +2225,8 @@
22312225 //FX->SetBool(eUseSpec, false);
22322226 //FX->SetBool(eUseEmis, false);
22332227 //FX->SetBool(eUseRefl, false);
2234-
2235-
2228+
2229+
22362230 UINT numPasses = 0;
22372231 HR(FX->Begin(&numPasses, D3DXFX_DONOTSAVESTATE));
22382232
@@ -2253,7 +2247,7 @@
22532247 DWORD tni=Grp[g].TexIdxEx[0];
22542248
22552249 if (ti==0 && tni!=0) continue;
2256-
2250+
22572251 if (Tex[ti]==NULL || ti==0) bTextured = false;
22582252 else bTextured = true;
22592253
@@ -2330,7 +2324,7 @@
23302324 if (!IsOK()) return;
23312325
23322326 D3DXMATRIX GroupMatrix, mWorldMesh; UINT numPasses = 0;
2333-
2327+
23342328 if (bGlobalTF) D3DXMatrixMultiply(&mWorldMesh, &mTransform, pW);
23352329 else mWorldMesh = *pW;
23362330
@@ -2351,7 +2345,7 @@
23512345
23522346 bool bInit = true;
23532347 bool bCurrentState = false;
2354-
2348+
23552349 for (DWORD g = 0; g < nGrp; g++) {
23562350
23572351
@@ -2375,7 +2369,7 @@
23752369
23762370
23772371 if (bShadowMap) {
2378-
2372+
23792373 bool bDisable = (Grp[g].UsrFlag & 0x1) != 0;
23802374
23812375 if (bDisable != bCurrentState) {
@@ -2615,9 +2609,9 @@
26152609 void D3D9Mesh::SetRotation(D3DXMATRIX &rot)
26162610 {
26172611 bGlobalTF = true;
2618-
2612+
26192613 memcpy(&mTransform, &rot, 48);
2620-
2614+
26212615 D3DXMatrixInverse(&mTransformInv, NULL, &mTransform);
26222616
26232617 for (DWORD i = 0; i<nGrp; i++) {
@@ -2628,6 +2622,23 @@
26282622
26292623 // ===========================================================================================
26302624 //
2625+void D3D9Mesh::SetScaling(float scale)
2626+{
2627+ bGlobalTF = true;
2628+
2629+ D3DXMatrixScaling(&mTransform, scale, scale, scale);
2630+
2631+ D3DXMatrixInverse(&mTransformInv, NULL, &mTransform);
2632+
2633+ for (DWORD i = 0; i < nGrp; i++)
2634+ {
2635+ if (Grp[i].bTransform) D3DXMatrixMultiply(&pGrpTF[i], &mTransform, &Grp[i].Transform);
2636+ else pGrpTF[i] = mTransform;
2637+ }
2638+}
2639+
2640+// ===========================================================================================
2641+//
26312642 void D3D9Mesh::UpdateBoundingBox()
26322643 {
26332644 if (!IsOK()) return;
@@ -2738,7 +2749,7 @@
27382749
27392750 float dst = D3DXVec3Dot(&bs, vDir);
27402751 float len2 = D3DXVec3Dot(&bs, &bs);
2741-
2752+
27422753 if (dst < -rad) continue;
27432754 if (sqrt(len2 - dst*dst) > rad) continue;
27442755
@@ -2749,7 +2760,7 @@
27492760
27502761 WORD *pIdc = pBuf->pIBSys + Grp[g].IdexOff;
27512762 D3DXVECTOR4 *pVrt = pBuf->pGBSys + Grp[g].VertOff;
2752-
2763+
27532764 D3DXMATRIX mWI; float det;
27542765 D3DXMatrixInverse(&mWI, &det, &mW);
27552766
@@ -2763,7 +2774,7 @@
27632774 WORD a = pIdc[i*3+0];
27642775 WORD b = pIdc[i*3+1];
27652776 WORD c = pIdc[i*3+2];
2766-
2777+
27672778 _a = D3DXVECTOR3f4(pVrt[a]);
27682779 _b = D3DXVECTOR3f4(pVrt[b]);
27692780 _c = D3DXVECTOR3f4(pVrt[c]);
@@ -2771,7 +2782,7 @@
27712782 float u, v, dst;
27722783
27732784 D3DXVec3Cross(&cp, &(_c - _b), &(_a - _b));
2774-
2785+
27752786 if (D3DXVec3Dot(&cp, &dir)<0) {
27762787 if (D3DXIntersectTri(&_c, &_b, &_a, &pos, &dir, &u, &v, &dst)) {
27772788 if (dst > 0.1f) {
@@ -2789,7 +2800,7 @@
27892800 }
27902801 }
27912802
2792-
2803+
27932804 if (result.idx >= 0 && result.group >= 0) {
27942805
27952806 int i = result.idx;
@@ -2825,7 +2836,7 @@
28252836 D3DXVec3Normalize(&result.normal, &cp);
28262837
28272838 D3DXVECTOR3 p = (_b * u) + (_a * v) + (_c * (1.0f - u - v));
2828- D3DXVec3TransformCoord(&result.pos, &p, &mW);
2839+ D3DXVec3TransformCoord(&result.pos, &p, &mW);
28292840 }
28302841
28312842 return result;
diff -r e20b4b8a0ac2 -r 51b5ec4a1033 Orbitersdk/D3D9Client/Mesh.h
--- a/Orbitersdk/D3D9Client/Mesh.h Tue Nov 05 00:28:42 2019 +0000
+++ b/Orbitersdk/D3D9Client/Mesh.h Tue Nov 05 02:08:42 2019 +0000
@@ -20,7 +20,7 @@
2020 #include "D3D9Client.h"
2121 #include "D3D9Effect.h"
2222 #include "AABBUtil.h"
23-#include <d3d9.h>
23+#include <d3d9.h>
2424 #include <d3dx9.h>
2525 #include <vector>
2626
@@ -104,21 +104,20 @@
104104 * textures.
105105 */
106106
107-class D3D9Mesh : private D3D9Effect
107+class D3D9Mesh : private D3D9Effect
108108 {
109109
110110 public:
111111
112- bool bCanRenderFast; // Mesh doesn't contain any advanced features in any group
113- bool bIsReflective; // Mesh has a reflective material in one or more groups
114- bool bMtrlModidied;
115- bool bIsTemplate;
112+ bool bCanRenderFast; // Mesh doesn't contain any advanced features in any group
113+ bool bIsReflective; // Mesh has a reflective material in one or more groups
114+ bool bMtrlModidied;
115+ bool bIsTemplate;
116116
117- D9BBox BBox;
118- MeshBuffer * pBuf;
117+ D9BBox BBox;
118+ MeshBuffer *pBuf;
119119
120-struct GROUPREC { // mesh group definition
121-
120+ struct GROUPREC { // mesh group definition
122121 DWORD VertOff; // Main mesh Vertex Offset
123122 DWORD IdexOff; // Main mesh Index Offset
124123 //------------------------------------------------
@@ -137,7 +136,7 @@
137136 bool bUpdate; // Bounding box update required
138137 bool bDualSided;
139138 bool bDeleted; // This entry is deleted by DelGroup()
140- bool bRendered;
139+ bool bRendered;
141140 D3DXMATRIX Transform; // Group specific transformation matrix
142141 D9BBox BBox;
143142 DWORD TexIdxEx[MAXTEX];
@@ -163,7 +162,7 @@
163162 const char * GetName() const { return name; }
164163
165164 void SetClass(DWORD cl) { vClass = cl; }
166-
165+
167166
168167 /**
169168 * \brief Check if a mesh is casting shadows
@@ -184,7 +183,7 @@
184183 * \brief Returns number of material specifications.
185184 * \return Number of materials.
186185 */
187- SURFHANDLE GetTexture(DWORD idx) const { return Tex[idx]; }
186+ SURFHANDLE GetTexture(DWORD idx) const { return Tex[idx]; }
188187 bool HasTexture(SURFHANDLE hSurf);
189188 bool IsReflective() const { return bIsReflective; }
190189
@@ -222,6 +221,7 @@
222221
223222 void SetPosition(VECTOR3 &pos);
224223 void SetRotation(D3DXMATRIX &rot);
224+ void SetScaling(float scale);
225225
226226 /**
227227 * \brief Replace a mesh texture.
@@ -243,7 +243,7 @@
243243 void RenderRings(const LPD3DXMATRIX pW, LPDIRECT3DTEXTURE9 pTex);
244244 void RenderRings2(const LPD3DXMATRIX pW, LPDIRECT3DTEXTURE9 pTex, float irad, float orad);
245245 void RenderAxisVector(LPD3DXMATRIX pW, const LPD3DXCOLOR pColor, float len);
246-
246+
247247 void CheckMeshStatus();
248248 void ResetTransformations();
249249 void TransformGroup(DWORD n, const D3DXMATRIX *m);
@@ -252,9 +252,9 @@
252252 int EditGroup (DWORD grp, GROUPEDITSPEC *ges);
253253
254254 void SetSunLight(const D3D9Sun *pLight);
255-
255+
256256 D3D9Pick Pick(const LPD3DXMATRIX pW, const LPD3DXMATRIX pT, const D3DXVECTOR3 *vDir);
257-
257+
258258 void UpdateBoundingBox();
259259 void BoundingBox(const NMVERTEX *vtx, DWORD n, D9BBox *box);
260260
@@ -275,7 +275,7 @@
275275
276276 private:
277277
278- //void Copy(const D3D9Mesh &mesh);
278+
279279 void UpdateTangentSpace(NMVERTEX *pVrt, WORD *pIdx, DWORD nVtx, DWORD nFace, bool bTextured);
280280 void ProcessInherit();
281281 bool CopyVertices(GROUPREC *grp, const MESHGROUPEX *mg, D3DXVECTOR3 *reorig = NULL, float *scale = NULL);
@@ -310,7 +310,7 @@
310310
311311 char name[128];
312312
313-
313+
314314 };
315315
316-#endif // !__MESH_H
\ No newline at end of file
316+#endif // !__MESH_H
diff -r e20b4b8a0ac2 -r 51b5ec4a1033 Orbitersdk/D3D9Client/OapiExtension.cpp
--- a/Orbitersdk/D3D9Client/OapiExtension.cpp Tue Nov 05 00:28:42 2019 +0000
+++ b/Orbitersdk/D3D9Client/OapiExtension.cpp Tue Nov 05 02:08:42 2019 +0000
@@ -193,9 +193,9 @@
193193
194194 if (GetModuleBaseName(hProcess, hMods[i], szModName, ARRAYSIZE(szModName)))
195195 {
196- std::string name = std::string(szModName); toLower(name);
196+ std::string name = std::string(szModName); toUpper(name);
197197 // Module of interest?
198- if (name == "d3d9.dll" || 0 == name.compare(0, 6, "d3dx9_"))
198+ if (name == "D3D9.DLL" || 0 == name.compare(0, 6, "D3DX9_"))
199199 {
200200 // Get the full path to the module's file.
201201 if (GetModuleFileNameEx(hProcess, hMods[i], szModName, ARRAYSIZE(szModName)))
diff -r e20b4b8a0ac2 -r 51b5ec4a1033 Orbitersdk/D3D9Client/Scene.cpp
--- a/Orbitersdk/D3D9Client/Scene.cpp Tue Nov 05 00:28:42 2019 +0000
+++ b/Orbitersdk/D3D9Client/Scene.cpp Tue Nov 05 02:08:42 2019 +0000
@@ -1142,7 +1142,6 @@
11421142 }
11431143
11441144
1145-
11461145 // ---------------------------------------------------------------------------------------------
11471146 // Create a render list for shadow mapping
11481147 // ---------------------------------------------------------------------------------------------
@@ -1275,7 +1274,7 @@
12751274 VECTOR3 cp = GetCameraGPos();
12761275 cpos = tmul(prot, cp - ppos); // camera in local planet coords
12771276
1278- for (n = 0; n<nlist; n++) {
1277+ for (n = 0; n < nlist; n++) {
12791278
12801279 if (list[n].active && apprad*list[n].distfac > LABEL_DISTLIMIT) {
12811280
@@ -1287,7 +1286,7 @@
12871286
12881287 const GraphicsClient::LABELSPEC *ls = list[n].list;
12891288 VECTOR3 sp;
1290- for (int j = 0; j<list[n].length; j++) {
1289+ for (int j = 0; j < list[n].length; j++) {
12911290 if (dotp(ls[j].pos, cpos - ls[j].pos) >= 0.0) { // surface point visible?
12921291 sp = mul(prot, ls[j].pos) + ppos;
12931292 RenderObjectMarker(pSketch, sp, ls[j].label[0], ls[j].label[1], list[n].shape, size);
@@ -1307,7 +1306,7 @@
13071306 pSketch->SetTextColor(labelCol[0]);
13081307 pSketch->SetPen(lblPen[0]);
13091308
1310- for (DWORD i = 0; i<n; i++) {
1309+ for (DWORD i = 0; i < n; i++) {
13111310
13121311 OBJHANDLE hBase = oapiGetBaseByIndex(hObj, i);
13131312
@@ -1330,7 +1329,8 @@
13301329 }
13311330 }
13321331 }
1333- pSketch->EndDrawing();
1332+
1333+ pSketch->EndDrawing(); // SKETCHPAD_LABELS
13341334 }
13351335 }
13361336
@@ -1521,6 +1521,8 @@
15211521
15221522
15231523
1524+
1525+
15241526 // -------------------------------------------------------------------------------------------------------
15251527 // render the internal parts of the focus object in a separate render pass
15261528 // -------------------------------------------------------------------------------------------------------
@@ -1560,10 +1562,12 @@
15601562
15611563
15621564
1565+
15631566 // -------------------------------------------------------------------------------------------------------
15641567 // Copy Offscreen render target to backbuffer
15651568 // -------------------------------------------------------------------------------------------------------
15661569
1570+
15671571 if (pOffscreenTarget && pLightBlur) {
15681572
15691573 int iGensPerFrame = pLightBlur->FindDefine("PassCount");
@@ -1687,8 +1691,6 @@
16871691
16881692 gc->PushRenderTarget(gc->GetBackBuffer(), gc->GetDepthStencil(), RENDERPASS_MAINOVERLAY); // Overlay
16891693
1690-
1691-
16921694 pSketch = GetPooledSketchpad(SKETCHPAD_2D_OVERLAY);
16931695
16941696 if (pSketch) {
@@ -2957,6 +2959,7 @@
29572959 D3DXMatrixMultiply(&mEnv, &mGlo, &mEnv);
29582960
29592961 PushCamera();
2962+
29602963 SetCameraFrustumLimits(0.1, 2e7);
29612964 SetupInternalCamera(&mEnv, &gpos, cCur->dAperture, double(h)/double(w));
29622965
@@ -2993,6 +2996,25 @@
29932996
29942997 // ===========================================================================================
29952998 //
2999+bool Scene::CameraDirection2Viewport(const VECTOR3 &dir, int &x, int &y)
3000+{
3001+ D3DXVECTOR3 homog;
3002+ D3DXVECTOR3 idir = D3DXVECTOR3( -float(dir.x), -float(dir.y), -float(dir.z) );
3003+ D3DMAT_VectorMatrixMultiply(&homog, &idir, &Camera.mProjView);
3004+ if (homog.x >= -1.0f && homog.y <= 1.0f && homog.z >= 0.0) {
3005+ if (_hypot(homog.x, homog.y) < 1e-6) {
3006+ x = viewW / 2, y = viewH / 2;
3007+ } else {
3008+ x = (int)(viewW*0.5f*(1.0f + homog.x));
3009+ y = (int)(viewH*0.5f*(1.0f - homog.y));
3010+ }
3011+ return true;
3012+ }
3013+ return false;
3014+}
3015+
3016+// ===========================================================================================
3017+//
29963018 void Scene::GlobalExit()
29973019 {
29983020 SAFE_RELEASE(FX);
diff -r e20b4b8a0ac2 -r 51b5ec4a1033 Orbitersdk/D3D9Client/Scene.h
--- a/Orbitersdk/D3D9Client/Scene.h Tue Nov 05 00:28:42 2019 +0000
+++ b/Orbitersdk/D3D9Client/Scene.h Tue Nov 05 02:08:42 2019 +0000
@@ -164,7 +164,7 @@
164164 const D3D9Light *GetLight(int index) const;
165165 const D3D9Light *GetLights() const { return Lights; }
166166 DWORD GetLightCount() const { return nLights; }
167-
167+
168168
169169 DWORD GetRenderPass() const;
170170 void BeginPass(DWORD dwPass);
@@ -218,7 +218,7 @@
218218
219219 bool RenderBlurredMap(LPDIRECT3DDEVICE9 pDev, LPDIRECT3DCUBETEXTURE9 pSrc);
220220
221- LPDIRECT3DSURFACE9 GetEnvDepthStencil() { return pEnvDS; }
221+ LPDIRECT3DSURFACE9 GetEnvDepthStencil() const { return pEnvDS; }
222222
223223 /**
224224 * \brief Render any shadows cast by vessels on planet surfaces
@@ -266,8 +266,6 @@
266266
267267 void ClearOmitFlags();
268268 bool IsRendering() const { return bRendering; }
269-
270-
271269
272270
273271 // Custom Camera Interface ======================================================================================================
@@ -306,6 +304,7 @@
306304
307305 // Check if a sphere located in pCnt (relative to cam) with a specified radius is visible in a camera
308306 bool IsVisibleInCamera(D3DXVECTOR3 *pCnt, float radius);
307+ bool CameraDirection2Viewport(const VECTOR3 &dir, int &x, int &y);
309308 double GetTanAp() const { return tan(Camera.aperture); }
310309 float GetCameraAspect() const { return (float)Camera.aspect; }
311310 float GetCameraFarPlane() const { return Camera.farplane; }
@@ -424,7 +423,7 @@
424423 std::list<vVessel *> SmapRenderList;
425424 std::stack<CAMERA> CameraStack;
426425 std::stack<DWORD> PassStack;
427-
426+
428427
429428 CAMERA Camera;
430429 D3D9Light* Lights;
@@ -480,4 +479,4 @@
480479
481480 };
482481
483-#endif // !__SCENE_H
\ No newline at end of file
482+#endif // !__SCENE_H
diff -r e20b4b8a0ac2 -r 51b5ec4a1033 Orbitersdk/D3D9Client/VObject.cpp
--- a/Orbitersdk/D3D9Client/VObject.cpp Tue Nov 05 00:28:42 2019 +0000
+++ b/Orbitersdk/D3D9Client/VObject.cpp Tue Nov 05 02:08:42 2019 +0000
@@ -51,11 +51,11 @@
5151 , bOmit (false)
5252 , scn( (Scene *)scene) // should be const!
5353 , sunapprad()
54- , sundst()
54+ , sundst ()
55+ , size (oapiGetSize(_hObj))
5556 {
5657 _TRACE;
5758 D3DXMatrixIdentity(&mWorld);
58- size = oapiGetSize(hObj);
5959 cdist = 0.0;
6060 dmWorld = identity4();
6161 albedo = _V(1,1,1);
@@ -303,14 +303,13 @@
303303 cpos = gpos - scn->GetCameraGPos();
304304 cdist = length(cpos);
305305
306- double rad = oapiGetSize(hObj);
307- double alt = max(1.0, cdist-rad);
308- double apr = rad * scn->ViewH()*0.5 / (alt * tan(scn->GetCameraAperture()));
306+ double alt = max(1.0, cdist - size);
307+ double apr = size * scn->ViewH()*0.5 / (alt * tan(scn->GetCameraAperture()));
309308
310309 double ds = 10000.0 / cdist;
311310 double s = 2.0;
312311 if (apr<0.3) s = 1.0;
313- float size = float(rad * ds * s/apr);
312+ float scale = float(size * ds * s/apr);
314313
315314 D3DXMATRIX W;
316315 D3DXVECTOR3 vCam;
@@ -318,7 +317,7 @@
318317 vPos*=float(ds);
319318
320319 D3DXVec3Normalize(&vCam, &vPos);
321- D3DMAT_CreateX_Billboard(&vCam, &vPos, size, &W);
320+ D3DMAT_CreateX_Billboard(&vCam, &vPos, scale, &W);
322321
323322 float ints = float(sqrt(1.0+dotp(unit(gpos-spos), unit(cpos)))) * 1.0f;
324323
diff -r e20b4b8a0ac2 -r 51b5ec4a1033 Orbitersdk/D3D9Client/VPlanet.cpp
--- a/Orbitersdk/D3D9Client/VPlanet.cpp Tue Nov 05 00:28:42 2019 +0000
+++ b/Orbitersdk/D3D9Client/VPlanet.cpp Tue Nov 05 02:08:42 2019 +0000
@@ -140,7 +140,7 @@
140140 } else {
141141 ringmgr = 0;
142142 }
143-
143+
144144 memcpy2 (&fog, oapiGetObjectParam (_hObj, OBJPRM_PLANET_FOGPARAM), sizeof (FogParam));
145145 prm.bFogEnabled = (fog.dens_0 > 0);
146146
@@ -148,7 +148,7 @@
148148
149149 //if (*(bool*)gc->GetConfigParam(CFGPRM_ATMFOG)==false) prm.bFogEnabled = false;
150150
151-
151+
152152 nbase = oapiGetBaseCount (_hObj);
153153 if (nbase) vbase = new vBase*[nbase];
154154 else vbase = NULL;
@@ -165,17 +165,20 @@
165165 vbase[i] = new vBase (hBase, scn, this);
166166 }
167167 }
168- }
169-
168+ }
169+
170170 mesh = NULL;
171171 if (surfmgr && surfmgr->GetMaxLevel() == 0) {
172172 char cbuf[256];
173173 oapiGetObjectName (hObj, cbuf, 256);
174174 OBJHANDLE hMesh = oapiLoadMesh (cbuf);
175175 if (hMesh) {
176- LogAlw("Loading a mesh [%s] for [%s]", cbuf, name);
177- float size = float(oapiGetSize(hObj));
178- mesh = new D3D9Mesh (hMesh, false, NULL, &size);
176+ LogAlw("Loading mesh [%s] for planetary body '%s'", cbuf, name);
177+ mesh = new D3D9Mesh (hMesh);
178+ // Scale if not ~1.0 (+- 1e-9)
179+ if (fabs(size - 1.0) > 1e-9) {
180+ mesh->SetScaling(float(size));
181+ }
179182 oapiDeleteMesh (hMesh);
180183 }
181184 }
@@ -183,8 +186,8 @@
183186 // Create a rock patch mesh --------------------------------------------------------------
184187 //
185188 pRockPatch = NULL;
186-
187-
189+
190+
188191 // Add a cursor object into the scene ------------------------
189192 //
190193 hCursor[0] = AddMarker(D3D9SM_SPHERE, 0.0, 0.0, 80.0f, &D3DXCOLOR(0, 0, 0.75, 0.5f)); // Cursor
@@ -268,7 +271,6 @@
268271 return 0.0;
269272 }
270273
271-
272274 // ==============================================================
273275
274276 DWORD vPlanet::GetBaseCount()
@@ -328,9 +330,9 @@
328330
329331 float dst = D3DXVec3Length(&pos);
330332
331- *dmin = dst - float(oapiGetSize(hObj));
333+ *dmin = dst - float(size);
332334 *zmin = *dmin;
333- *zmax = dst + float(oapiGetSize(hObj));
335+ *zmax = dst + float(size);
334336
335337 return true;
336338 }
@@ -357,7 +359,7 @@
357359 void vPlanet::PickSurface(TILEPICK *result)
358360 {
359361 if (surfmgr2) {
360-
362+
361363 surfmgr2->Pick(result);
362364
363365 if (result->pTile) {
@@ -408,7 +410,7 @@
408410 HSRFOBJ vPlanet::AddObject(D3D9Mesh *pMesh, double lng, double lat, float rot, bool bDual, float scale)
409411 {
410412 _SRFMARKER m; memset(&m, 0, sizeof(_SRFMARKER));
411-
413+
412414 m.lng = lng;
413415 m.lat = lat;
414416 m.rot = rot;
@@ -418,10 +420,10 @@
418420 m.pMesh = pMesh;
419421 m.type = 0;
420422 m.bEnabled = true;
421-
423+
422424 D3DXMatrixRotationAxis(&m.mWorld, &D3DXVEC(m.uPos), rot);
423425 D3DXMatrixScaling(&m.mWorld, scale, scale, scale);
424-
426+
425427 Markers.push_front(m);
426428 return Markers.begin();
427429 }
@@ -440,10 +442,10 @@
440442 m.vColor = D3DXC2V(*color);
441443 m.type = WORD(type);
442444 m.bEnabled = true;
443-
445+
444446 switch (type) {
445447 case D3D9SM_SPHERE:
446- {
448+ {
447449 m.bDual = true;
448450 m.pMesh = hStockMesh[type];
449451 }
@@ -496,7 +498,7 @@
496498 {
497499 _TRACE;
498500 if (!active) return false;
499-
501+
500502 vObject::Update(bMainScene);
501503
502504 // Update Sunlight direction -------------------------------------
@@ -574,7 +576,7 @@
574576 }
575577
576578 // check all base visuals
577- if (nbase) {
579+ if (nbase) {
578580 VECTOR3 pos, cpos = scn->GetCameraGPos();
579581 double scale = (double)scn->ViewH()/scn->GetTanAp();
580582 for (DWORD i = 0; i < nbase; i++) {
@@ -600,11 +602,11 @@
600602 }
601603
602604 // Toggle surface base on/off based on visual size -----------------
603- //
605+ //
604606 if (vbase[i]) {
605607 if (apprad < 1.0) vbase[i]->Activate(false);
606608 else if (apprad > 2.0) vbase[i]->Activate(true);
607- vbase[i]->Update(bMainScene);
609+ vbase[i]->Update(bMainScene);
608610 }
609611 }
610612 }
@@ -640,8 +642,8 @@
640642 if (hazemgr) { delete hazemgr; hazemgr = NULL; }
641643 if (hazemgr2) { delete hazemgr2; hazemgr2 = NULL; }
642644 } else {
643- if (tilever>1 && bScatter) {
644- if (!hazemgr2) hazemgr2 = new HazeManager2 (scn->GetClient(), this);
645+ if (tilever>1 && bScatter) {
646+ if (!hazemgr2) hazemgr2 = new HazeManager2 (scn->GetClient(), this);
645647 }
646648 else if (!hazemgr) hazemgr = new HazeManager (scn->GetClient(), this);
647649 }
@@ -692,7 +694,7 @@
692694 HR(D3D9Effect::FX->SetBool(D3D9Effect::eShadowToggle, true));
693695 }
694696 }
695-
697+
696698
697699 PlanetRenderer::InitializeScattering(this);
698700 PlanetRenderer::SetViewProjectionMatrix(scn->GetProjectionViewMatrix());
@@ -730,9 +732,9 @@
730732
731733 if (ringmgr) {
732734 ringmgr->Render(dev, mWorld, false);
733- dev->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
735+ dev->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
734736 }
735-
737+
736738 if (hazemgr2) {
737739 double apr = 180.0 * scn->GetCameraAperture() / (scn->GetCameraAspect() * PI);
738740 hazemgr2->Render(mWorld, float(apr));
@@ -742,8 +744,8 @@
742744 RenderCloudLayer (dev, D3DCULL_NONE); // render clouds from below
743745
744746 if (hazemgr) hazemgr->Render(dev, mWorld); // horizon ring
745-
746-
747+
748+
747749 if (prm.bAtm) {
748750 if (ModLighting (amb))
749751 prm.AmbColor = D3DXCOLOR(amb);
@@ -794,7 +796,7 @@
794796 mesh->SetSunLight(scn->GetSun());
795797 mesh->Render(&mWorld, RENDER_ASTEROID);
796798 } else {
797- RenderSphere (dev);
799+ RenderSphere (dev);
798800 }
799801
800802 if (nbase) RenderBaseStructures (dev);
@@ -805,7 +807,7 @@
805807 if (hazemgr) hazemgr->Render (dev, mWorld, true); // haze across planet disc
806808 if (ringmgr) {
807809 ringmgr->Render (dev, mWorld, true);
808- dev->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
810+ dev->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
809811 }
810812
811813 }
@@ -820,14 +822,14 @@
820822
821823 void vPlanet::RenderBeacons(LPDIRECT3DDEVICE9 dev)
822824 {
823- // Beacons rendered elsewhere before the cloud layer
825+ // Beacons rendered elsewhere before the cloud layer
824826 }
825827
826828 // ==============================================================
827829 /*
828830 void vPlanet::RenderSurfaceMicroDetails(LPDIRECT3DDEVICE9 dev)
829831 {
830-
832+
831833 }
832834 */
833835 // ==============================================================
@@ -857,9 +859,9 @@
857859 }
858860
859861 if (bLog) D3D9SetTime(D3D9Stats.Timer.Surface, tot_surf);
860- }
862+ }
861863 else {
862- dev->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
864+ dev->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
863865 if (prm.bFog) D3D9Effect::FX->SetFloat(D3D9Effect::eFogDensity, fogfactor/dist_scale);
864866 surfmgr->SetAmbientColor(prm.AmbColor);
865867 surfmgr->Render (dev, mWorld, dist_scale, patchres, 0.0, prm.bFog); // surface
@@ -888,7 +890,7 @@
888890 double tot_cloud = D3D9GetTime();
889891
890892 if (cullmode != D3DCULL_CCW) dev->SetRenderState (D3DRS_CULLMODE, cullmode);
891- if (cloudmgr2) {
893+ if (cloudmgr2) {
892894 cloudmgr2->Render(dmWorld, false, prm);
893895 }
894896 else
@@ -905,12 +907,12 @@
905907 if (cloudmgr2) {
906908 //if (prm.bCloudFlatShadows)
907909 // cloudmgr2->RenderFlatCloudShadows (dmWorld, prm);
908- }
910+ }
909911 else if (clouddata) { // legacy method
910912 float fogfactor;
911913 D3D9Effect::FX->GetFloat(D3D9Effect::eFogDensity, &fogfactor);
912914 if (prm.bFog) D3D9Effect::FX->SetFloat(D3D9Effect::eFogDensity, fogfactor/dist_scale);
913- clouddata->cloudmgr->RenderShadow(dev, clouddata->mWorldC0, dist_scale, min(patchres,8), clouddata->viewap, clouddata->shadowalpha);
915+ clouddata->cloudmgr->RenderShadow(dev, clouddata->mWorldC0, dist_scale, min(patchres,8), clouddata->viewap, clouddata->shadowalpha);
914916 if (prm.bFog) D3D9Effect::FX->SetFloat(D3D9Effect::eFogDensity, fogfactor);
915917 }
916918 }
@@ -920,7 +922,7 @@
920922 void vPlanet::RenderBaseSurfaces(LPDIRECT3DDEVICE9 dev)
921923 {
922924 for (DWORD i=0;i<nbase;i++) if (vbase[i]) {
923- vbase[i]->RenderSurface(dev);
925+ vbase[i]->RenderSurface(dev);
924926 vbase[i]->RenderRunwayLights(dev);
925927 }
926928 }
@@ -983,14 +985,14 @@
983985
984986 D3DXVECTOR3 lambda4 = D3DXVECTOR3(pow(float(SPrm.red),rp), pow(float(SPrm.green),rp), pow(float(SPrm.blue),rp));
985987 D3DXVECTOR3 lambda2 = D3DXVECTOR3(pow(float(SPrm.red),mp), pow(float(SPrm.green),mp), pow(float(SPrm.blue),mp));
986-
988+
987989 D3DXVec3Normalize(&lambda4, &lambda4);
988990 D3DXVec3Normalize(&lambda2, &lambda2);
989991
990992 D3DXVECTOR3 vOutTotSun = lambda4*float(SPrm.rout) + lambda2*float(SPrm.mie);
991993 D3DXVECTOR3 vRayInSct = lambda4*float(SPrm.rin * SPrm.rout);
992994
993- double fDPS = max(0.34, dotp(unit(vPos), sundir));
995+ double fDPS = max(0.34, dotp(unit(vPos), sundir));
994996 double fDns = exp2(-fAlt * prm.InvSclHeight);
995997
996998 return exp2(-vOutTotSun * float(fDns * AngleCoEff(fDPS)));
@@ -1038,12 +1040,12 @@
10381040 double R = R0 + alt;
10391041
10401042 double rdt = -R * cos(dir);
1041- double Ray = rdt + sqrt(R1*R1 - (R*R - rdt*rdt));
1043+ double Ray = rdt + sqrt(R1*R1 - (R*R - rdt*rdt));
10421044
1043- double p0 = Ray * 0.0;
1044- double p1 = Ray * 0.2765;
1045- double p2 = Ray * 0.7235;
1046- double p3 = Ray * 1.0;
1045+ double p0 = Ray * 0.0;
1046+ double p1 = Ray * 0.2765;
1047+ double p2 = Ray * 0.7235;
1048+ double p3 = Ray * 1.0;
10471049
10481050 double a0 = sqrt(R*R + p0*p0 + 2.0*R*p0*cos(dir)) - R0;
10491051 double a1 = sqrt(R*R + p1*p1 + 2.0*R*p1*cos(dir)) - R0;
@@ -1078,7 +1080,7 @@
10781080 for (int i=0;i<samples;i++) {
10791081 double exact = ExactOpticalDepth(0.0, angle, size, outer, prm.SclHeight) / prm.SclHeight;
10801082 double gauss = GaussLobatto(0.0, angle, size, outer, prm.SclHeight) / prm.SclHeight;
1081- double accur = OpticalDepth(0.0, cos(angle)) / double(prm.SclHeight);
1083+ double accur = OpticalDepth(0.0, cos(angle)) / double(prm.SclHeight);
10821084 angle += delta;
10831085 fprintf(fp,"%d %6.6g %6.6g %6.6g\n", i, exact, accur, gauss);
10841086 }
@@ -1096,9 +1098,9 @@
10961098 if (mode==0 && alt>0.5) mode = 2;
10971099 if (mode==0 && alt<0.5) mode = 1;
10981100
1099- if (mode==1) return &SPrm; // Surface configuration
1101+ if (mode==1) return &SPrm; // Surface configuration
11001102 if (mode==2) return &OPrm; // Orbital configuration
1101-
1103+
11021104 // ----------------------------------------------------
11031105 CPrm.aux1 = lerp(SPrm.aux1, OPrm.aux1, alt);
11041106 CPrm.aux2 = lerp(SPrm.aux2, OPrm.aux2, alt);
@@ -1123,11 +1125,11 @@
11231125 CPrm.hazei = lerp(SPrm.hazei, OPrm.hazei, alt);
11241126 // ----------------------------------------------------
11251127 CPrm.height = SPrm.height;
1126-
1128+
11271129 return &CPrm;
11281130 }
1129-
1130-
1131+
1132+
11311133
11321134 // ==============================================================
11331135
@@ -1179,14 +1181,14 @@
11791181 oapiReadItem_float(hFile, "AGamma", prm->agamma);
11801182 oapiReadItem_float(hFile, "HazeClr", prm->hazec);
11811183 oapiReadItem_float(hFile, "HazeIts", prm->hazei);
1182-
1184+
11831185 oapiCloseFile(hFile, FILE_IN_ZEROONFAIL);
11841186
11851187 if (!oapiPlanetHasAtmosphere(hObj)) return false;
11861188
11871189 UpdateAtmoConfig();
11881190 return true;
1189-
1191+
11901192 }
11911193
11921194 // ==============================================================
@@ -1225,7 +1227,7 @@
12251227 // -----------------------------------------------------------------
12261228 oapiWriteItem_float(hFile, "MiePower", prm->mie);
12271229 oapiWriteItem_float(hFile, "MiePhase", prm->mphase);
1228- // -----------------------------------------------------------------
1230+ // -----------------------------------------------------------------
12291231 oapiWriteItem_float(hFile, "Aux1", prm->aux1);
12301232 oapiWriteItem_float(hFile, "Aux2", prm->aux2);
12311233 oapiWriteItem_float(hFile, "Aux3", prm->aux3);
@@ -1233,7 +1235,7 @@
12331235 oapiWriteItem_float(hFile, "AGamma", prm->agamma);
12341236 oapiWriteItem_float(hFile, "HazeClr", prm->hazec);
12351237 oapiWriteItem_float(hFile, "HazeIts", prm->hazei);
1236-
1238+
12371239 oapiCloseFile(hFile, FILE_OUT);
12381240
12391241 DumpDebugFile();
@@ -1300,7 +1302,7 @@
13001302 bool vPlanet::ParseMicroTextures()
13011303 {
13021304 if (Config->MicroMode==0) return false; // Micro textures are disabled
1303- if (surfmgr2==NULL) return false; // Only supported with tile format 2
1305+ if (surfmgr2==NULL) return false; // Only supported with tile format 2
13041306
13051307 // Parse file (only once!)
13061308 if (!bMicroTexFileRead) {
diff -r e20b4b8a0ac2 -r 51b5ec4a1033 Orbitersdk/D3D9Client/VStar.cpp
--- a/Orbitersdk/D3D9Client/VStar.cpp Tue Nov 05 00:28:42 2019 +0000
+++ b/Orbitersdk/D3D9Client/VStar.cpp Tue Nov 05 02:08:42 2019 +0000
@@ -20,7 +20,6 @@
2020
2121 vStar::vStar(OBJHANDLE _hObj, const Scene *scene): vObject (_hObj, scene)
2222 {
23-// size = oapiGetSize(_hObj);
2423 maxdist = 0.5*scene->GetCameraFarPlane();
2524 }
2625
@@ -71,7 +70,7 @@
7170 mWorld._21 = -(mWorld._12*mWorld._33 - mWorld._32*mWorld._13); //0;
7271 mWorld._22 = -(mWorld._13*mWorld._31 - mWorld._33*mWorld._11); //1;
7372 mWorld._23 = -(mWorld._11*mWorld._32 - mWorld._31*mWorld._12); // 0;
74-
73+
7574 // artificially reduce size reduction with distance
7675 // to make star appear larger
7776 size_hack = float(1.0+pow(cdist,0.6)*1e-6);
diff -r e20b4b8a0ac2 -r 51b5ec4a1033 Orbitersdk/D3D9Client/VVessel.cpp
--- a/Orbitersdk/D3D9Client/VVessel.cpp Tue Nov 05 00:28:42 2019 +0000
+++ b/Orbitersdk/D3D9Client/VVessel.cpp Tue Nov 05 02:08:42 2019 +0000
@@ -330,6 +330,7 @@
330330 MESHHANDLE hMesh = vessel->GetMeshTemplate(idx);
331331 const D3D9Mesh *mesh = mmgr->GetMesh(hMesh);
332332
333+
333334 if (hMesh && mesh) {
334335 meshlist[idx].mesh = new D3D9Mesh(hMesh, *mesh); // Create new Instance from an existing mesh template
335336 meshlist[idx].mesh->SetClass(vClass);
@@ -393,6 +394,20 @@
393394 if (anim[i].comp[k]->trans->mesh == idx) animstate[i] = anim[i].defstate; // reset to default animation state
394395 }
395396 }
397+
398+ pMatMgr->ApplyConfiguration(meshlist[idx].mesh);
399+
400+ meshlist[idx].vismode = vessel->GetMeshVisibilityMode(idx);
401+ vessel->GetMeshOffset(idx, ofs);
402+
403+ if (length(ofs)) {
404+ if (!meshlist[idx].trans) meshlist[idx].trans = new D3DXMATRIX;
405+ D3DMAT_Identity(meshlist[idx].trans);
406+ D3DMAT_SetTranslation(meshlist[idx].trans, &ofs);
407+ }
408+ else {
409+ SAFE_DELETE(meshlist[idx].trans);
410+ }
396411 }
397412 }
398413
@@ -780,7 +795,7 @@
780795
781796 DWORD bfvmode = *(DWORD*)gc->GetConfigParam(CFGPRM_SHOWBODYFORCEVECTORSFLAG);
782797 float sclset = *(float*)gc->GetConfigParam(CFGPRM_BODYFORCEVECTORSSCALE);
783- float scale = float(oapiGetSize(hObj)) / 50.0f;
798+ float scale = float(size) / 50.0f;
784799
785800 // -------------------------------------
786801 // Render Body Force Vectors
@@ -801,10 +816,10 @@
801816 if (bfvmode & BFV_TOTAL) { vessel->GetForceVector(vector); if (length(vector)>len) len = length(vector); }
802817 if (bfvmode & BFV_TORQUE) { vessel->GetTorqueVector(vector); if (length(vector)>len) len = length(vector); }
803818
804- lscale = float(oapiGetSize(hObj)*sclset/len);
819+ lscale = float(size * sclset / len);
805820 }
806821 else {
807- lscale = float(oapiGetSize(hObj))*sclset/50.0f;
822+ lscale = float(size * sclset / 50.0);
808823 }
809824
810825 alpha = *(float*)gc->GetConfigParam(CFGPRM_BODYFORCEVECTORSOPACITY);
@@ -880,7 +895,7 @@
880895 {
881896 float sclset = *(float*)gc->GetConfigParam(CFGPRM_COORDINATEAXESSCALE);
882897 scale *= 0.99f; // 1% "slimmer" to avoid z-fighting with force vector(s)
883- float ascale = float(oapiGetSize(hObj))*sclset*0.5f;
898+ float ascale = float(size)*sclset*0.5f;
884899
885900 RenderAxisVector(pSkp, &D3DXCOLOR(1,0,0,alpha), _V(1,0,0), ascale, scale);
886901 RenderAxisLabel(pSkp, &D3DXCOLOR(1,0,0,alpha), _V(1,0,0), ascale, scale, "X");
Show on old repository browser