Skip to content

Commit

Permalink
#283: Inline client: cleaned up force & axis vector rendering code.
Browse files Browse the repository at this point in the history
  • Loading branch information
mschweiger committed Oct 29, 2022
1 parent b0c6fef commit bb6734c
Show file tree
Hide file tree
Showing 16 changed files with 216 additions and 242 deletions.
6 changes: 2 additions & 4 deletions OVP/D3D7Client/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,6 @@ void Scene::RenderObjectMarker (oapi::Sketchpad* pSkp, const VECTOR3 &gpos, cons

void Scene::RenderVectors()
{
VOBJREC* pv;

dev->SetRenderState(D3DRENDERSTATE_ZENABLE, FALSE);
dev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR);
dev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
Expand All @@ -661,11 +659,11 @@ void Scene::RenderVectors()
dev->GetMaterial(&pmtrl);
dev->SetMaterial(&mtrl);

for (pv = vobjFirst; pv; pv = pv->next) {
for (VOBJREC* pv = vobjFirst; pv; pv = pv->next) {
pv->vobj->RenderVectors(dev);
}
dev->SetRenderState(D3DRENDERSTATE_ZENABLE, TRUE);

dev->SetRenderState(D3DRENDERSTATE_ZENABLE, TRUE);
dev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
dev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
dev->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_CURRENT);
Expand Down
20 changes: 9 additions & 11 deletions OVP/D3D7Client/VObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,25 +229,23 @@ void vObject::RenderVectors(LPDIRECT3DDEVICE7 dev)
// Render and texture stage states are assumed to be set correctly on call

if (veclist.size()) {
float alpha, palpha = -1.0f;
VECTOR3 col, pcol = { -1,-1,-1 };
for (auto it = veclist.begin(); it != veclist.end(); it++) {
alpha = (*it).alpha;
col = (*it).col;
if (alpha != palpha || col.x != pcol.x || col.y != pcol.y || col.z != pcol.z) {
dev->SetRenderState(D3DRENDERSTATE_TEXTUREFACTOR, D3DRGBA(col.x, col.y, col.z, alpha));
palpha = alpha; pcol = col;
float palpha = -1.0f;
VECTOR3 pcol = { -1,-1,-1 };
for (auto&& vec : veclist) {
if (vec.alpha != palpha || vec.col.x != pcol.x || vec.col.y != pcol.y || vec.col.z != pcol.z) {
dev->SetRenderState(D3DRENDERSTATE_TEXTUREFACTOR, D3DRGBA(vec.col.x, vec.col.y, vec.col.z, vec.alpha));
palpha = vec.alpha; pcol = vec.col;
}
if (DrawVector(dev, (*it).v, (*it).orig, (*it).rad, (*it).col, alpha) && (*it).label.size()) {
double scale3 = ((*it).lsize >= 0 ? (*it).lsize : size);
if (DrawVector(dev, vec.v, vec.orig, vec.rad) && vec.label.size()) {
double scale3 = (vec.lsize >= 0 ? vec.lsize : size);
//scene->Render3DLabel(mul(body->GRot(), ve->v + ve->v.unit() * (scale3 * 0.1)) + body->GPos(),
// ve->label, scale3, ve->lcol);
}
}
}
}

bool vObject::DrawVector(LPDIRECT3DDEVICE7 dev, const VECTOR3& end, const VECTOR3& orig, double rad, const VECTOR3& col, float opac)
bool vObject::DrawVector(LPDIRECT3DDEVICE7 dev, const VECTOR3& end, const VECTOR3& orig, double rad)
{
static const float EPS = 1e-2f;
static const int nseg = 8;
Expand Down
3 changes: 1 addition & 2 deletions OVP/D3D7Client/VObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@ class vObject: public oapi::VisObject {

void AddVector(const VECTOR3& v, const VECTOR3& orig, double rad, const std::string& label, const VECTOR3& col, float alpha = 1.0f, DWORD lcol = 0, float lsize = -1.0);

bool DrawVector(LPDIRECT3DDEVICE7 dev, const VECTOR3& end, const VECTOR3& orig, double rad,
const VECTOR3& col, float opac);
bool DrawVector(LPDIRECT3DDEVICE7 dev, const VECTOR3& end, const VECTOR3& orig, double rad);

static const oapi::D3D7Client *gc; // graphics client instance pointer
static LPDIRECTDRAWSURFACE7 blobtex[3]; // beacon textures
Expand Down
18 changes: 9 additions & 9 deletions OVP/D3D7Client/VPlanet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,15 @@ void vPlanet::RenderVectors(LPDIRECT3DDEVICE7 dev)

// ==============================================================

void vPlanet::RenderBaseVectors(LPDIRECT3DDEVICE7 dev)
{
for (DWORD i = 0; i < nbase; i++)
if (vbase[i])
vbase[i]->RenderVectors(dev);
}

// ==============================================================

void vPlanet::RenderCloudShadows (LPDIRECT3DDEVICE7 dev, const RenderPrm &prm)
{
if (cloudmgr2) {
Expand Down Expand Up @@ -690,15 +699,6 @@ void vPlanet::RenderBaseShadows (LPDIRECT3DDEVICE7 dev, float depth)

// ==============================================================

void vPlanet::RenderBaseVectors(LPDIRECT3DDEVICE7 dev)
{
for (DWORD i = 0; i < nbase; i++)
if (vbase[i])
vbase[i]->RenderVectors(dev);
}

// ==============================================================

void vPlanet::RenderBaseStructures (LPDIRECT3DDEVICE7 dev)
{
bool zmod = false, zcheck = false;
Expand Down
2 changes: 1 addition & 1 deletion OVP/D3D7Client/VPlanet.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ class vPlanet: public vObject {
void RenderSphere (LPDIRECT3DDEVICE7 dev, const RenderPrm &prm, bool &using_zbuf);
void RenderCloudLayer (LPDIRECT3DDEVICE7 dev, DWORD cullmode, const RenderPrm &prm);
void RenderVectors(LPDIRECT3DDEVICE7 dev);
void RenderBaseVectors(LPDIRECT3DDEVICE7 dev);
void RenderBaseSurfaces (LPDIRECT3DDEVICE7 dev);
void RenderBaseStructures (LPDIRECT3DDEVICE7 dev);
void RenderBaseShadows (LPDIRECT3DDEVICE7 dev, float depth);
void RenderBaseVectors(LPDIRECT3DDEVICE7 dev);
void RenderCloudShadows (LPDIRECT3DDEVICE7 dev, const RenderPrm &prm);
bool ModLighting (DWORD &ambient);

Expand Down
3 changes: 1 addition & 2 deletions OVP/D3D7Client/VVessel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,9 @@ void vVessel::UpdateRenderVectors()
if ((flag & BF_TORQUE) && vessel->GetTorqueVector(F)) {
sprintf(cbuf, "M = %fNm", len = length(F));
if (logscale) len = log(len + 1e-5) - log(1e-5); else len *= scale * 1e5;
AddVector(unit(F) * (len * pscale), _V(0, 0, 0), scale2, std::string(cbuf), _V(1, 0, 1), alpha, D3DRGB(1, 0, 1));
AddVector(unit(F) * (len * pscale), _V(0, 0, 0), scale2 * 0.5, std::string(cbuf), _V(1, 0, 1), alpha, D3DRGB(1, 0, 1));
}
}

}

void vVessel::LoadMeshes ()
Expand Down
51 changes: 42 additions & 9 deletions Src/Orbiter/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ void Scene::Timejump (PlanetarySystem *psys, Camera **camlist, DWORD ncam, bool

static int lvlid[256];

void Scene::Render3DLabel (const Vector &gp, char *label, double scale, DWORD colour)
void Scene::Render3DLabel (const Vector &gp, const char *label, double scale, DWORD colour)
{
static VERTEX_TL1TEX Vtx[4] = {
{0,0,0,0,(D3DCOLOR)D3DRGBA(1,1,1,1),0.001f,0.001f},
Expand Down Expand Up @@ -589,7 +589,7 @@ void Scene::Render3DLabel (const Vector &gp, char *label, double scale, DWORD co
w = 0;
x0 = 0;
v = 0;
for (char *c = label; *c; c++) {
for (const char *c = label; *c; c++) {
int idx = *c - 32;
sr.left = gfont_ofs[0][idx];
sr.right = sr.left + gfont_cw[0][idx];
Expand Down Expand Up @@ -948,13 +948,11 @@ void Scene::Render (D3DRECT* vp_rect)
pstream[n]->Render (dev, ptex);
if (ptex) dev->SetTexture (0, 0);

// render object vectors - should this be done without z-buffer?
bool bRenderVectors = true;
if (bRenderVectors) {
g_camera->SetFrustumLimits (1.0, 1e30);
for (i = 0; i < nobj; i++)
vobj[i]->RenderVectors (dev);
g_camera->SetFrustumLimits (npl, fpl); // reset fustrum limits
// render object vectors
if (*(DWORD*)gc->GetConfigParam(CFGPRM_FORCEVECTORFLAG) & BF_ENABLE || *(DWORD*)gc->GetConfigParam(CFGPRM_FRAMEAXISFLAG) & FA_ENABLE) {
g_camera->SetFrustumLimits(1.0, 1e30);
RenderVectors();
g_camera->SetFrustumLimits(npl, fpl); // reset fustrum limits
}

// render focus object in cockpit view
Expand Down Expand Up @@ -1029,3 +1027,38 @@ void Scene::RenderVesselShadows ()
SetDefaultMaterial();
dev->SetRenderState (D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
}

void Scene::RenderVectors()
{
dev->SetRenderState(D3DRENDERSTATE_ZENABLE, FALSE);
dev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR);
dev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);

dev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
dev->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
dev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);

dev->SetRenderState(D3DRENDERSTATE_SPECULARENABLE, TRUE);
dev->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTFG_POINT);
dev->SetTextureStageState(0, D3DTSS_MINFILTER, D3DTFN_POINT);
dev->SetTexture(0, 0);
D3DMATERIAL7 pmtrl, mtrl = { {1,1,1,1},{1,1,1,1},{1,1,1,1},{0.2,0.2,0.2,1},40 };
dev->GetMaterial(&pmtrl);
dev->SetMaterial(&mtrl);

for (int i = 0; i < nobj; i++)
vobj[i]->RenderVectors(dev);

dev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
dev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
dev->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_CURRENT);
dev->SetRenderState(D3DRENDERSTATE_SPECULARENABLE, FALSE);
dev->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTFG_LINEAR);
dev->SetTextureStageState(0, D3DTSS_MINFILTER, D3DTFN_LINEAR);
dev->SetMaterial(&pmtrl);

for (int i = 0; i < nobj; i++)
vobj[i]->RenderVectorLabels(dev);

dev->SetRenderState(D3DRENDERSTATE_ZENABLE, TRUE);
}
10 changes: 9 additions & 1 deletion Src/Orbiter/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Scene {
void Render (D3DRECT* vp_rect);
// Render the scene in vp using device dev

void Render3DLabel (const Vector &p, char *label, double scale = 1.0, DWORD colour = D3DRGBA(1,1,1,1));
void Render3DLabel (const Vector &p, const char *label, double scale = 1.0, DWORD colour = D3DRGBA(1,1,1,1));
// Render text "label" at position p using current world matrix

void RenderObjectMarker (oapi::Sketchpad* pSkp, const Vector &gpos, const std::string& label1, const std::string& label2 = 0, int mode = 0, int scale = 0);
Expand All @@ -111,6 +111,14 @@ class Scene {
double MinParticleCameraDist() const;
// return the minimum distance between the camera and any particle in the scene

protected:
/**
* \brief Render vector features for each visual object if requested
* (frame axes, force vectors, etc.)
*/
void RenderVectors();


private:
OrbiterGraphics *gc; // graphics client instance

Expand Down
19 changes: 0 additions & 19 deletions Src/Orbiter/VBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,25 +720,6 @@ void VBase::RenderGroundShadow (LPDIRECT3DDEVICE7 dev)
}
}

void VBase::SetupRenderVectorList ()
{
DWORD flag = g_pOrbiter->Cfg()->CfgVisHelpPrm.flagFrameAxes;
if ((flag & FA_ENABLE) && (flag & FA_BASE)) {
double scale = base->size * g_pOrbiter->Cfg()->CfgVisHelpPrm.scaleFrameAxes;
double rad = base->size*0.02;
float alpha = g_pOrbiter->Cfg()->CfgVisHelpPrm.opacFrameAxes;
Vector cam (tmul (base->GRot(), g_camera->GPos()-base->GPos()));
AddVec (cam, Vector(scale,0,0), Vector(0,0,0), rad, Vector(0.5,0.5,0.5), alpha, LABEL_PX, D3DRGB(1,1,1));
AddVec (cam, Vector(0,scale,0), Vector(0,0,0), rad, Vector(0.5,0.5,0.5), alpha, LABEL_PY, D3DRGB(1,1,1));
AddVec (cam, Vector(0,0,scale), Vector(0,0,0), rad, Vector(0.5,0.5,0.5), alpha, LABEL_PZ, D3DRGB(1,1,1));
if (flag & FA_NEG) {
AddVec (cam, Vector(-scale,0,0), Vector(0,0,0), rad, Vector(0.5,0.5,0.5), alpha, LABEL_NX, D3DRGB(1,1,1));
AddVec (cam, Vector(0,-scale,0), Vector(0,0,0), rad, Vector(0.5,0.5,0.5), alpha, LABEL_NY, D3DRGB(1,1,1));
AddVec (cam, Vector(0,0,-scale), Vector(0,0,0), rad, Vector(0.5,0.5,0.5), alpha, LABEL_NZ, D3DRGB(1,1,1));
}
}
}

bool VBase::ModLighting (LPD3DLIGHT7 light)
{
const CelestialBody *cb = base->RefPlanet();
Expand Down
1 change: 0 additions & 1 deletion Src/Orbiter/VBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class VBase: public VObject {
void RenderShadows (LPDIRECT3DDEVICE7 dev);
void RenderStructures (LPDIRECT3DDEVICE7 dev);
void RenderGroundShadow (LPDIRECT3DDEVICE7 dev);
void SetupRenderVectorList ();
const Base *GetBase() const { return base; }
Vector SunDir () const { return sundir; }

Expand Down
34 changes: 14 additions & 20 deletions Src/Orbiter/VPlanet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,20 @@ void VPlanet::RenderCloudShadows (LPDIRECT3DDEVICE7 dev)
}
}

void VPlanet::RenderVectors(LPDIRECT3DDEVICE7 dev)
{
VObject::RenderVectors(dev);
RenderBaseVectors(dev);
}

void VPlanet::RenderBaseVectors(LPDIRECT3DDEVICE7 dev)
{
for (DWORD i = 0; i < planet->nBase(); i++) {
VBase* vbase = (VBase*)planet->GetBase(i)->GetVishandle();
if (vbase) vbase->RenderVectors(dev);
}
}

void VPlanet::RenderBaseSurfaceTiles (LPDIRECT3DDEVICE7 dev)
{
for (DWORD i = 0; i < planet->nBase(); i++) {
Expand Down Expand Up @@ -765,26 +779,6 @@ int VPlanet::ShadowPlanetOnRing (VERTEX_XYZC *&vtx, DWORD &nvtx)
return nvtx;
}

void VPlanet::SetupRenderVectorList ()
{
DWORD flag = g_pOrbiter->Cfg()->CfgVisHelpPrm.flagFrameAxes;
if ((flag & FA_ENABLE) && (flag & FA_CBODY)) {
double psize = planet->Size();
double scale = g_pOrbiter->Cfg()->CfgVisHelpPrm.scaleFrameAxes * psize*1.3;
double rad = 0.02 * psize;
float alpha = g_pOrbiter->Cfg()->CfgVisHelpPrm.opacFrameAxes;
Vector cam (tmul (planet->GRot(), g_camera->GPos()-planet->GPos()));
AddVec (cam, Vector(scale,0,0), Vector(0,0,0), rad, Vector(0.5,0.5,0.5), alpha, LABEL_PX, D3DRGB(1,1,1));
AddVec (cam, Vector(0,scale,0), Vector(0,0,0), rad, Vector(0.5,0.5,0.5), alpha, LABEL_PY, D3DRGB(1,1,1));
AddVec (cam, Vector(0,0,scale), Vector(0,0,0), rad, Vector(0.5,0.5,0.5), alpha, LABEL_PZ, D3DRGB(1,1,1));
if (flag & FA_NEG) {
AddVec (cam, Vector(-scale,0,0), Vector(0,0,0), rad, Vector(0.5,0.5,0.5), alpha, LABEL_NX, D3DRGB(1,1,1));
AddVec (cam, Vector(0,-scale,0), Vector(0,0,0), rad, Vector(0.5,0.5,0.5), alpha, LABEL_NY, D3DRGB(1,1,1));
AddVec (cam, Vector(0,0,-scale), Vector(0,0,0), rad, Vector(0.5,0.5,0.5), alpha, LABEL_NZ, D3DRGB(1,1,1));
}
}
}

bool VPlanet::ModLighting (DWORD &ambient)
{
// Eventually we may need to modify the direct light levels (diffuse+specular) as
Expand Down
5 changes: 3 additions & 2 deletions Src/Orbiter/VPlanet.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class VPlanet: public VObject {
void RenderCloudShadows (LPDIRECT3DDEVICE7 dev);
// render cloud shadows on the ground

void RenderVectors(LPDIRECT3DDEVICE7 dev);
void RenderBaseVectors(LPDIRECT3DDEVICE7 dev);

void RenderBaseSurfaceTiles (LPDIRECT3DDEVICE7 dev);
void RenderBaseSurfaceDecals (LPDIRECT3DDEVICE7 dev);
void RenderBaseShadows (LPDIRECT3DDEVICE7 dev, float alpha);
Expand All @@ -84,8 +87,6 @@ class VPlanet: public VObject {
void RenderRing (LPDIRECT3DDEVICE7 dev, bool addbkg = false);
// render ring system around planet

void SetupRenderVectorList ();

PatchManager *cloudmanager;
HorizonManager *horizonmanager;
RingManager *ringmanager;
Expand Down
Loading

0 comments on commit bb6734c

Please sign in to comment.