2019-05-15 14:52:37 +00:00
|
|
|
#include "common.h"
|
2020-04-17 13:31:11 +00:00
|
|
|
|
2020-10-29 18:11:47 +00:00
|
|
|
#include "RwHelper.h"
|
2019-05-15 14:52:37 +00:00
|
|
|
#include "templates.h"
|
2020-11-03 19:33:07 +00:00
|
|
|
#include "main.h"
|
2019-05-15 14:52:37 +00:00
|
|
|
#include "Entity.h"
|
|
|
|
#include "ModelInfo.h"
|
|
|
|
#include "Lights.h"
|
2020-05-11 20:21:18 +00:00
|
|
|
#include "RwHelper.h"
|
2019-05-15 14:52:37 +00:00
|
|
|
#include "Renderer.h"
|
2019-05-31 09:44:43 +00:00
|
|
|
#include "Camera.h"
|
2019-05-15 14:52:37 +00:00
|
|
|
#include "VisibilityPlugins.h"
|
2019-10-26 11:12:24 +00:00
|
|
|
#include "World.h"
|
2020-08-19 14:10:22 +00:00
|
|
|
#include "custompipes.h"
|
2020-11-26 15:47:19 +00:00
|
|
|
#include "MemoryHeap.h"
|
2019-05-15 14:52:37 +00:00
|
|
|
|
2020-05-11 20:21:18 +00:00
|
|
|
//--MIAMI: file done
|
|
|
|
|
2020-04-17 05:54:14 +00:00
|
|
|
CLinkList<CVisibilityPlugins::AlphaObjectInfo> CVisibilityPlugins::m_alphaList;
|
2020-05-11 20:21:18 +00:00
|
|
|
CLinkList<CVisibilityPlugins::AlphaObjectInfo> CVisibilityPlugins::m_alphaBoatAtomicList;
|
2020-04-17 05:54:14 +00:00
|
|
|
CLinkList<CVisibilityPlugins::AlphaObjectInfo> CVisibilityPlugins::m_alphaEntityList;
|
2020-05-11 20:21:18 +00:00
|
|
|
CLinkList<CVisibilityPlugins::AlphaObjectInfo> CVisibilityPlugins::m_alphaUnderwaterEntityList;
|
2020-11-03 19:33:07 +00:00
|
|
|
#ifdef NEW_RENDERER
|
|
|
|
CLinkList<CVisibilityPlugins::AlphaObjectInfo> CVisibilityPlugins::m_alphaBuildingList;
|
|
|
|
#endif
|
2020-04-16 08:50:45 +00:00
|
|
|
|
2020-04-17 05:54:14 +00:00
|
|
|
int32 CVisibilityPlugins::ms_atomicPluginOffset = -1;
|
|
|
|
int32 CVisibilityPlugins::ms_framePluginOffset = -1;
|
|
|
|
int32 CVisibilityPlugins::ms_clumpPluginOffset = -1;
|
2020-04-16 08:50:45 +00:00
|
|
|
|
2020-04-17 05:54:14 +00:00
|
|
|
RwCamera *CVisibilityPlugins::ms_pCamera;
|
|
|
|
RwV3d *CVisibilityPlugins::ms_pCameraPosn;
|
|
|
|
float CVisibilityPlugins::ms_cullCompsDist;
|
|
|
|
float CVisibilityPlugins::ms_vehicleLod0Dist;
|
|
|
|
float CVisibilityPlugins::ms_vehicleLod1Dist;
|
|
|
|
float CVisibilityPlugins::ms_vehicleFadeDist;
|
|
|
|
float CVisibilityPlugins::ms_bigVehicleLod0Dist;
|
|
|
|
float CVisibilityPlugins::ms_bigVehicleLod1Dist;
|
|
|
|
float CVisibilityPlugins::ms_pedLod1Dist;
|
|
|
|
float CVisibilityPlugins::ms_pedFadeDist;
|
2019-05-15 14:52:37 +00:00
|
|
|
|
2020-12-13 11:53:19 +00:00
|
|
|
#define RENDERCALLBACK AtomicDefaultRenderCallBack
|
|
|
|
|
2019-05-15 14:52:37 +00:00
|
|
|
void
|
|
|
|
CVisibilityPlugins::Initialise(void)
|
|
|
|
{
|
2020-04-16 09:44:04 +00:00
|
|
|
m_alphaList.Init(NUMALPHALIST);
|
2019-05-15 14:52:37 +00:00
|
|
|
m_alphaList.head.item.sort = 0.0f;
|
|
|
|
m_alphaList.tail.item.sort = 100000000.0f;
|
2020-05-11 20:21:18 +00:00
|
|
|
|
|
|
|
m_alphaBoatAtomicList.Init(NUMBOATALPHALIST);
|
|
|
|
m_alphaBoatAtomicList.head.item.sort = 0.0f;
|
|
|
|
m_alphaBoatAtomicList.tail.item.sort = 100000000.0f;
|
|
|
|
|
2020-04-16 09:44:04 +00:00
|
|
|
#ifdef ASPECT_RATIO_SCALE
|
|
|
|
// default 150 if not enough for bigger FOVs
|
|
|
|
m_alphaEntityList.Init(NUMALPHAENTITYLIST * 3);
|
|
|
|
#else
|
|
|
|
m_alphaEntityList.Init(NUMALPHAENTITYLIST);
|
|
|
|
#endif // ASPECT_RATIO_SCALE
|
2019-05-15 14:52:37 +00:00
|
|
|
m_alphaEntityList.head.item.sort = 0.0f;
|
|
|
|
m_alphaEntityList.tail.item.sort = 100000000.0f;
|
2020-05-11 20:21:18 +00:00
|
|
|
|
|
|
|
m_alphaUnderwaterEntityList.Init(NUMALPHAUNTERWATERENTITYLIST);
|
|
|
|
m_alphaUnderwaterEntityList.head.item.sort = 0.0f;
|
|
|
|
m_alphaUnderwaterEntityList.tail.item.sort = 100000000.0f;
|
|
|
|
|
2020-11-03 19:33:07 +00:00
|
|
|
#ifdef NEW_RENDERER
|
|
|
|
m_alphaBuildingList.Init(NUMALPHAENTITYLIST);
|
|
|
|
m_alphaBuildingList.head.item.sort = 0.0f;
|
|
|
|
m_alphaBuildingList.tail.item.sort = 100000000.0f;
|
|
|
|
#endif
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
|
2019-06-13 10:25:55 +00:00
|
|
|
void
|
|
|
|
CVisibilityPlugins::Shutdown(void)
|
|
|
|
{
|
|
|
|
m_alphaList.Shutdown();
|
2020-05-11 20:21:18 +00:00
|
|
|
m_alphaBoatAtomicList.Shutdown();
|
2019-06-13 10:25:55 +00:00
|
|
|
m_alphaEntityList.Shutdown();
|
2020-05-11 20:21:18 +00:00
|
|
|
m_alphaUnderwaterEntityList.Shutdown();
|
2020-11-03 19:33:07 +00:00
|
|
|
#ifdef NEW_RENDERER
|
|
|
|
m_alphaBuildingList.Shutdown();
|
|
|
|
#endif
|
2019-06-13 10:25:55 +00:00
|
|
|
}
|
|
|
|
|
2019-05-15 14:52:37 +00:00
|
|
|
void
|
|
|
|
CVisibilityPlugins::InitAlphaEntityList(void)
|
|
|
|
{
|
|
|
|
m_alphaEntityList.Clear();
|
2020-05-11 20:21:18 +00:00
|
|
|
m_alphaBoatAtomicList.Clear();
|
|
|
|
m_alphaUnderwaterEntityList.Clear();
|
2020-11-03 19:33:07 +00:00
|
|
|
#ifdef NEW_RENDERER
|
|
|
|
m_alphaBuildingList.Clear();
|
|
|
|
#endif
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CVisibilityPlugins::InsertEntityIntoSortedList(CEntity *e, float dist)
|
|
|
|
{
|
|
|
|
AlphaObjectInfo item;
|
|
|
|
item.entity = e;
|
|
|
|
item.sort = dist;
|
2020-11-03 19:33:07 +00:00
|
|
|
#ifdef NEW_RENDERER
|
|
|
|
if(gbNewRenderer && e->IsBuilding())
|
|
|
|
return !!m_alphaBuildingList.InsertSorted(item);
|
|
|
|
#endif
|
2020-05-11 20:21:18 +00:00
|
|
|
if(e->bUnderwater && m_alphaUnderwaterEntityList.InsertSorted(item))
|
|
|
|
return true;
|
|
|
|
return !!m_alphaEntityList.InsertSorted(item);
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CVisibilityPlugins::InitAlphaAtomicList(void)
|
|
|
|
{
|
|
|
|
m_alphaList.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CVisibilityPlugins::InsertAtomicIntoSortedList(RpAtomic *a, float dist)
|
|
|
|
{
|
|
|
|
AlphaObjectInfo item;
|
|
|
|
item.atomic = a;
|
|
|
|
item.sort = dist;
|
2020-05-11 20:21:18 +00:00
|
|
|
return !!m_alphaList.InsertSorted(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CVisibilityPlugins::InsertAtomicIntoBoatSortedList(RpAtomic *a, float dist)
|
|
|
|
{
|
|
|
|
AlphaObjectInfo item;
|
|
|
|
item.atomic = a;
|
|
|
|
item.sort = dist;
|
|
|
|
return !!m_alphaBoatAtomicList.InsertSorted(item);
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
|
2020-12-13 11:53:19 +00:00
|
|
|
// can't increase this yet unfortunately...
|
|
|
|
// probably have to fix fading for this so material alpha isn't overwritten
|
|
|
|
#define VEHICLE_LODDIST_MULTIPLIER (TheCamera.GenerationDistMultiplier)
|
|
|
|
|
2019-05-31 09:44:43 +00:00
|
|
|
void
|
|
|
|
CVisibilityPlugins::SetRenderWareCamera(RwCamera *camera)
|
|
|
|
{
|
|
|
|
ms_pCamera = camera;
|
|
|
|
ms_pCameraPosn = RwMatrixGetPos(RwFrameGetMatrix(RwCameraGetFrame(camera)));
|
|
|
|
|
2019-10-27 03:17:30 +00:00
|
|
|
if(TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOPDOWN ||
|
|
|
|
TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOP_DOWN_PED)
|
2019-05-31 09:44:43 +00:00
|
|
|
ms_cullCompsDist = 1000000.0f;
|
|
|
|
else
|
|
|
|
ms_cullCompsDist = sq(TheCamera.LODDistMultiplier * 20.0f);
|
|
|
|
|
2020-12-13 11:53:19 +00:00
|
|
|
ms_vehicleLod0Dist = sq(70.0f * VEHICLE_LODDIST_MULTIPLIER);
|
|
|
|
ms_vehicleLod1Dist = sq(90.0f * VEHICLE_LODDIST_MULTIPLIER);
|
|
|
|
ms_vehicleFadeDist = sq(100.0f * VEHICLE_LODDIST_MULTIPLIER);
|
|
|
|
ms_bigVehicleLod0Dist = sq(60.0f * VEHICLE_LODDIST_MULTIPLIER);
|
|
|
|
ms_bigVehicleLod1Dist = sq(150.0f * VEHICLE_LODDIST_MULTIPLIER);
|
|
|
|
ms_pedLod1Dist = sq(60.0f * TheCamera.LODDistMultiplier);
|
|
|
|
ms_pedFadeDist = sq(70.0f * TheCamera.LODDistMultiplier);
|
2019-05-31 09:44:43 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 20:21:18 +00:00
|
|
|
static float DistToCameraSq;
|
|
|
|
static float PitchToCamera;
|
|
|
|
|
2020-05-11 15:03:32 +00:00
|
|
|
void
|
|
|
|
CVisibilityPlugins::SetupVehicleVariables(RpClump *vehicle)
|
|
|
|
{
|
2020-05-16 11:02:13 +00:00
|
|
|
if (RwObjectGetType((RwObject*)vehicle) != rpCLUMP)
|
2020-05-16 10:31:23 +00:00
|
|
|
return;
|
2020-05-11 20:21:18 +00:00
|
|
|
DistToCameraSq = GetDistanceSquaredFromCamera(RpClumpGetFrame(vehicle));
|
|
|
|
RwV3d distToCam;
|
|
|
|
RwV3dSub(&distToCam, ms_pCameraPosn, &RwFrameGetMatrix(RpClumpGetFrame(vehicle))->pos);
|
|
|
|
float dist2d = Sqrt(SQR(distToCam.x) + SQR(distToCam.y));
|
|
|
|
PitchToCamera = Atan2(distToCam.z, dist2d);
|
2020-05-11 15:03:32 +00:00
|
|
|
}
|
|
|
|
|
2019-05-15 14:52:37 +00:00
|
|
|
RpMaterial*
|
|
|
|
SetAlphaCB(RpMaterial *material, void *data)
|
|
|
|
{
|
2020-05-11 02:55:57 +00:00
|
|
|
((RwRGBA*)RpMaterialGetColor(material))->alpha = (uint8)(uintptr)data;
|
2019-05-15 14:52:37 +00:00
|
|
|
return material;
|
|
|
|
}
|
|
|
|
|
|
|
|
RpMaterial*
|
|
|
|
SetTextureCB(RpMaterial *material, void *data)
|
|
|
|
{
|
|
|
|
RpMaterialSetTexture(material, (RwTexture*)data);
|
|
|
|
return material;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-05-11 20:21:18 +00:00
|
|
|
CVisibilityPlugins::RenderAtomicList(CLinkList<AlphaObjectInfo> &list)
|
2019-05-15 14:52:37 +00:00
|
|
|
{
|
|
|
|
CLink<AlphaObjectInfo> *node;
|
2020-05-11 20:21:18 +00:00
|
|
|
for(node = list.tail.prev; node != &list.head; node = node->prev)
|
2020-12-13 11:53:19 +00:00
|
|
|
RENDERCALLBACK(node->item.atomic);
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-05-11 20:21:18 +00:00
|
|
|
CVisibilityPlugins::RenderAlphaAtomics(void)
|
|
|
|
{
|
|
|
|
RenderAtomicList(m_alphaList);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CVisibilityPlugins::RenderBoatAlphaAtomics(void)
|
|
|
|
{
|
|
|
|
SetCullMode(rwCULLMODECULLNONE);
|
|
|
|
RenderAtomicList(m_alphaBoatAtomicList);
|
|
|
|
SetCullMode(rwCULLMODECULLBACK);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CVisibilityPlugins::RenderFadingEntities(CLinkList<AlphaObjectInfo> &list)
|
2019-05-15 14:52:37 +00:00
|
|
|
{
|
|
|
|
CLink<AlphaObjectInfo> *node;
|
|
|
|
CSimpleModelInfo *mi;
|
2020-05-11 20:21:18 +00:00
|
|
|
for(node = list.tail.prev; node != &list.head; node = node->prev){
|
2019-05-15 14:52:37 +00:00
|
|
|
CEntity *e = node->item.entity;
|
|
|
|
if(e->m_rwObject == nil)
|
|
|
|
continue;
|
2020-08-19 14:10:22 +00:00
|
|
|
#ifdef EXTENDED_PIPELINES
|
|
|
|
if(CustomPipes::bRenderingEnvMap && (e->IsPed() || e->IsVehicle()))
|
|
|
|
continue;
|
|
|
|
#endif
|
2020-05-05 11:48:35 +00:00
|
|
|
mi = (CSimpleModelInfo *)CModelInfo::GetModelInfo(e->GetModelIndex());
|
2020-05-10 15:09:14 +00:00
|
|
|
if(mi->GetModelType() == MITYPE_SIMPLE && mi->m_noZwrite)
|
2019-05-15 14:52:37 +00:00
|
|
|
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE);
|
|
|
|
|
|
|
|
if(e->bDistanceFade){
|
|
|
|
DeActivateDirectional();
|
|
|
|
SetAmbientColours();
|
|
|
|
e->bImBeingRendered = true;
|
|
|
|
RenderFadingAtomic((RpAtomic*)e->m_rwObject, node->item.sort);
|
|
|
|
e->bImBeingRendered = false;
|
|
|
|
}else
|
|
|
|
CRenderer::RenderOneNonRoad(e);
|
|
|
|
|
2020-05-10 15:09:14 +00:00
|
|
|
if(mi->GetModelType() == MITYPE_SIMPLE && mi->m_noZwrite)
|
2019-05-15 14:52:37 +00:00
|
|
|
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-11 20:21:18 +00:00
|
|
|
void
|
|
|
|
CVisibilityPlugins::RenderFadingEntities(void)
|
|
|
|
{
|
|
|
|
RenderFadingEntities(m_alphaEntityList);
|
|
|
|
RenderBoatAlphaAtomics();
|
|
|
|
}
|
|
|
|
|
2020-05-11 15:03:32 +00:00
|
|
|
void
|
|
|
|
CVisibilityPlugins::RenderFadingUnderwaterEntities(void)
|
|
|
|
{
|
2020-05-11 20:21:18 +00:00
|
|
|
RenderFadingEntities(m_alphaUnderwaterEntityList);
|
2020-05-11 15:03:32 +00:00
|
|
|
}
|
|
|
|
|
2019-05-15 14:52:37 +00:00
|
|
|
RpAtomic*
|
|
|
|
CVisibilityPlugins::RenderWheelAtomicCB(RpAtomic *atomic)
|
|
|
|
{
|
|
|
|
RpAtomic *lodatm;
|
|
|
|
float len;
|
|
|
|
CSimpleModelInfo *mi;
|
|
|
|
|
|
|
|
mi = GetAtomicModelInfo(atomic);
|
2020-05-11 20:21:18 +00:00
|
|
|
len = Sqrt(DistToCameraSq);
|
2020-12-13 11:53:19 +00:00
|
|
|
lodatm = mi->GetAtomicFromDistance(len * TheCamera.LODDistMultiplier / VEHICLE_LODDIST_MULTIPLIER);
|
2019-05-15 14:52:37 +00:00
|
|
|
if(lodatm){
|
|
|
|
if(RpAtomicGetGeometry(lodatm) != RpAtomicGetGeometry(atomic))
|
|
|
|
RpAtomicSetGeometry(atomic, RpAtomicGetGeometry(lodatm), rpATOMICSAMEBOUNDINGSPHERE);
|
2020-12-13 11:53:19 +00:00
|
|
|
RENDERCALLBACK(atomic);
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
return atomic;
|
|
|
|
}
|
|
|
|
|
|
|
|
RpAtomic*
|
|
|
|
CVisibilityPlugins::RenderObjNormalAtomic(RpAtomic *atomic)
|
|
|
|
{
|
|
|
|
RwMatrix *m;
|
|
|
|
RwV3d view;
|
|
|
|
float len;
|
|
|
|
|
|
|
|
m = RwFrameGetLTM(RpAtomicGetFrame(atomic));
|
|
|
|
RwV3dSub(&view, RwMatrixGetPos(m), ms_pCameraPosn);
|
|
|
|
len = RwV3dLength(&view);
|
|
|
|
if(RwV3dDotProduct(&view, RwMatrixGetUp(m)) < -0.3f*len && len > 8.0f)
|
|
|
|
return atomic;
|
2020-12-13 11:53:19 +00:00
|
|
|
RENDERCALLBACK(atomic);
|
2019-05-15 14:52:37 +00:00
|
|
|
return atomic;
|
|
|
|
}
|
|
|
|
|
|
|
|
RpAtomic*
|
|
|
|
CVisibilityPlugins::RenderAlphaAtomic(RpAtomic *atomic, int alpha)
|
|
|
|
{
|
|
|
|
RpGeometry *geo;
|
|
|
|
uint32 flags;
|
|
|
|
|
|
|
|
geo = RpAtomicGetGeometry(atomic);
|
|
|
|
flags = RpGeometryGetFlags(geo);
|
|
|
|
RpGeometrySetFlags(geo, flags | rpGEOMETRYMODULATEMATERIALCOLOR);
|
|
|
|
RpGeometryForAllMaterials(geo, SetAlphaCB, (void*)alpha);
|
2020-12-13 11:53:19 +00:00
|
|
|
RENDERCALLBACK(atomic);
|
2019-05-15 14:52:37 +00:00
|
|
|
RpGeometryForAllMaterials(geo, SetAlphaCB, (void*)255);
|
|
|
|
RpGeometrySetFlags(geo, flags);
|
|
|
|
return atomic;
|
|
|
|
}
|
|
|
|
|
2020-05-10 08:04:20 +00:00
|
|
|
RpAtomic*
|
|
|
|
CVisibilityPlugins::RenderWeaponCB(RpAtomic *atomic)
|
|
|
|
{
|
|
|
|
RwMatrix *m;
|
|
|
|
RwV3d view;
|
|
|
|
float maxdist, distsq;
|
|
|
|
CSimpleModelInfo *mi;
|
|
|
|
|
|
|
|
mi = GetAtomicModelInfo(atomic);
|
|
|
|
m = RwFrameGetLTM(RpAtomicGetFrame(atomic));
|
|
|
|
RwV3dSub(&view, RwMatrixGetPos(m), ms_pCameraPosn);
|
|
|
|
maxdist = mi->GetLodDistance(0);
|
|
|
|
distsq = RwV3dDotProduct(&view, &view);
|
|
|
|
if(distsq < maxdist*maxdist)
|
2020-12-13 11:53:19 +00:00
|
|
|
RENDERCALLBACK(atomic);
|
2020-05-10 08:04:20 +00:00
|
|
|
return atomic;
|
|
|
|
}
|
|
|
|
|
2019-05-15 14:52:37 +00:00
|
|
|
RpAtomic*
|
|
|
|
CVisibilityPlugins::RenderFadingAtomic(RpAtomic *atomic, float camdist)
|
|
|
|
{
|
|
|
|
RpAtomic *lodatm;
|
|
|
|
float fadefactor;
|
2020-05-11 23:24:57 +00:00
|
|
|
uint32 alpha;
|
2019-05-15 14:52:37 +00:00
|
|
|
CSimpleModelInfo *mi;
|
|
|
|
|
|
|
|
mi = GetAtomicModelInfo(atomic);
|
|
|
|
lodatm = mi->GetAtomicFromDistance(camdist - FADE_DISTANCE);
|
2020-05-11 15:03:32 +00:00
|
|
|
if(mi->m_additive)
|
2020-11-03 19:33:07 +00:00
|
|
|
RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE);
|
2020-05-11 15:03:32 +00:00
|
|
|
|
|
|
|
fadefactor = (mi->GetLargestLodDistance() - (camdist - FADE_DISTANCE))/FADE_DISTANCE;
|
|
|
|
if(fadefactor > 1.0f)
|
|
|
|
fadefactor = 1.0f;
|
|
|
|
alpha = mi->m_alpha * fadefactor;
|
|
|
|
if(alpha == 255)
|
2020-12-13 11:53:19 +00:00
|
|
|
RENDERCALLBACK(atomic);
|
2020-05-11 15:03:32 +00:00
|
|
|
else{
|
|
|
|
RpGeometry *geo = RpAtomicGetGeometry(lodatm);
|
|
|
|
uint32 flags = RpGeometryGetFlags(geo);
|
|
|
|
RpGeometrySetFlags(geo, flags | rpGEOMETRYMODULATEMATERIALCOLOR);
|
|
|
|
RpGeometryForAllMaterials(geo, SetAlphaCB, (void*)alpha);
|
|
|
|
if(geo != RpAtomicGetGeometry(atomic))
|
|
|
|
RpAtomicSetGeometry(atomic, geo, rpATOMICSAMEBOUNDINGSPHERE); // originally 5 (mistake?)
|
2020-12-13 11:53:19 +00:00
|
|
|
RENDERCALLBACK(atomic);
|
2020-05-11 15:03:32 +00:00
|
|
|
RpGeometryForAllMaterials(geo, SetAlphaCB, (void*)255);
|
|
|
|
RpGeometrySetFlags(geo, flags);
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
2020-05-11 15:03:32 +00:00
|
|
|
|
|
|
|
if(mi->m_additive)
|
|
|
|
RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA);
|
|
|
|
|
2019-05-15 14:52:37 +00:00
|
|
|
return atomic;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RpAtomic*
|
|
|
|
CVisibilityPlugins::RenderVehicleHiDetailCB(RpAtomic *atomic)
|
|
|
|
{
|
|
|
|
RwFrame *clumpframe;
|
2020-05-11 20:21:18 +00:00
|
|
|
float dot;
|
2019-05-15 14:52:37 +00:00
|
|
|
uint32 flags;
|
|
|
|
|
|
|
|
clumpframe = RpClumpGetFrame(RpAtomicGetClump(atomic));
|
2020-05-11 20:21:18 +00:00
|
|
|
if(DistToCameraSq < ms_vehicleLod0Dist){
|
2019-05-15 14:52:37 +00:00
|
|
|
flags = GetAtomicId(atomic);
|
2020-05-11 20:21:18 +00:00
|
|
|
if(DistToCameraSq > ms_cullCompsDist && (flags & ATOMIC_FLAG_NOCULL) == 0 && PitchToCamera < 0.2f){
|
2019-05-15 14:52:37 +00:00
|
|
|
dot = GetDotProductWithCameraVector(RwFrameGetLTM(RpAtomicGetFrame(atomic)),
|
|
|
|
RwFrameGetLTM(clumpframe), flags);
|
2020-05-11 20:21:18 +00:00
|
|
|
if(dot > 0.0f && ((flags & ATOMIC_FLAG_ANGLECULL) || 0.1f*DistToCameraSq < dot*dot))
|
2019-05-15 14:52:37 +00:00
|
|
|
return atomic;
|
|
|
|
}
|
2020-12-13 11:53:19 +00:00
|
|
|
RENDERCALLBACK(atomic);
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
return atomic;
|
|
|
|
}
|
|
|
|
|
|
|
|
RpAtomic*
|
|
|
|
CVisibilityPlugins::RenderVehicleHiDetailAlphaCB(RpAtomic *atomic)
|
|
|
|
{
|
|
|
|
RwFrame *clumpframe;
|
2020-05-11 20:21:18 +00:00
|
|
|
float dot;
|
2019-05-15 14:52:37 +00:00
|
|
|
uint32 flags;
|
|
|
|
|
|
|
|
clumpframe = RpClumpGetFrame(RpAtomicGetClump(atomic));
|
2020-05-11 20:21:18 +00:00
|
|
|
if(DistToCameraSq < ms_vehicleLod0Dist){
|
2019-05-15 14:52:37 +00:00
|
|
|
flags = GetAtomicId(atomic);
|
|
|
|
dot = GetDotProductWithCameraVector(RwFrameGetLTM(RpAtomicGetFrame(atomic)),
|
|
|
|
RwFrameGetLTM(clumpframe), flags);
|
2020-05-11 20:21:18 +00:00
|
|
|
if(DistToCameraSq > ms_cullCompsDist && (flags & ATOMIC_FLAG_NOCULL) == 0 && PitchToCamera < 0.2f)
|
|
|
|
if(dot > 0.0f && ((flags & ATOMIC_FLAG_ANGLECULL) || 0.1f*DistToCameraSq < dot*dot))
|
2019-05-15 14:52:37 +00:00
|
|
|
return atomic;
|
|
|
|
|
|
|
|
if(flags & ATOMIC_FLAG_DRAWLAST){
|
|
|
|
// sort before clump
|
2020-05-11 20:21:18 +00:00
|
|
|
if(!InsertAtomicIntoSortedList(atomic, DistToCameraSq - 0.0001f))
|
2020-12-13 11:53:19 +00:00
|
|
|
RENDERCALLBACK(atomic);
|
2019-05-15 14:52:37 +00:00
|
|
|
}else{
|
2020-05-11 20:21:18 +00:00
|
|
|
if(!InsertAtomicIntoSortedList(atomic, DistToCameraSq + dot))
|
2020-12-13 11:53:19 +00:00
|
|
|
RENDERCALLBACK(atomic);
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return atomic;
|
|
|
|
}
|
|
|
|
|
|
|
|
RpAtomic*
|
|
|
|
CVisibilityPlugins::RenderVehicleHiDetailCB_BigVehicle(RpAtomic *atomic)
|
|
|
|
{
|
|
|
|
RwFrame *clumpframe;
|
2020-05-11 20:21:18 +00:00
|
|
|
float dot;
|
2019-05-15 14:52:37 +00:00
|
|
|
uint32 flags;
|
|
|
|
|
|
|
|
clumpframe = RpClumpGetFrame(RpAtomicGetClump(atomic));
|
2020-05-11 20:21:18 +00:00
|
|
|
if(DistToCameraSq < ms_bigVehicleLod0Dist){
|
2019-05-15 14:52:37 +00:00
|
|
|
flags = GetAtomicId(atomic);
|
2020-05-11 20:21:18 +00:00
|
|
|
if(DistToCameraSq > ms_cullCompsDist && (flags & ATOMIC_FLAG_NOCULL) == 0 && PitchToCamera < 0.2f){
|
2019-05-15 14:52:37 +00:00
|
|
|
dot = GetDotProductWithCameraVector(RwFrameGetLTM(RpAtomicGetFrame(atomic)),
|
|
|
|
RwFrameGetLTM(clumpframe), flags);
|
|
|
|
if(dot > 0.0f)
|
|
|
|
return atomic;
|
|
|
|
}
|
2020-12-13 11:53:19 +00:00
|
|
|
RENDERCALLBACK(atomic);
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
return atomic;
|
|
|
|
}
|
|
|
|
|
|
|
|
RpAtomic*
|
|
|
|
CVisibilityPlugins::RenderVehicleHiDetailAlphaCB_BigVehicle(RpAtomic *atomic)
|
|
|
|
{
|
|
|
|
RwFrame *clumpframe;
|
2020-05-11 20:21:18 +00:00
|
|
|
float dot;
|
2019-05-15 14:52:37 +00:00
|
|
|
uint32 flags;
|
|
|
|
|
|
|
|
clumpframe = RpClumpGetFrame(RpAtomicGetClump(atomic));
|
2020-05-11 20:21:18 +00:00
|
|
|
if(DistToCameraSq < ms_bigVehicleLod0Dist){
|
2019-05-15 14:52:37 +00:00
|
|
|
flags = GetAtomicId(atomic);
|
|
|
|
dot = GetDotProductWithCameraVector(RwFrameGetLTM(RpAtomicGetFrame(atomic)),
|
|
|
|
RwFrameGetLTM(clumpframe), flags);
|
2020-05-11 20:21:18 +00:00
|
|
|
if(DistToCameraSq > ms_cullCompsDist && (flags & ATOMIC_FLAG_NOCULL) == 0 && PitchToCamera < 0.2f)
|
|
|
|
if(dot > 0.0f && ((flags & ATOMIC_FLAG_ANGLECULL) || 0.1f*DistToCameraSq < dot*dot))
|
2019-05-15 14:52:37 +00:00
|
|
|
return atomic;
|
|
|
|
|
2020-05-11 20:21:18 +00:00
|
|
|
if(!InsertAtomicIntoSortedList(atomic, DistToCameraSq + dot))
|
2020-12-13 11:53:19 +00:00
|
|
|
RENDERCALLBACK(atomic);
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
return atomic;
|
|
|
|
}
|
|
|
|
|
|
|
|
RpAtomic*
|
|
|
|
CVisibilityPlugins::RenderVehicleHiDetailCB_Boat(RpAtomic *atomic)
|
|
|
|
{
|
2020-05-11 20:21:18 +00:00
|
|
|
if(DistToCameraSq < ms_bigVehicleLod1Dist)
|
2020-12-13 11:53:19 +00:00
|
|
|
RENDERCALLBACK(atomic);
|
2019-05-15 14:52:37 +00:00
|
|
|
return atomic;
|
|
|
|
}
|
|
|
|
|
2020-05-11 20:21:18 +00:00
|
|
|
RpAtomic*
|
|
|
|
CVisibilityPlugins::RenderVehicleHiDetailAlphaCB_Boat(RpAtomic *atomic)
|
|
|
|
{
|
|
|
|
if(DistToCameraSq < ms_vehicleLod0Dist){
|
|
|
|
if(GetAtomicId(atomic) & ATOMIC_FLAG_DRAWLAST){
|
|
|
|
if(!InsertAtomicIntoBoatSortedList(atomic, DistToCameraSq))
|
2020-12-13 11:53:19 +00:00
|
|
|
RENDERCALLBACK(atomic);
|
2020-05-11 20:21:18 +00:00
|
|
|
}else
|
2020-12-13 11:53:19 +00:00
|
|
|
RENDERCALLBACK(atomic);
|
2020-05-11 20:21:18 +00:00
|
|
|
}
|
|
|
|
return atomic;
|
|
|
|
}
|
|
|
|
|
2019-05-15 14:52:37 +00:00
|
|
|
RpAtomic*
|
|
|
|
CVisibilityPlugins::RenderVehicleLowDetailCB_BigVehicle(RpAtomic *atomic)
|
|
|
|
{
|
|
|
|
RwFrame *clumpframe;
|
2020-05-11 20:21:18 +00:00
|
|
|
float dot;
|
2019-05-15 14:52:37 +00:00
|
|
|
uint32 flags;
|
|
|
|
|
|
|
|
clumpframe = RpClumpGetFrame(RpAtomicGetClump(atomic));
|
2020-05-11 20:21:18 +00:00
|
|
|
if(DistToCameraSq >= ms_bigVehicleLod0Dist &&
|
|
|
|
DistToCameraSq < ms_bigVehicleLod1Dist){
|
2019-05-15 14:52:37 +00:00
|
|
|
flags = GetAtomicId(atomic);
|
2020-05-11 20:21:18 +00:00
|
|
|
if(DistToCameraSq > ms_cullCompsDist && (flags & ATOMIC_FLAG_NOCULL) == 0 && PitchToCamera < 0.2f){
|
2019-05-15 14:52:37 +00:00
|
|
|
dot = GetDotProductWithCameraVector(RwFrameGetLTM(RpAtomicGetFrame(atomic)),
|
|
|
|
RwFrameGetLTM(clumpframe), flags);
|
|
|
|
if(dot > 0.0f)
|
|
|
|
return atomic;
|
|
|
|
}
|
2020-12-13 11:53:19 +00:00
|
|
|
RENDERCALLBACK(atomic);
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
return atomic;
|
|
|
|
}
|
|
|
|
|
|
|
|
RpAtomic*
|
|
|
|
CVisibilityPlugins::RenderVehicleLowDetailAlphaCB_BigVehicle(RpAtomic *atomic)
|
|
|
|
{
|
|
|
|
RwFrame *clumpframe;
|
2020-05-11 20:21:18 +00:00
|
|
|
float dot;
|
2019-05-15 14:52:37 +00:00
|
|
|
uint32 flags;
|
|
|
|
|
|
|
|
clumpframe = RpClumpGetFrame(RpAtomicGetClump(atomic));
|
2020-05-11 20:21:18 +00:00
|
|
|
if(DistToCameraSq >= ms_bigVehicleLod0Dist &&
|
|
|
|
DistToCameraSq < ms_bigVehicleLod1Dist){
|
2019-05-15 14:52:37 +00:00
|
|
|
flags = GetAtomicId(atomic);
|
|
|
|
dot = GetDotProductWithCameraVector(RwFrameGetLTM(RpAtomicGetFrame(atomic)),
|
|
|
|
RwFrameGetLTM(clumpframe), flags);
|
|
|
|
if(dot > 0.0f)
|
2020-05-11 20:21:18 +00:00
|
|
|
if(DistToCameraSq > ms_cullCompsDist && (flags & ATOMIC_FLAG_NOCULL) == 0 && PitchToCamera < 0.2f)
|
2019-05-15 14:52:37 +00:00
|
|
|
return atomic;
|
|
|
|
|
2020-05-11 20:21:18 +00:00
|
|
|
if(!InsertAtomicIntoSortedList(atomic, DistToCameraSq + dot))
|
2020-12-13 11:53:19 +00:00
|
|
|
RENDERCALLBACK(atomic);
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
return atomic;
|
|
|
|
}
|
|
|
|
|
|
|
|
RpAtomic*
|
|
|
|
CVisibilityPlugins::RenderVehicleReallyLowDetailCB(RpAtomic *atomic)
|
|
|
|
{
|
|
|
|
RpClump *clump;
|
|
|
|
int32 alpha;
|
|
|
|
|
|
|
|
clump = RpAtomicGetClump(atomic);
|
2020-05-11 20:21:18 +00:00
|
|
|
if(DistToCameraSq >= ms_vehicleLod0Dist){
|
2019-05-15 14:52:37 +00:00
|
|
|
alpha = GetClumpAlpha(clump);
|
|
|
|
if(alpha == 255)
|
2020-12-13 11:53:19 +00:00
|
|
|
RENDERCALLBACK(atomic);
|
2019-05-15 14:52:37 +00:00
|
|
|
else
|
|
|
|
RenderAlphaAtomic(atomic, alpha);
|
|
|
|
}
|
|
|
|
return atomic;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
RpAtomic*
|
|
|
|
CVisibilityPlugins::RenderVehicleReallyLowDetailCB_BigVehicle(RpAtomic *atomic)
|
|
|
|
{
|
2020-05-11 20:21:18 +00:00
|
|
|
if(DistToCameraSq >= ms_bigVehicleLod1Dist)
|
2020-12-13 11:53:19 +00:00
|
|
|
RENDERCALLBACK(atomic);
|
2019-05-15 14:52:37 +00:00
|
|
|
return atomic;
|
|
|
|
}
|
|
|
|
|
|
|
|
RpAtomic*
|
|
|
|
CVisibilityPlugins::RenderTrainHiDetailCB(RpAtomic *atomic)
|
|
|
|
{
|
|
|
|
RwFrame *clumpframe;
|
2020-05-11 20:21:18 +00:00
|
|
|
float dot;
|
2019-05-15 14:52:37 +00:00
|
|
|
uint32 flags;
|
|
|
|
|
|
|
|
clumpframe = RpClumpGetFrame(RpAtomicGetClump(atomic));
|
2020-05-11 20:21:18 +00:00
|
|
|
if(DistToCameraSq < ms_bigVehicleLod1Dist){
|
2019-05-15 14:52:37 +00:00
|
|
|
flags = GetAtomicId(atomic);
|
2020-05-11 20:21:18 +00:00
|
|
|
if(DistToCameraSq > ms_cullCompsDist && (flags & ATOMIC_FLAG_NOCULL) == 0 && PitchToCamera < 0.2f){
|
2019-05-15 14:52:37 +00:00
|
|
|
dot = GetDotProductWithCameraVector(RwFrameGetLTM(RpAtomicGetFrame(atomic)),
|
|
|
|
RwFrameGetLTM(clumpframe), flags);
|
2020-05-11 20:21:18 +00:00
|
|
|
if(dot > 0.0f && ((flags & ATOMIC_FLAG_ANGLECULL) || 0.1f*DistToCameraSq < dot*dot))
|
2019-05-15 14:52:37 +00:00
|
|
|
return atomic;
|
|
|
|
}
|
2020-12-13 11:53:19 +00:00
|
|
|
RENDERCALLBACK(atomic);
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
return atomic;
|
|
|
|
}
|
|
|
|
|
|
|
|
RpAtomic*
|
|
|
|
CVisibilityPlugins::RenderTrainHiDetailAlphaCB(RpAtomic *atomic)
|
|
|
|
{
|
|
|
|
RwFrame *clumpframe;
|
2020-05-11 20:21:18 +00:00
|
|
|
float dot;
|
2019-05-15 14:52:37 +00:00
|
|
|
uint32 flags;
|
|
|
|
|
|
|
|
clumpframe = RpClumpGetFrame(RpAtomicGetClump(atomic));
|
2020-05-11 20:21:18 +00:00
|
|
|
if(DistToCameraSq < ms_bigVehicleLod1Dist){
|
2019-05-15 14:52:37 +00:00
|
|
|
flags = GetAtomicId(atomic);
|
|
|
|
dot = GetDotProductWithCameraVector(RwFrameGetLTM(RpAtomicGetFrame(atomic)),
|
|
|
|
RwFrameGetLTM(clumpframe), flags);
|
2020-05-11 20:21:18 +00:00
|
|
|
if(DistToCameraSq > ms_cullCompsDist && (flags & ATOMIC_FLAG_NOCULL) == 0 && PitchToCamera < 0.2f)
|
|
|
|
if(dot > 0.0f && ((flags & ATOMIC_FLAG_ANGLECULL) || 0.1f*DistToCameraSq < dot*dot))
|
2019-05-15 14:52:37 +00:00
|
|
|
return atomic;
|
|
|
|
|
|
|
|
if(flags & ATOMIC_FLAG_DRAWLAST){
|
|
|
|
// sort before clump
|
2020-05-11 20:21:18 +00:00
|
|
|
if(!InsertAtomicIntoSortedList(atomic, DistToCameraSq - 0.0001f))
|
2020-12-13 11:53:19 +00:00
|
|
|
RENDERCALLBACK(atomic);
|
2019-05-15 14:52:37 +00:00
|
|
|
}else{
|
2020-05-11 20:21:18 +00:00
|
|
|
if(!InsertAtomicIntoSortedList(atomic, DistToCameraSq + dot))
|
2020-12-13 11:53:19 +00:00
|
|
|
RENDERCALLBACK(atomic);
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return atomic;
|
|
|
|
}
|
|
|
|
|
2020-05-10 15:09:14 +00:00
|
|
|
RpAtomic*
|
|
|
|
CVisibilityPlugins::RenderVehicleRotorAlphaCB(RpAtomic *atomic)
|
|
|
|
{
|
2020-05-11 20:21:18 +00:00
|
|
|
RwFrame *clumpframe;
|
|
|
|
float dot;
|
|
|
|
RwV3d cam2atm;
|
|
|
|
|
|
|
|
clumpframe = RpClumpGetFrame(RpAtomicGetClump(atomic));
|
|
|
|
if(DistToCameraSq < ms_bigVehicleLod1Dist){
|
|
|
|
RwV3dSub(&cam2atm, &RwFrameGetLTM(RpAtomicGetFrame(atomic))->pos, ms_pCameraPosn);
|
|
|
|
dot = RwV3dDotProduct(&cam2atm, &RwFrameGetLTM(clumpframe)->at);
|
|
|
|
if(!InsertAtomicIntoSortedList(atomic, DistToCameraSq + dot*20.0f))
|
2020-12-13 11:53:19 +00:00
|
|
|
RENDERCALLBACK(atomic);
|
2020-05-11 20:21:18 +00:00
|
|
|
}
|
|
|
|
return atomic;
|
2020-05-10 15:09:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RpAtomic*
|
|
|
|
CVisibilityPlugins::RenderVehicleTailRotorAlphaCB(RpAtomic *atomic)
|
|
|
|
{
|
2020-05-11 20:21:18 +00:00
|
|
|
RwMatrix *clumpMat, *atmMat;
|
|
|
|
float dot;
|
|
|
|
RwV3d cam2atm;
|
|
|
|
|
|
|
|
if(DistToCameraSq < ms_bigVehicleLod0Dist){
|
|
|
|
atmMat = RwFrameGetLTM(RpAtomicGetFrame(atomic));
|
|
|
|
clumpMat = RwFrameGetLTM(RpClumpGetFrame(RpAtomicGetClump(atomic)));
|
|
|
|
RwV3dSub(&cam2atm, &atmMat->pos, ms_pCameraPosn);
|
|
|
|
dot = RwV3dDotProduct(&cam2atm, &clumpMat->up) + RwV3dDotProduct(&cam2atm, &clumpMat->right);
|
|
|
|
if(!InsertAtomicIntoSortedList(atomic, DistToCameraSq - dot))
|
2020-12-13 11:53:19 +00:00
|
|
|
RENDERCALLBACK(atomic);
|
2020-05-11 20:21:18 +00:00
|
|
|
}
|
|
|
|
return atomic;
|
2020-05-10 15:09:14 +00:00
|
|
|
}
|
|
|
|
|
2019-05-15 14:52:37 +00:00
|
|
|
RpAtomic*
|
|
|
|
CVisibilityPlugins::RenderPlayerCB(RpAtomic *atomic)
|
|
|
|
{
|
2019-10-26 11:12:24 +00:00
|
|
|
if(CWorld::Players[0].m_pSkinTexture)
|
|
|
|
RpGeometryForAllMaterials(RpAtomicGetGeometry(atomic), SetTextureCB, CWorld::Players[0].m_pSkinTexture);
|
2020-12-13 11:53:19 +00:00
|
|
|
RENDERCALLBACK(atomic);
|
2019-05-15 14:52:37 +00:00
|
|
|
return atomic;
|
|
|
|
}
|
|
|
|
|
|
|
|
RpAtomic*
|
2020-05-11 20:21:18 +00:00
|
|
|
CVisibilityPlugins::RenderPedCB(RpAtomic *atomic)
|
2019-05-15 14:52:37 +00:00
|
|
|
{
|
|
|
|
int32 alpha;
|
2020-05-11 20:21:18 +00:00
|
|
|
RwV3d cam2atm;
|
2019-05-15 14:52:37 +00:00
|
|
|
|
2020-05-11 20:21:18 +00:00
|
|
|
RwV3dSub(&cam2atm, &RwFrameGetLTM(RpAtomicGetFrame(atomic))->pos, ms_pCameraPosn);
|
|
|
|
if(RwV3dDotProduct(&cam2atm, &cam2atm) < ms_pedLod1Dist){
|
|
|
|
alpha = GetClumpAlpha(RpAtomicGetClump(atomic));
|
2019-05-15 14:52:37 +00:00
|
|
|
if(alpha == 255)
|
2020-12-13 11:53:19 +00:00
|
|
|
RENDERCALLBACK(atomic);
|
2019-05-15 14:52:37 +00:00
|
|
|
else
|
|
|
|
RenderAlphaAtomic(atomic, alpha);
|
|
|
|
}
|
|
|
|
return atomic;
|
|
|
|
}
|
|
|
|
|
2020-07-01 16:03:39 +00:00
|
|
|
float
|
|
|
|
CVisibilityPlugins::GetDistanceSquaredFromCamera(RwV3d *pos)
|
|
|
|
{
|
|
|
|
RwV3d dist;
|
|
|
|
RwV3dSub(&dist, pos, ms_pCameraPosn);
|
|
|
|
return RwV3dDotProduct(&dist, &dist);
|
|
|
|
}
|
|
|
|
|
2019-05-15 14:52:37 +00:00
|
|
|
float
|
|
|
|
CVisibilityPlugins::GetDistanceSquaredFromCamera(RwFrame *frame)
|
|
|
|
{
|
|
|
|
RwMatrix *m;
|
|
|
|
RwV3d dist;
|
|
|
|
m = RwFrameGetLTM(frame);
|
|
|
|
RwV3dSub(&dist, RwMatrixGetPos(m), ms_pCameraPosn);
|
|
|
|
return RwV3dDotProduct(&dist, &dist);
|
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
CVisibilityPlugins::GetDotProductWithCameraVector(RwMatrix *atomicMat, RwMatrix *clumpMat, uint32 flags)
|
|
|
|
{
|
|
|
|
RwV3d dist;
|
|
|
|
float dot, dotdoor;
|
|
|
|
|
|
|
|
// Vehicle forward is the y axis (RwMatrix.up)
|
|
|
|
// Vehicle right is the x axis (RwMatrix.right)
|
|
|
|
|
|
|
|
RwV3dSub(&dist, RwMatrixGetPos(atomicMat), ms_pCameraPosn);
|
|
|
|
// forward/backward facing
|
|
|
|
if(flags & (ATOMIC_FLAG_FRONT | ATOMIC_FLAG_REAR))
|
|
|
|
dot = RwV3dDotProduct(&dist, RwMatrixGetUp(clumpMat));
|
|
|
|
// left/right facing
|
2019-06-19 22:36:11 +00:00
|
|
|
else if(flags & (ATOMIC_FLAG_LEFT | ATOMIC_FLAG_RIGHT))
|
2019-05-15 14:52:37 +00:00
|
|
|
dot = RwV3dDotProduct(&dist, RwMatrixGetRight(clumpMat));
|
|
|
|
else
|
|
|
|
dot = 0.0f;
|
|
|
|
if(flags & (ATOMIC_FLAG_LEFT | ATOMIC_FLAG_REAR))
|
|
|
|
dot = -dot;
|
|
|
|
|
|
|
|
if(flags & (ATOMIC_FLAG_REARDOOR | ATOMIC_FLAG_FRONTDOOR)){
|
|
|
|
if(flags & ATOMIC_FLAG_REARDOOR)
|
|
|
|
dotdoor = -RwV3dDotProduct(&dist, RwMatrixGetUp(clumpMat));
|
|
|
|
else if(flags & ATOMIC_FLAG_FRONTDOOR)
|
|
|
|
dotdoor = RwV3dDotProduct(&dist, RwMatrixGetUp(clumpMat));
|
|
|
|
else
|
|
|
|
dotdoor = 0.0f;
|
|
|
|
|
|
|
|
if(dot < 0.0f && dotdoor < 0.0f)
|
|
|
|
dot += dotdoor;
|
|
|
|
if(dot > 0.0f && dotdoor > 0.0f)
|
|
|
|
dot += dotdoor;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dot;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* These are all unused */
|
|
|
|
|
|
|
|
bool
|
|
|
|
CVisibilityPlugins::DefaultVisibilityCB(RpClump *clump)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CVisibilityPlugins::FrustumSphereCB(RpClump *clump)
|
|
|
|
{
|
2019-10-26 11:12:24 +00:00
|
|
|
RwSphere sphere;
|
|
|
|
RwFrame *frame = RpClumpGetFrame(clump);
|
|
|
|
|
|
|
|
CClumpModelInfo *modelInfo = (CClumpModelInfo*)GetFrameHierarchyId(frame);
|
|
|
|
sphere.radius = modelInfo->GetColModel()->boundingSphere.radius;
|
|
|
|
sphere.center.x = modelInfo->GetColModel()->boundingSphere.center.x;
|
|
|
|
sphere.center.y = modelInfo->GetColModel()->boundingSphere.center.y;
|
|
|
|
sphere.center.z = modelInfo->GetColModel()->boundingSphere.center.z;
|
|
|
|
RwV3dTransformPoints(&sphere.center, &sphere.center, 1, RwFrameGetLTM(frame));
|
|
|
|
return RwCameraFrustumTestSphere(ms_pCamera, &sphere) != rwSPHEREOUTSIDE;
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CVisibilityPlugins::VehicleVisibilityCB(RpClump *clump)
|
|
|
|
{
|
2019-10-26 11:12:24 +00:00
|
|
|
if (GetDistanceSquaredFromCamera(RpClumpGetFrame(clump)) <= ms_vehicleLod1Dist)
|
|
|
|
return FrustumSphereCB(clump);
|
|
|
|
return false;
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CVisibilityPlugins::VehicleVisibilityCB_BigVehicle(RpClump *clump)
|
|
|
|
{
|
2019-10-26 11:12:24 +00:00
|
|
|
return FrustumSphereCB(clump);
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// RW Plugins
|
|
|
|
//
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ID_VISIBILITYATOMIC = MAKECHUNKID(rwVENDORID_ROCKSTAR, 0x00),
|
|
|
|
ID_VISIBILITYCLUMP = MAKECHUNKID(rwVENDORID_ROCKSTAR, 0x01),
|
|
|
|
ID_VISIBILITYFRAME = MAKECHUNKID(rwVENDORID_ROCKSTAR, 0x02),
|
|
|
|
};
|
|
|
|
|
|
|
|
bool
|
|
|
|
CVisibilityPlugins::PluginAttach(void)
|
|
|
|
{
|
|
|
|
ms_atomicPluginOffset = RpAtomicRegisterPlugin(sizeof(AtomicExt),
|
|
|
|
ID_VISIBILITYATOMIC,
|
|
|
|
AtomicConstructor, AtomicDestructor, AtomicCopyConstructor);
|
|
|
|
|
|
|
|
ms_framePluginOffset = RwFrameRegisterPlugin(sizeof(FrameExt),
|
|
|
|
ID_VISIBILITYFRAME,
|
|
|
|
FrameConstructor, FrameDestructor, FrameCopyConstructor);
|
|
|
|
|
|
|
|
ms_clumpPluginOffset = RpClumpRegisterPlugin(sizeof(ClumpExt),
|
|
|
|
ID_VISIBILITYCLUMP,
|
|
|
|
ClumpConstructor, ClumpDestructor, ClumpCopyConstructor);
|
|
|
|
return ms_atomicPluginOffset != -1 && ms_clumpPluginOffset != -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ATOMICEXT(o) (RWPLUGINOFFSET(AtomicExt, o, ms_atomicPluginOffset))
|
|
|
|
#define FRAMEEXT(o) (RWPLUGINOFFSET(FrameExt, o, ms_framePluginOffset))
|
|
|
|
#define CLUMPEXT(o) (RWPLUGINOFFSET(ClumpExt, o, ms_clumpPluginOffset))
|
|
|
|
|
|
|
|
//
|
|
|
|
// Atomic
|
|
|
|
//
|
|
|
|
|
|
|
|
void*
|
|
|
|
CVisibilityPlugins::AtomicConstructor(void *object, int32, int32)
|
|
|
|
{
|
|
|
|
ATOMICEXT(object)->modelInfo = nil;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
|
|
|
CVisibilityPlugins::AtomicDestructor(void *object, int32, int32)
|
|
|
|
{
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
|
|
|
CVisibilityPlugins::AtomicCopyConstructor(void *dst, const void *src, int32, int32)
|
|
|
|
{
|
|
|
|
*ATOMICEXT(dst) = *ATOMICEXT(src);
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CVisibilityPlugins::SetAtomicModelInfo(RpAtomic *atomic,
|
|
|
|
CSimpleModelInfo *modelInfo)
|
|
|
|
{
|
|
|
|
AtomicExt *ext = ATOMICEXT(atomic);
|
|
|
|
ext->modelInfo = modelInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSimpleModelInfo*
|
|
|
|
CVisibilityPlugins::GetAtomicModelInfo(RpAtomic *atomic)
|
|
|
|
{
|
|
|
|
return ATOMICEXT(atomic)->modelInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CVisibilityPlugins::SetAtomicFlag(RpAtomic *atomic, int f)
|
|
|
|
{
|
|
|
|
ATOMICEXT(atomic)->flags |= f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CVisibilityPlugins::ClearAtomicFlag(RpAtomic *atomic, int f)
|
|
|
|
{
|
|
|
|
ATOMICEXT(atomic)->flags &= ~f;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
CVisibilityPlugins::GetAtomicId(RpAtomic *atomic)
|
|
|
|
{
|
|
|
|
return ATOMICEXT(atomic)->flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CVisibilityPlugins::SetAtomicRenderCallback(RpAtomic *atomic, RpAtomicCallBackRender cb)
|
|
|
|
{
|
|
|
|
if(cb == nil)
|
2020-12-13 11:53:19 +00:00
|
|
|
cb = RENDERCALLBACK; // not necessary
|
2019-05-15 14:52:37 +00:00
|
|
|
RpAtomicSetRenderCallBack(atomic, cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Frame
|
|
|
|
//
|
|
|
|
|
|
|
|
void*
|
|
|
|
CVisibilityPlugins::FrameConstructor(void *object, int32, int32)
|
|
|
|
{
|
|
|
|
FRAMEEXT(object)->id = 0;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
|
|
|
CVisibilityPlugins::FrameDestructor(void *object, int32, int32)
|
|
|
|
{
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
|
|
|
CVisibilityPlugins::FrameCopyConstructor(void *dst, const void *src, int32, int32)
|
|
|
|
{
|
|
|
|
*FRAMEEXT(dst) = *FRAMEEXT(src);
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-07-22 11:56:28 +00:00
|
|
|
CVisibilityPlugins::SetFrameHierarchyId(RwFrame *frame, uintptr id)
|
2019-05-15 14:52:37 +00:00
|
|
|
{
|
|
|
|
FRAMEEXT(frame)->id = id;
|
|
|
|
}
|
|
|
|
|
2020-07-22 11:56:28 +00:00
|
|
|
uintptr
|
2019-05-15 14:52:37 +00:00
|
|
|
CVisibilityPlugins::GetFrameHierarchyId(RwFrame *frame)
|
|
|
|
{
|
|
|
|
return FRAMEEXT(frame)->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Clump
|
|
|
|
//
|
|
|
|
|
|
|
|
void*
|
|
|
|
CVisibilityPlugins::ClumpConstructor(void *object, int32, int32)
|
|
|
|
{
|
|
|
|
ClumpExt *ext = CLUMPEXT(object);
|
|
|
|
ext->visibilityCB = DefaultVisibilityCB;
|
|
|
|
ext->alpha = 0xFF;
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
|
|
|
CVisibilityPlugins::ClumpDestructor(void *object, int32, int32)
|
|
|
|
{
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
|
|
|
CVisibilityPlugins::ClumpCopyConstructor(void *dst, const void *src, int32, int32)
|
|
|
|
{
|
|
|
|
CLUMPEXT(dst)->visibilityCB = CLUMPEXT(src)->visibilityCB;
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CVisibilityPlugins::SetClumpModelInfo(RpClump *clump, CClumpModelInfo *modelInfo)
|
|
|
|
{
|
|
|
|
CVehicleModelInfo *vmi;
|
2020-05-11 02:55:57 +00:00
|
|
|
SetFrameHierarchyId(RpClumpGetFrame(clump), (uintptr)modelInfo);
|
2019-05-15 14:52:37 +00:00
|
|
|
|
|
|
|
// Unused
|
2020-05-05 12:06:55 +00:00
|
|
|
switch (modelInfo->GetModelType()) {
|
2019-05-15 14:52:37 +00:00
|
|
|
// ignore MLO
|
|
|
|
case MITYPE_VEHICLE:
|
|
|
|
vmi = (CVehicleModelInfo*)modelInfo;
|
2020-05-11 02:55:57 +00:00
|
|
|
if(vmi->m_vehicleType == VEHICLE_TYPE_TRAIN ||
|
|
|
|
vmi->m_vehicleType == VEHICLE_TYPE_HELI ||
|
2019-05-15 14:52:37 +00:00
|
|
|
vmi->m_vehicleType == VEHICLE_TYPE_PLANE)
|
|
|
|
CLUMPEXT(clump)->visibilityCB = VehicleVisibilityCB_BigVehicle;
|
|
|
|
else
|
|
|
|
CLUMPEXT(clump)->visibilityCB = VehicleVisibilityCB;
|
|
|
|
break;
|
2020-05-11 23:24:57 +00:00
|
|
|
default: break;
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CVisibilityPlugins::SetClumpAlpha(RpClump *clump, int alpha)
|
|
|
|
{
|
|
|
|
CLUMPEXT(clump)->alpha = alpha;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
CVisibilityPlugins::GetClumpAlpha(RpClump *clump)
|
|
|
|
{
|
|
|
|
return CLUMPEXT(clump)->alpha;
|
|
|
|
}
|