Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
[sea_cameras] Add debug draw for camera
Browse files Browse the repository at this point in the history
  • Loading branch information
espkk committed Mar 28, 2022
1 parent abdce36 commit 900a9a0
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/libs/common/include/dx9render.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ class VDX9RENDER : public SERVICE
virtual void SetColorParameters(float fGamma, float fBrightness, float fContrast) = 0;

virtual void DrawSphere(const CVECTOR &vPos, float fRadius, uint32_t dwColor) = 0;
virtual void DrawEllipsoid(const CVECTOR &vPos, float a, float b, float c, float ay, uint32_t dwColor) = 0;

virtual void GetNearFarPlane(float &fNear, float &fFar) = 0;
virtual void SetNearFarPlane(float fNear, float fFar) = 0;
Expand Down
14 changes: 14 additions & 0 deletions src/libs/renderer/src/s_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4436,6 +4436,20 @@ void DX9RENDER::DrawSphere(const CVECTOR &vPos, float fRadius, uint32_t dwColor)
sizeof(DX9SphVertex), "DXSphere");
}


void DX9RENDER::DrawEllipsoid(const CVECTOR &vPos, float a, float b, float c, float ay, uint32_t dwColor)
{
CMatrix trans, scale, rot;
trans.BuildPosition(vPos.x, vPos.y, vPos.z);
scale.BuildScale(a, b, c);
rot.BuildRotateY(ay);

SetTransform(D3DTS_WORLD, scale * rot * trans);
SetRenderState(D3DRS_TEXTUREFACTOR, dwColor);
DrawPrimitiveUP(D3DPT_TRIANGLELIST, D3DFVF_XYZ | D3DFVF_DIFFUSE, DX9sphereNumTrgs, DX9sphereVertex,
sizeof(DX9SphVertex), "DXEllipsoid");
}

void DX9RENDER::SetLoadTextureEnable(bool bEnable)
{
bLoadTextureEnabled = bEnable;
Expand Down
1 change: 1 addition & 0 deletions src/libs/renderer/src/s_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ class DX9RENDER : public VDX9RENDER

void SetColorParameters(float fGamma, float fBrightness, float fContrast) override;
void DrawSphere(const CVECTOR &vPos, float fRadius, uint32_t dwColor) override;
void DrawEllipsoid(const CVECTOR &vPos, float a, float b, float c, float ay, uint32_t dwColor) override;

void GetNearFarPlane(float &fNear, float &fFar) override;
void SetNearFarPlane(float fNear, float fFar) override;
Expand Down
1 change: 1 addition & 0 deletions src/libs/sea_cameras/src/sea_cameras.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "sea_cameras.h"
#include "deck_camera.h"
#include "free_camera.h"
#include "ship_camera.h"
#include "shared/sea_ai/script_defines.h"

CREATE_CLASS(SEA_CAMERAS)
Expand Down
3 changes: 2 additions & 1 deletion src/libs/sea_cameras/src/sea_cameras.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "ship_camera.h"
#include "common_camera.h"

#include <vector>

class SEA_CAMERAS : public Entity
Expand Down
27 changes: 13 additions & 14 deletions src/libs/sea_cameras/src/ship_camera.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "ship_camera.h"
#include "sd2_h/save_load.h"
#include "core.h"
#include "sd2_h/save_load.h"
#include "ship_camera.h"

#define SCMR_BOXSCALE_X 1.6f
#define SCMR_BOXSCALE_Y 1.3f
Expand Down Expand Up @@ -72,6 +72,12 @@ void SHIP_CAMERA::Execute(uint32_t dwDeltaTime)
Move(fDeltaTime);
}

void SHIP_CAMERA::Realize(uint32_t dwDeltaTime)
{
pRS->DrawEllipsoid(GetAIObj()->GetPos(), a, b, c, fModelAy, 0x900C0C0C);
pRS->DrawSphere(vCenter, 5.0f, 0xFFFFFFFF);
}

void SHIP_CAMERA::Move(float fDeltaTime)
{
if (!pSea)
Expand All @@ -80,7 +86,6 @@ void SHIP_CAMERA::Move(float fDeltaTime)
return;

const auto fSpeed = fDeltaTime;
auto fTempHeight = 0.0f;

CONTROL_STATE cs;

Expand All @@ -98,7 +103,6 @@ void SHIP_CAMERA::Move(float fDeltaTime)
fKInert = 0.0f;
if (fKInert > 1.0f)
fKInert = 1.0f;
fSensivityDistance = 1.0f;
fDistanceDlt += (fSensivityDistanceDlt - fDistanceDlt) * fKInert;
fDistance += fSpeed * fDistanceDlt;
if (fDistance > 1.0f)
Expand Down Expand Up @@ -141,14 +145,13 @@ void SHIP_CAMERA::Move(float fDeltaTime)
// Current distance
auto boxSize =
GetAIObj()->GetBoxsize() * CVECTOR(SCMR_BOXSCALE_X * 0.5f, SCMR_BOXSCALE_Y * 0.5f, SCMR_BOXSCALE_Z * 0.5f);
const auto realBoxSize = GetAIObj()->GetRealBoxsize();
boxSize.x += realBoxSize.y;
boxSize.z += realBoxSize.y;
boxSize.x += boxSize.y;
boxSize.z += boxSize.y;
const auto maxRad = boxSize.z * 2.0f;
// Semi-axes of the ellipsoid along which the camera moves
const auto a = boxSize.x * 1.2f + fDistance * (maxRad - boxSize.x * 1.2f); // x
const auto b = boxSize.y * 1.5f + fDistance * (70.0f - boxSize.y * 1.5f); // y
const auto c = boxSize.z * 1.2f + fDistance * (maxRad - boxSize.z * 1.2f); // z
a = boxSize.x * 1.2f + fDistance * (maxRad - boxSize.x * 1.2f); // x
b = boxSize.y * 1.5f + fDistance * (70.0f - boxSize.y * 1.5f); // y
c = boxSize.z * 1.2f + fDistance * (maxRad - boxSize.z * 1.2f); // z
// Find the position of the camera on the ellipsoid
vCenter.y += 0.5f * boxSize.y;
CVECTOR vPos;
Expand Down Expand Up @@ -190,10 +193,6 @@ void SHIP_CAMERA::Move(float fDeltaTime)
pRS->SetPerspective(GetPerspective());
}

void SHIP_CAMERA::Realize(uint32_t dwDeltaTime)
{
}

void SHIP_CAMERA::SetCharacter(ATTRIBUTES *_pACharacter)
{
entid_t eidTemp;
Expand Down
2 changes: 2 additions & 0 deletions src/libs/sea_cameras/src/ship_camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class SHIP_CAMERA : public COMMON_CAMERA
CVECTOR vCenter, vAng;
float fModelAy;

float a, b, c; // camera ellipsoid parameters

// int32_t minHeightOnSea,maxHeightOnSea;

private:
Expand Down
21 changes: 21 additions & 0 deletions src/techniques/_dev/dxdraw.fx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,27 @@ technique DXSphere
AlphaArg1[0] = tfactor;
AlphaArg2[0] = diffuse;

ColorOp[1] = disable;
}
}

technique DXEllipsoid
{
pass p0
{
ZWriteEnable = false;
Lighting = false;
AlphaTestEnable = false;
AlphaBlendEnable = true;
SrcBlend = srcalpha;
DestBlend = invsrcalpha;

ColorOp[0] = selectarg1;
ColorArg1[0] = tfactor;

AlphaOp[0] = selectarg1;
AlphaArg1[0] = tfactor;

ColorOp[1] = disable;
}
}

0 comments on commit 900a9a0

Please sign in to comment.