mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-14 15:46:17 +00:00
Mass code cleanup
This commit is contained in:
@@ -15,11 +15,11 @@ ENodeType CCollisionNode::NodeType()
|
||||
return eCollisionNode;
|
||||
}
|
||||
|
||||
void CCollisionNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
|
||||
void CCollisionNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo)
|
||||
{
|
||||
if (!mpCollision) return;
|
||||
if (!ViewInfo.ViewFrustum.BoxInFrustum(AABox())) return;
|
||||
if (ViewInfo.GameMode) return;
|
||||
if (!rkViewInfo.ViewFrustum.BoxInFrustum(AABox())) return;
|
||||
if (rkViewInfo.GameMode) return;
|
||||
|
||||
pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawMesh);
|
||||
|
||||
@@ -27,7 +27,7 @@ void CCollisionNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewIn
|
||||
pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawSelection);
|
||||
}
|
||||
|
||||
void CCollisionNode::Draw(FRenderOptions /*Options*/, int /*ComponentIndex*/, const SViewInfo& ViewInfo)
|
||||
void CCollisionNode::Draw(FRenderOptions /*Options*/, int /*ComponentIndex*/, const SViewInfo& rkViewInfo)
|
||||
{
|
||||
if (!mpCollision) return;
|
||||
|
||||
@@ -37,13 +37,13 @@ void CCollisionNode::Draw(FRenderOptions /*Options*/, int /*ComponentIndex*/, co
|
||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
glDepthMask(GL_TRUE);
|
||||
|
||||
CDrawUtil::UseCollisionShader(TintColor(ViewInfo));
|
||||
CDrawUtil::UseCollisionShader(TintColor(rkViewInfo));
|
||||
mpCollision->Draw();
|
||||
CDrawUtil::UseColorShader(CColor::skTransparentBlack);
|
||||
mpCollision->DrawWireframe();
|
||||
}
|
||||
|
||||
SRayIntersection CCollisionNode::RayNodeIntersectTest(const CRay& /*Ray*/, u32 /*AssetID*/, const SViewInfo& /*ViewInfo*/)
|
||||
SRayIntersection CCollisionNode::RayNodeIntersectTest(const CRay& /*rkRay*/, u32 /*AssetID*/, const SViewInfo& /*rkViewInfo*/)
|
||||
{
|
||||
// todo
|
||||
SRayIntersection Result;
|
||||
|
||||
@@ -11,9 +11,9 @@ class CCollisionNode : public CSceneNode
|
||||
public:
|
||||
CCollisionNode(CScene *pScene, u32 NodeID, CSceneNode *pParent = 0, CCollisionMeshGroup *pCollision = 0);
|
||||
ENodeType NodeType();
|
||||
void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo);
|
||||
void Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo);
|
||||
SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo);
|
||||
void AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo);
|
||||
void Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& rkViewInfo);
|
||||
SRayIntersection RayNodeIntersectTest(const CRay& rkRay, u32 AssetID, const SViewInfo& rkViewInfo);
|
||||
void SetCollision(CCollisionMeshGroup *pCollision);
|
||||
};
|
||||
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
#include "Core/Render/CRenderer.h"
|
||||
#include <Math/MathUtil.h>
|
||||
|
||||
CLightNode::CLightNode(CScene *pScene, u32 NodeID, CSceneNode *pParent, CLight *Light)
|
||||
CLightNode::CLightNode(CScene *pScene, u32 NodeID, CSceneNode *pParent, CLight *pLight)
|
||||
: CSceneNode(pScene, NodeID, pParent)
|
||||
, mpLight(pLight)
|
||||
{
|
||||
mpLight = Light;
|
||||
mLocalAABox = CAABox::skOne;
|
||||
mPosition = Light->GetPosition();
|
||||
mPosition = pLight->Position();
|
||||
|
||||
switch (Light->GetType())
|
||||
switch (pLight->Type())
|
||||
{
|
||||
case eLocalAmbient: SetName("Ambient Light"); break;
|
||||
case eDirectional: SetName("Directional Light"); break;
|
||||
@@ -25,104 +25,104 @@ ENodeType CLightNode::NodeType()
|
||||
return eLightNode;
|
||||
}
|
||||
|
||||
void CLightNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
|
||||
void CLightNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo)
|
||||
{
|
||||
if (ViewInfo.GameMode) return;
|
||||
if (rkViewInfo.GameMode) return;
|
||||
|
||||
if (ViewInfo.ViewFrustum.BoxInFrustum(AABox()))
|
||||
if (rkViewInfo.ViewFrustum.BoxInFrustum(AABox()))
|
||||
pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawMesh);
|
||||
|
||||
if (IsSelected() && mpLight->GetType() == eCustom)
|
||||
if (IsSelected() && mpLight->Type() == eCustom)
|
||||
{
|
||||
CAABox RadiusBox = (CAABox::skOne * 2.f * mpLight->GetRadius()) + mPosition;
|
||||
|
||||
if (ViewInfo.ViewFrustum.BoxInFrustum(RadiusBox))
|
||||
if (rkViewInfo.ViewFrustum.BoxInFrustum(RadiusBox))
|
||||
pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawSelection);
|
||||
}
|
||||
}
|
||||
|
||||
void CLightNode::Draw(FRenderOptions /*Options*/, int /*ComponentIndex*/, const SViewInfo& ViewInfo)
|
||||
void CLightNode::Draw(FRenderOptions /*Options*/, int /*ComponentIndex*/, const SViewInfo& rkViewInfo)
|
||||
{
|
||||
CDrawUtil::DrawLightBillboard(mpLight->GetType(), mpLight->GetColor(), mPosition, BillboardScale(), TintColor(ViewInfo));
|
||||
CDrawUtil::DrawLightBillboard(mpLight->Type(), mpLight->Color(), mPosition, BillboardScale(), TintColor(rkViewInfo));
|
||||
}
|
||||
|
||||
void CLightNode::DrawSelection()
|
||||
{
|
||||
CDrawUtil::DrawWireSphere(mPosition, mpLight->GetRadius(), mpLight->GetColor());
|
||||
CDrawUtil::DrawWireSphere(mPosition, mpLight->GetRadius(), mpLight->Color());
|
||||
}
|
||||
|
||||
void CLightNode::RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& /*ViewInfo*/)
|
||||
void CLightNode::RayAABoxIntersectTest(CRayCollisionTester& rTester, const SViewInfo& /*ViewInfo*/)
|
||||
{
|
||||
CVector2f BillScale = BillboardScale();
|
||||
float ScaleXY = (BillScale.x > BillScale.y ? BillScale.x : BillScale.y);
|
||||
float ScaleXY = (BillScale.X > BillScale.Y ? BillScale.X : BillScale.Y);
|
||||
|
||||
CAABox BillBox = CAABox(mPosition + CVector3f(-ScaleXY, -ScaleXY, -BillScale.y),
|
||||
mPosition + CVector3f( ScaleXY, ScaleXY, BillScale.y));
|
||||
CAABox BillBox = CAABox(mPosition + CVector3f(-ScaleXY, -ScaleXY, -BillScale.Y),
|
||||
mPosition + CVector3f( ScaleXY, ScaleXY, BillScale.Y));
|
||||
|
||||
std::pair<bool,float> BoxResult = BillBox.IntersectsRay(Tester.Ray());
|
||||
if (BoxResult.first) Tester.AddNode(this, 0, BoxResult.second);
|
||||
std::pair<bool,float> BoxResult = BillBox.IntersectsRay(rTester.Ray());
|
||||
if (BoxResult.first) rTester.AddNode(this, 0, BoxResult.second);
|
||||
}
|
||||
|
||||
SRayIntersection CLightNode::RayNodeIntersectTest(const CRay& Ray, u32 AssetID, const SViewInfo& ViewInfo)
|
||||
SRayIntersection CLightNode::RayNodeIntersectTest(const CRay& rkRay, u32 AssetID, const SViewInfo& rkViewInfo)
|
||||
{
|
||||
// todo: come up with a better way to share this code between CScriptNode and CLightNode
|
||||
SRayIntersection out;
|
||||
out.pNode = this;
|
||||
out.ComponentIndex = AssetID;
|
||||
SRayIntersection Out;
|
||||
Out.pNode = this;
|
||||
Out.ComponentIndex = AssetID;
|
||||
|
||||
CTexture *pBillboard = CDrawUtil::GetLightTexture(mpLight->GetType());
|
||||
CTexture *pBillboard = CDrawUtil::GetLightTexture(mpLight->Type());
|
||||
|
||||
if (!pBillboard)
|
||||
{
|
||||
out.Hit = false;
|
||||
return out;
|
||||
Out.Hit = false;
|
||||
return Out;
|
||||
}
|
||||
|
||||
// Step 1: check whether the ray intersects with the plane the billboard is on
|
||||
CPlane BillboardPlane(-ViewInfo.pCamera->Direction(), mPosition);
|
||||
std::pair<bool,float> PlaneTest = Math::RayPlaneIntersecton(Ray, BillboardPlane);
|
||||
CPlane BillboardPlane(-rkViewInfo.pCamera->Direction(), mPosition);
|
||||
std::pair<bool,float> PlaneTest = Math::RayPlaneIntersecton(rkRay, BillboardPlane);
|
||||
|
||||
if (PlaneTest.first)
|
||||
{
|
||||
// Step 2: transform the hit point into the plane's local space
|
||||
CVector3f PlaneHitPoint = Ray.PointOnRay(PlaneTest.second);
|
||||
CVector3f PlaneHitPoint = rkRay.PointOnRay(PlaneTest.second);
|
||||
CVector3f RelHitPoint = PlaneHitPoint - mPosition;
|
||||
|
||||
CVector3f PlaneForward = -ViewInfo.pCamera->Direction();
|
||||
CVector3f PlaneRight = -ViewInfo.pCamera->RightVector();
|
||||
CVector3f PlaneUp = ViewInfo.pCamera->UpVector();
|
||||
CVector3f PlaneForward = -rkViewInfo.pCamera->Direction();
|
||||
CVector3f PlaneRight = -rkViewInfo.pCamera->RightVector();
|
||||
CVector3f PlaneUp = rkViewInfo.pCamera->UpVector();
|
||||
CQuaternion PlaneRot = CQuaternion::FromAxes(PlaneRight, PlaneForward, PlaneUp);
|
||||
|
||||
CVector3f RotatedHitPoint = PlaneRot.Inverse() * RelHitPoint;
|
||||
CVector2f LocalHitPoint = RotatedHitPoint.xz() / BillboardScale();
|
||||
CVector2f LocalHitPoint = RotatedHitPoint.XZ() / BillboardScale();
|
||||
|
||||
// Step 3: check whether the transformed hit point is in the -1 to 1 range
|
||||
if ((LocalHitPoint.x >= -1.f) && (LocalHitPoint.x <= 1.f) && (LocalHitPoint.y >= -1.f) && (LocalHitPoint.y <= 1.f))
|
||||
if ((LocalHitPoint.X >= -1.f) && (LocalHitPoint.X <= 1.f) && (LocalHitPoint.Y >= -1.f) && (LocalHitPoint.Y <= 1.f))
|
||||
{
|
||||
// Step 4: look up the hit texel and check whether it's transparent or opaque
|
||||
CVector2f TexCoord = (LocalHitPoint + CVector2f(1.f)) * 0.5f;
|
||||
TexCoord.x = -TexCoord.x + 1.f;
|
||||
TexCoord.X = -TexCoord.X + 1.f;
|
||||
float TexelAlpha = pBillboard->ReadTexelAlpha(TexCoord);
|
||||
|
||||
if (TexelAlpha < 0.25f)
|
||||
out.Hit = false;
|
||||
Out.Hit = false;
|
||||
|
||||
else
|
||||
{
|
||||
// It's opaque... we have a hit!
|
||||
out.Hit = true;
|
||||
out.Distance = PlaneTest.second;
|
||||
Out.Hit = true;
|
||||
Out.Distance = PlaneTest.second;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
out.Hit = false;
|
||||
Out.Hit = false;
|
||||
}
|
||||
|
||||
else
|
||||
out.Hit = false;
|
||||
Out.Hit = false;
|
||||
|
||||
return out;
|
||||
return Out;
|
||||
}
|
||||
|
||||
CLight* CLightNode::Light()
|
||||
@@ -132,7 +132,7 @@ CLight* CLightNode::Light()
|
||||
|
||||
CVector2f CLightNode::BillboardScale()
|
||||
{
|
||||
return AbsoluteScale().xz() * 0.75f;
|
||||
return AbsoluteScale().XZ() * 0.75f;
|
||||
}
|
||||
|
||||
void CLightNode::CalculateTransform(CTransform4f& rOut) const
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
|
||||
CModelNode::CModelNode(CScene *pScene, u32 NodeID, CSceneNode *pParent, CModel *pModel)
|
||||
: CSceneNode(pScene, NodeID, pParent)
|
||||
, mWorldModel(false)
|
||||
, mForceAlphaOn(false)
|
||||
, mEnableScanOverlay(false)
|
||||
, mTintColor(CColor::skWhite)
|
||||
{
|
||||
mScale = CVector3f::skOne;
|
||||
SetModel(pModel);
|
||||
mScale = CVector3f(1.f);
|
||||
mWorldModel = false;
|
||||
mForceAlphaOn = false;
|
||||
mEnableScanOverlay = false;
|
||||
mTintColor = CColor::skWhite;
|
||||
}
|
||||
|
||||
ENodeType CModelNode::NodeType()
|
||||
@@ -29,22 +29,22 @@ void CModelNode::PostLoad()
|
||||
}
|
||||
}
|
||||
|
||||
void CModelNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
|
||||
void CModelNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo)
|
||||
{
|
||||
if (!mpModel) return;
|
||||
if (!ViewInfo.ViewFrustum.BoxInFrustum(AABox())) return;
|
||||
if (ViewInfo.GameMode) return;
|
||||
if (!rkViewInfo.ViewFrustum.BoxInFrustum(AABox())) return;
|
||||
if (rkViewInfo.GameMode) return;
|
||||
|
||||
if (!mpModel->HasTransparency(mActiveMatSet))
|
||||
pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawMesh);
|
||||
else
|
||||
AddSurfacesToRenderer(pRenderer, mpModel, mActiveMatSet, ViewInfo);
|
||||
AddSurfacesToRenderer(pRenderer, mpModel, mActiveMatSet, rkViewInfo);
|
||||
|
||||
if (mSelected)
|
||||
pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawSelection);
|
||||
}
|
||||
|
||||
void CModelNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo)
|
||||
void CModelNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& rkViewInfo)
|
||||
{
|
||||
if (!mpModel) return;
|
||||
if (mForceAlphaOn) Options = (FRenderOptions) (Options & ~eNoAlpha);
|
||||
@@ -59,7 +59,7 @@ void CModelNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewInf
|
||||
}
|
||||
else
|
||||
{
|
||||
bool IsLightingEnabled = CGraphics::sLightMode == CGraphics::eWorldLighting || ViewInfo.GameMode;
|
||||
bool IsLightingEnabled = CGraphics::sLightMode == CGraphics::eWorldLighting || rkViewInfo.GameMode;
|
||||
|
||||
if (IsLightingEnabled)
|
||||
{
|
||||
@@ -71,7 +71,7 @@ void CModelNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewInf
|
||||
|
||||
else
|
||||
{
|
||||
LoadLights(ViewInfo);
|
||||
LoadLights(rkViewInfo);
|
||||
if (CGraphics::sLightMode == CGraphics::eNoLighting)
|
||||
CGraphics::sVertexBlock.COLOR0_Amb = CColor::skWhite;
|
||||
}
|
||||
@@ -80,7 +80,7 @@ void CModelNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewInf
|
||||
CGraphics::sPixelBlock.TevColor = CColor(Mul,Mul,Mul);
|
||||
}
|
||||
|
||||
CGraphics::sPixelBlock.TintColor = TintColor(ViewInfo);
|
||||
CGraphics::sPixelBlock.TintColor = TintColor(rkViewInfo);
|
||||
LoadModelMatrix();
|
||||
|
||||
if (ComponentIndex < 0)
|
||||
@@ -108,40 +108,40 @@ void CModelNode::DrawSelection()
|
||||
mpModel->DrawWireframe(eNoRenderOptions, WireframeColor());
|
||||
}
|
||||
|
||||
void CModelNode::RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& /*ViewInfo*/)
|
||||
void CModelNode::RayAABoxIntersectTest(CRayCollisionTester& rTester, const SViewInfo& /*rkViewInfo*/)
|
||||
{
|
||||
if (!mpModel) return;
|
||||
|
||||
const CRay& Ray = Tester.Ray();
|
||||
std::pair<bool,float> BoxResult = AABox().IntersectsRay(Ray);
|
||||
const CRay& rkRay = rTester.Ray();
|
||||
std::pair<bool,float> BoxResult = AABox().IntersectsRay(rkRay);
|
||||
|
||||
if (BoxResult.first)
|
||||
Tester.AddNodeModel(this, mpModel);
|
||||
rTester.AddNodeModel(this, mpModel);
|
||||
}
|
||||
|
||||
SRayIntersection CModelNode::RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo)
|
||||
SRayIntersection CModelNode::RayNodeIntersectTest(const CRay& rkRay, u32 AssetID, const SViewInfo& rkViewInfo)
|
||||
{
|
||||
SRayIntersection out;
|
||||
out.pNode = this;
|
||||
out.ComponentIndex = AssetID;
|
||||
SRayIntersection Out;
|
||||
Out.pNode = this;
|
||||
Out.ComponentIndex = AssetID;
|
||||
|
||||
CRay TransformedRay = Ray.Transformed(Transform().Inverse());
|
||||
FRenderOptions options = ViewInfo.pRenderer->RenderOptions();
|
||||
std::pair<bool,float> Result = mpModel->GetSurface(AssetID)->IntersectsRay(TransformedRay, ((options & eEnableBackfaceCull) == 0));
|
||||
CRay TransformedRay = rkRay.Transformed(Transform().Inverse());
|
||||
FRenderOptions Options = rkViewInfo.pRenderer->RenderOptions();
|
||||
std::pair<bool,float> Result = mpModel->GetSurface(AssetID)->IntersectsRay(TransformedRay, ((Options & eEnableBackfaceCull) == 0));
|
||||
|
||||
if (Result.first)
|
||||
{
|
||||
out.Hit = true;
|
||||
Out.Hit = true;
|
||||
|
||||
CVector3f HitPoint = TransformedRay.PointOnRay(Result.second);
|
||||
CVector3f WorldHitPoint = Transform() * HitPoint;
|
||||
out.Distance = Math::Distance(Ray.Origin(), WorldHitPoint);
|
||||
Out.Distance = Math::Distance(rkRay.Origin(), WorldHitPoint);
|
||||
}
|
||||
|
||||
else
|
||||
out.Hit = false;
|
||||
Out.Hit = false;
|
||||
|
||||
return out;
|
||||
return Out;
|
||||
}
|
||||
|
||||
CColor CModelNode::TintColor(const SViewInfo& /*rkViewInfo*/) const
|
||||
|
||||
@@ -19,11 +19,11 @@ public:
|
||||
|
||||
virtual ENodeType NodeType();
|
||||
virtual void PostLoad();
|
||||
virtual void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo);
|
||||
virtual void Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo);
|
||||
virtual void AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo);
|
||||
virtual void Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& rkViewInfo);
|
||||
virtual void DrawSelection();
|
||||
virtual void RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo);
|
||||
virtual SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo);
|
||||
virtual void RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& rkViewInfo);
|
||||
virtual SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& rkViewInfo);
|
||||
virtual CColor TintColor(const SViewInfo& rkViewInfo) const;
|
||||
|
||||
// Setters
|
||||
|
||||
@@ -12,13 +12,15 @@ public:
|
||||
: CSceneNode(pScene, NodeID, pParent) {}
|
||||
~CRootNode() {}
|
||||
|
||||
ENodeType NodeType() {
|
||||
ENodeType NodeType()
|
||||
{
|
||||
return eRootNode;
|
||||
}
|
||||
|
||||
inline void RayAABoxIntersectTest(CRayCollisionTester&, const SViewInfo&) {}
|
||||
|
||||
inline SRayIntersection RayNodeIntersectTest(const CRay &, u32, const SViewInfo&) {
|
||||
inline SRayIntersection RayNodeIntersectTest(const CRay &, u32, const SViewInfo&)
|
||||
{
|
||||
return SRayIntersection();
|
||||
}
|
||||
|
||||
|
||||
@@ -147,17 +147,17 @@ void CScene::DeleteNode(CSceneNode *pNode)
|
||||
{
|
||||
CScriptNode *pScript = static_cast<CScriptNode*>(pNode);
|
||||
|
||||
auto it = mScriptMap.find(pScript->Object()->InstanceID());
|
||||
auto it = mScriptMap.find(pScript->Instance()->InstanceID());
|
||||
if (it != mScriptMap.end())
|
||||
mScriptMap.erase(it);
|
||||
|
||||
switch (pScript->Object()->ObjectTypeID())
|
||||
switch (pScript->Instance()->ObjectTypeID())
|
||||
{
|
||||
case 0x4E:
|
||||
case 0x52454141:
|
||||
for (auto it = mAreaAttributesObjects.begin(); it != mAreaAttributesObjects.end(); it++)
|
||||
{
|
||||
if ((*it).Instance() == pScript->Object())
|
||||
if ((*it).Instance() == pScript->Instance())
|
||||
{
|
||||
mAreaAttributesObjects.erase(it);
|
||||
break;
|
||||
@@ -182,32 +182,32 @@ void CScene::SetActiveArea(CGameArea *pArea)
|
||||
mpAreaRootNode = new CRootNode(this, -1, mpSceneRootNode);
|
||||
|
||||
// Create static nodes
|
||||
u32 Count = mpArea->GetStaticModelCount();
|
||||
u32 Count = mpArea->NumStaticModels();
|
||||
|
||||
for (u32 iMdl = 0; iMdl < Count; iMdl++)
|
||||
{
|
||||
CStaticNode *pNode = CreateStaticNode(mpArea->GetStaticModel(iMdl));
|
||||
CStaticNode *pNode = CreateStaticNode(mpArea->StaticModel(iMdl));
|
||||
pNode->SetName("Static World Model " + TString::FromInt32(iMdl, 0, 10));
|
||||
}
|
||||
|
||||
// Create model nodes
|
||||
Count = mpArea->GetTerrainModelCount();
|
||||
Count = mpArea->NumWorldModels();
|
||||
|
||||
for (u32 iMdl = 0; iMdl < Count; iMdl++)
|
||||
{
|
||||
CModel *pModel = mpArea->GetTerrainModel(iMdl);
|
||||
CModel *pModel = mpArea->TerrainModel(iMdl);
|
||||
CModelNode *pNode = CreateModelNode(pModel);
|
||||
pNode->SetName("World Model " + TString::FromInt32(iMdl, 0, 10));
|
||||
pNode->SetWorldModel(true);
|
||||
}
|
||||
|
||||
CreateCollisionNode(mpArea->GetCollision());
|
||||
CreateCollisionNode(mpArea->Collision());
|
||||
|
||||
u32 NumLayers = mpArea->GetScriptLayerCount();
|
||||
u32 NumLayers = mpArea->NumScriptLayers();
|
||||
|
||||
for (u32 iLyr = 0; iLyr < NumLayers; iLyr++)
|
||||
{
|
||||
CScriptLayer *pLayer = mpArea->GetScriptLayer(iLyr);
|
||||
CScriptLayer *pLayer = mpArea->ScriptLayer(iLyr);
|
||||
u32 NumObjects = pLayer->NumInstances();
|
||||
mNodes[eScriptNode].reserve(mNodes[eScriptNode].size() + NumObjects);
|
||||
|
||||
@@ -218,7 +218,7 @@ void CScene::SetActiveArea(CGameArea *pArea)
|
||||
}
|
||||
}
|
||||
|
||||
CScriptLayer *pGenLayer = mpArea->GetGeneratorLayer();
|
||||
CScriptLayer *pGenLayer = mpArea->GeneratedObjectsLayer();
|
||||
if (pGenLayer)
|
||||
{
|
||||
for (u32 iObj = 0; iObj < pGenLayer->NumInstances(); iObj++)
|
||||
@@ -236,19 +236,19 @@ void CScene::SetActiveArea(CGameArea *pArea)
|
||||
pScript->BuildLightList(mpArea);
|
||||
}
|
||||
|
||||
u32 NumLightLayers = mpArea->GetLightLayerCount();
|
||||
u32 NumLightLayers = mpArea->NumLightLayers();
|
||||
CGraphics::sAreaAmbientColor = CColor::skBlack;
|
||||
|
||||
for (u32 iLyr = 0; iLyr < NumLightLayers; iLyr++)
|
||||
{
|
||||
u32 NumLights = mpArea->GetLightCount(iLyr);
|
||||
u32 NumLights = mpArea->NumLights(iLyr);
|
||||
|
||||
for (u32 iLit = 0; iLit < NumLights; iLit++)
|
||||
{
|
||||
CLight *pLight = mpArea->GetLight(iLyr, iLit);
|
||||
CLight *pLight = mpArea->Light(iLyr, iLit);
|
||||
|
||||
if (pLight->GetType() == eLocalAmbient)
|
||||
CGraphics::sAreaAmbientColor += pLight->GetColor();
|
||||
if (pLight->Type() == eLocalAmbient)
|
||||
CGraphics::sAreaAmbientColor += pLight->Color();
|
||||
|
||||
CreateLightNode(pLight);
|
||||
}
|
||||
@@ -285,36 +285,36 @@ void CScene::ClearScene()
|
||||
mpArea = nullptr;
|
||||
}
|
||||
|
||||
void CScene::AddSceneToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
|
||||
void CScene::AddSceneToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo)
|
||||
{
|
||||
// Call PostLoad the first time the scene is rendered to ensure the OpenGL context has been created before it runs.
|
||||
if (!mRanPostLoad)
|
||||
PostLoad();
|
||||
|
||||
// Override show flags in game mode
|
||||
FShowFlags ShowFlags = (ViewInfo.GameMode ? gkGameModeShowFlags : ViewInfo.ShowFlags);
|
||||
FShowFlags ShowFlags = (rkViewInfo.GameMode ? gkGameModeShowFlags : rkViewInfo.ShowFlags);
|
||||
FNodeFlags NodeFlags = NodeFlagsForShowFlags(ShowFlags);
|
||||
|
||||
for (CSceneIterator It(this, NodeFlags, false); It; ++It)
|
||||
{
|
||||
if (ViewInfo.GameMode || It->IsVisible())
|
||||
It->AddToRenderer(pRenderer, ViewInfo);
|
||||
if (rkViewInfo.GameMode || It->IsVisible())
|
||||
It->AddToRenderer(pRenderer, rkViewInfo);
|
||||
}
|
||||
}
|
||||
|
||||
SRayIntersection CScene::SceneRayCast(const CRay& Ray, const SViewInfo& ViewInfo)
|
||||
SRayIntersection CScene::SceneRayCast(const CRay& rkRay, const SViewInfo& rkViewInfo)
|
||||
{
|
||||
FShowFlags ShowFlags = (ViewInfo.GameMode ? gkGameModeShowFlags : ViewInfo.ShowFlags);
|
||||
FShowFlags ShowFlags = (rkViewInfo.GameMode ? gkGameModeShowFlags : rkViewInfo.ShowFlags);
|
||||
FNodeFlags NodeFlags = NodeFlagsForShowFlags(ShowFlags);
|
||||
CRayCollisionTester Tester(Ray);
|
||||
CRayCollisionTester Tester(rkRay);
|
||||
|
||||
for (CSceneIterator It(this, NodeFlags, false); It; ++It)
|
||||
{
|
||||
if (It->IsVisible())
|
||||
It->RayAABoxIntersectTest(Tester, ViewInfo);
|
||||
It->RayAABoxIntersectTest(Tester, rkViewInfo);
|
||||
}
|
||||
|
||||
return Tester.TestNodes(ViewInfo);
|
||||
return Tester.TestNodes(rkViewInfo);
|
||||
}
|
||||
|
||||
CSceneNode* CScene::NodeByID(u32 NodeID)
|
||||
@@ -333,7 +333,7 @@ CScriptNode* CScene::NodeForInstanceID(u32 InstanceID)
|
||||
else return nullptr;
|
||||
}
|
||||
|
||||
CScriptNode* CScene::NodeForObject(CScriptObject *pObj)
|
||||
CScriptNode* CScene::NodeForInstance(CScriptObject *pObj)
|
||||
{
|
||||
return NodeForInstanceID(pObj->InstanceID());
|
||||
}
|
||||
@@ -352,7 +352,7 @@ CLightNode* CScene::NodeForLight(CLight *pLight)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CModel* CScene::GetActiveSkybox()
|
||||
CModel* CScene::ActiveSkybox()
|
||||
{
|
||||
bool SkyEnabled = false;
|
||||
|
||||
@@ -372,11 +372,11 @@ CModel* CScene::GetActiveSkybox()
|
||||
}
|
||||
}
|
||||
|
||||
if (SkyEnabled) return mpWorld->GetDefaultSkybox();
|
||||
if (SkyEnabled) return mpWorld->DefaultSkybox();
|
||||
else return nullptr;
|
||||
}
|
||||
|
||||
CGameArea* CScene::GetActiveArea()
|
||||
CGameArea* CScene::ActiveArea()
|
||||
{
|
||||
return mpArea;
|
||||
}
|
||||
|
||||
@@ -64,12 +64,10 @@ public:
|
||||
SRayIntersection SceneRayCast(const CRay& rkRay, const SViewInfo& rkViewInfo);
|
||||
CSceneNode* NodeByID(u32 NodeID);
|
||||
CScriptNode* NodeForInstanceID(u32 InstanceID);
|
||||
CScriptNode* NodeForObject(CScriptObject *pObj);
|
||||
CScriptNode* NodeForInstance(CScriptObject *pObj);
|
||||
CLightNode* NodeForLight(CLight *pLight);
|
||||
|
||||
// Setters/Getters
|
||||
CModel* GetActiveSkybox();
|
||||
CGameArea* GetActiveArea();
|
||||
CModel* ActiveSkybox();
|
||||
CGameArea* ActiveArea();
|
||||
|
||||
// Static
|
||||
static FShowFlags ShowFlagsForNodeFlags(FNodeFlags NodeFlags);
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include "Core/Render/CDrawUtil.h"
|
||||
#include "Core/Resource/CGameArea.h"
|
||||
#include "Core/Resource/CResCache.h"
|
||||
#include <Common/AnimUtil.h>
|
||||
#include <Math/CTransform4f.h>
|
||||
|
||||
#include <algorithm>
|
||||
@@ -13,27 +12,23 @@ u32 CSceneNode::smNumNodes = 0;
|
||||
CColor CSceneNode::skSelectionTint = CColor::Integral(39, 154, 167);
|
||||
|
||||
CSceneNode::CSceneNode(CScene *pScene, u32 NodeID, CSceneNode *pParent)
|
||||
: mpScene(pScene)
|
||||
, mpParent(pParent)
|
||||
, _mID(NodeID)
|
||||
, mPosition(CVector3f::skZero)
|
||||
, mRotation(CQuaternion::skIdentity)
|
||||
, mScale(CVector3f::skOne)
|
||||
, _mTransformDirty(true)
|
||||
, _mInheritsPosition(true)
|
||||
, _mInheritsRotation(true)
|
||||
, _mInheritsScale(true)
|
||||
, mLightLayerIndex(0)
|
||||
, mLightCount(0)
|
||||
, mMouseHovering(false)
|
||||
, mSelected(false)
|
||||
, mVisible(true)
|
||||
{
|
||||
smNumNodes++;
|
||||
mpScene = pScene;
|
||||
mpParent = pParent;
|
||||
_mID = NodeID;
|
||||
|
||||
mPosition = CVector3f::skZero;
|
||||
mRotation = CQuaternion::skIdentity;
|
||||
mScale = CVector3f::skOne;
|
||||
_mTransformDirty = true;
|
||||
|
||||
_mInheritsPosition = true;
|
||||
_mInheritsRotation = true;
|
||||
_mInheritsScale = true;
|
||||
|
||||
mLightLayerIndex = 0;
|
||||
mLightCount = 0;
|
||||
|
||||
mMouseHovering = false;
|
||||
mSelected = false;
|
||||
mVisible = true;
|
||||
|
||||
if (mpParent)
|
||||
mpParent->mChildren.push_back(this);
|
||||
@@ -53,13 +48,13 @@ void CSceneNode::DrawSelection()
|
||||
CDrawUtil::DrawWireCube(AABox(), CColor::skWhite);
|
||||
}
|
||||
|
||||
void CSceneNode::RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& /*ViewInfo*/)
|
||||
void CSceneNode::RayAABoxIntersectTest(CRayCollisionTester& rTester, const SViewInfo& /*rkViewInfo*/)
|
||||
{
|
||||
// Default implementation for virtual function
|
||||
std::pair<bool,float> result = AABox().IntersectsRay(Tester.Ray());
|
||||
std::pair<bool,float> Result = AABox().IntersectsRay(rTester.Ray());
|
||||
|
||||
if (result.first)
|
||||
Tester.AddNode(this, -1, result.second);
|
||||
if (Result.first)
|
||||
rTester.AddNode(this, -1, Result.second);
|
||||
}
|
||||
|
||||
bool CSceneNode::IsVisible() const
|
||||
@@ -68,10 +63,10 @@ bool CSceneNode::IsVisible() const
|
||||
return mVisible;
|
||||
}
|
||||
|
||||
CColor CSceneNode::TintColor(const SViewInfo& ViewInfo) const
|
||||
CColor CSceneNode::TintColor(const SViewInfo& rkViewInfo) const
|
||||
{
|
||||
// Default implementation for virtual function
|
||||
return (IsSelected() && !ViewInfo.GameMode ? skSelectionTint : CColor::skWhite);
|
||||
return (IsSelected() && !rkViewInfo.GameMode ? skSelectionTint : CColor::skWhite);
|
||||
}
|
||||
|
||||
CColor CSceneNode::WireframeColor() const
|
||||
@@ -138,8 +133,8 @@ void CSceneNode::BuildLightList(CGameArea *pArea)
|
||||
mLightCount = 0;
|
||||
mAmbientColor = CColor::skBlack;
|
||||
|
||||
u32 index = mLightLayerIndex;
|
||||
if ((pArea->GetLightLayerCount() <= index) || (pArea->GetLightCount(index) == 0)) index = 0;
|
||||
u32 Index = mLightLayerIndex;
|
||||
if ((pArea->NumLightLayers() <= Index) || (pArea->NumLights(Index) == 0)) Index = 0;
|
||||
|
||||
struct SLightEntry {
|
||||
CLight *pLight;
|
||||
@@ -148,32 +143,32 @@ void CSceneNode::BuildLightList(CGameArea *pArea)
|
||||
SLightEntry(CLight *_pLight, float _Distance)
|
||||
: pLight(_pLight), Distance(_Distance) {}
|
||||
|
||||
bool operator<(const SLightEntry& other) {
|
||||
return (Distance < other.Distance);
|
||||
bool operator<(const SLightEntry& rkOther) {
|
||||
return (Distance < rkOther.Distance);
|
||||
}
|
||||
};
|
||||
std::vector<SLightEntry> LightEntries;
|
||||
|
||||
// Default ambient color to white if there are no lights on the selected layer
|
||||
u32 numLights = pArea->GetLightCount(index);
|
||||
if (numLights == 0) mAmbientColor = CColor::skWhite;
|
||||
u32 NumLights = pArea->NumLights(Index);
|
||||
if (NumLights == 0) mAmbientColor = CColor::skWhite;
|
||||
|
||||
for (u32 iLight = 0; iLight < numLights; iLight++)
|
||||
for (u32 iLight = 0; iLight < NumLights; iLight++)
|
||||
{
|
||||
CLight* pLight = pArea->GetLight(index, iLight);
|
||||
CLight* pLight = pArea->Light(Index, iLight);
|
||||
|
||||
// Ambient lights should only be present one per layer; need to check how the game deals with multiple ambients
|
||||
if (pLight->GetType() == eLocalAmbient)
|
||||
mAmbientColor = pLight->GetColor();
|
||||
if (pLight->Type() == eLocalAmbient)
|
||||
mAmbientColor = pLight->Color();
|
||||
|
||||
// Other lights will be used depending which are closest to the node
|
||||
else
|
||||
{
|
||||
bool IsInRange = AABox().IntersectsSphere(pLight->GetPosition(), pLight->GetRadius());
|
||||
bool IsInRange = AABox().IntersectsSphere(pLight->Position(), pLight->GetRadius());
|
||||
|
||||
if (IsInRange)
|
||||
{
|
||||
float Dist = mPosition.Distance(pLight->GetPosition());
|
||||
float Dist = mPosition.Distance(pLight->Position());
|
||||
LightEntries.push_back(SLightEntry(pLight, Dist));
|
||||
}
|
||||
}
|
||||
@@ -183,14 +178,14 @@ void CSceneNode::BuildLightList(CGameArea *pArea)
|
||||
std::sort(LightEntries.begin(), LightEntries.end());
|
||||
mLightCount = (LightEntries.size() > 8) ? 8 : LightEntries.size();
|
||||
|
||||
for (u32 i = 0; i < mLightCount; i++)
|
||||
mLights[i] = LightEntries[i].pLight;
|
||||
for (u32 iLight = 0; iLight < mLightCount; iLight++)
|
||||
mLights[iLight] = LightEntries[iLight].pLight;
|
||||
}
|
||||
|
||||
void CSceneNode::LoadLights(const SViewInfo& ViewInfo)
|
||||
void CSceneNode::LoadLights(const SViewInfo& rkViewInfo)
|
||||
{
|
||||
CGraphics::sNumLights = 0;
|
||||
CGraphics::ELightingMode Mode = (ViewInfo.GameMode ? CGraphics::eWorldLighting : CGraphics::sLightMode);
|
||||
CGraphics::ELightingMode Mode = (rkViewInfo.GameMode ? CGraphics::eWorldLighting : CGraphics::sLightMode);
|
||||
|
||||
switch (Mode)
|
||||
{
|
||||
@@ -248,38 +243,38 @@ void CSceneNode::AddSurfacesToRenderer(CRenderer *pRenderer, CModel *pModel, u32
|
||||
}
|
||||
|
||||
// ************ TRANSFORM ************
|
||||
void CSceneNode::Translate(const CVector3f& translation, ETransformSpace transformSpace)
|
||||
void CSceneNode::Translate(const CVector3f& rkTranslation, ETransformSpace TransformSpace)
|
||||
{
|
||||
switch (transformSpace)
|
||||
switch (TransformSpace)
|
||||
{
|
||||
case eWorldTransform:
|
||||
mPosition += translation;
|
||||
mPosition += rkTranslation;
|
||||
break;
|
||||
case eLocalTransform:
|
||||
mPosition += mRotation * translation;
|
||||
mPosition += mRotation * rkTranslation;
|
||||
break;
|
||||
}
|
||||
MarkTransformChanged();
|
||||
}
|
||||
|
||||
void CSceneNode::Rotate(const CQuaternion& rotation, ETransformSpace transformSpace)
|
||||
void CSceneNode::Rotate(const CQuaternion& rkRotation, ETransformSpace TransformSpace)
|
||||
{
|
||||
switch (transformSpace)
|
||||
switch (TransformSpace)
|
||||
{
|
||||
case eWorldTransform:
|
||||
mRotation = rotation * mRotation;
|
||||
mRotation = rkRotation * mRotation;
|
||||
break;
|
||||
case eLocalTransform:
|
||||
mRotation *= rotation;
|
||||
mRotation *= rkRotation;
|
||||
break;
|
||||
}
|
||||
MarkTransformChanged();
|
||||
}
|
||||
|
||||
void CSceneNode::Scale(const CVector3f& scale)
|
||||
void CSceneNode::Scale(const CVector3f& rkScale)
|
||||
{
|
||||
// No support for stretch/skew world-space scaling; local only
|
||||
mScale *= scale;
|
||||
mScale *= rkScale;
|
||||
MarkTransformChanged();
|
||||
}
|
||||
|
||||
@@ -327,31 +322,6 @@ void CSceneNode::CalculateTransform(CTransform4f& rOut) const
|
||||
}
|
||||
|
||||
// ************ GETTERS ************
|
||||
TString CSceneNode::Name() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
CSceneNode* CSceneNode::Parent() const
|
||||
{
|
||||
return mpParent;
|
||||
}
|
||||
|
||||
CScene* CSceneNode::Scene() const
|
||||
{
|
||||
return mpScene;
|
||||
}
|
||||
|
||||
u32 CSceneNode::ID() const
|
||||
{
|
||||
return _mID;
|
||||
}
|
||||
|
||||
CVector3f CSceneNode::LocalPosition() const
|
||||
{
|
||||
return mPosition;
|
||||
}
|
||||
|
||||
CVector3f CSceneNode::AbsolutePosition() const
|
||||
{
|
||||
CVector3f ret = mPosition;
|
||||
@@ -362,11 +332,6 @@ CVector3f CSceneNode::AbsolutePosition() const
|
||||
return ret;
|
||||
}
|
||||
|
||||
CQuaternion CSceneNode::LocalRotation() const
|
||||
{
|
||||
return mRotation;
|
||||
}
|
||||
|
||||
CQuaternion CSceneNode::AbsoluteRotation() const
|
||||
{
|
||||
CQuaternion ret = mRotation;
|
||||
@@ -377,11 +342,6 @@ CQuaternion CSceneNode::AbsoluteRotation() const
|
||||
return ret;
|
||||
}
|
||||
|
||||
CVector3f CSceneNode::LocalScale() const
|
||||
{
|
||||
return mScale;
|
||||
}
|
||||
|
||||
CVector3f CSceneNode::AbsoluteScale() const
|
||||
{
|
||||
CVector3f ret = mScale;
|
||||
@@ -399,96 +359,3 @@ CAABox CSceneNode::AABox() const
|
||||
|
||||
return _mCachedAABox;
|
||||
}
|
||||
|
||||
CVector3f CSceneNode::CenterPoint() const
|
||||
{
|
||||
return AABox().Center();
|
||||
}
|
||||
|
||||
u32 CSceneNode::LightLayerIndex() const
|
||||
{
|
||||
return mLightLayerIndex;
|
||||
}
|
||||
|
||||
bool CSceneNode::MarkedVisible() const
|
||||
{
|
||||
// The reason I have this function is because the instance view needs to know whether a node is marked
|
||||
// visible independently from other factors that may affect node visibility (as returned by IsVisible()).
|
||||
// It's a little confusing, so maybe there's a better way to set this up.
|
||||
return mVisible;
|
||||
}
|
||||
|
||||
bool CSceneNode::IsMouseHovering() const
|
||||
{
|
||||
return mMouseHovering;
|
||||
}
|
||||
|
||||
bool CSceneNode::IsSelected() const
|
||||
{
|
||||
return mSelected;
|
||||
}
|
||||
|
||||
bool CSceneNode::InheritsPosition() const
|
||||
{
|
||||
return _mInheritsPosition;
|
||||
}
|
||||
|
||||
bool CSceneNode::InheritsRotation() const
|
||||
{
|
||||
return _mInheritsRotation;
|
||||
}
|
||||
|
||||
bool CSceneNode::InheritsScale() const
|
||||
{
|
||||
return _mInheritsScale;
|
||||
}
|
||||
|
||||
// ************ SETTERS ************
|
||||
void CSceneNode::SetName(const TString& Name)
|
||||
{
|
||||
mName = Name;
|
||||
}
|
||||
|
||||
void CSceneNode::SetPosition(const CVector3f& position)
|
||||
{
|
||||
mPosition = position;
|
||||
MarkTransformChanged();
|
||||
}
|
||||
|
||||
void CSceneNode::SetRotation(const CQuaternion& rotation)
|
||||
{
|
||||
mRotation = rotation;
|
||||
MarkTransformChanged();
|
||||
}
|
||||
|
||||
void CSceneNode::SetRotation(const CVector3f& rotEuler)
|
||||
{
|
||||
mRotation = CQuaternion::FromEuler(rotEuler);
|
||||
MarkTransformChanged();
|
||||
}
|
||||
|
||||
void CSceneNode::SetScale(const CVector3f& scale)
|
||||
{
|
||||
mScale = scale;
|
||||
MarkTransformChanged();
|
||||
}
|
||||
|
||||
void CSceneNode::SetLightLayerIndex(u32 index)
|
||||
{
|
||||
mLightLayerIndex = index;
|
||||
}
|
||||
|
||||
void CSceneNode::SetMouseHovering(bool Hovering)
|
||||
{
|
||||
mMouseHovering = Hovering;
|
||||
}
|
||||
|
||||
void CSceneNode::SetSelected(bool Selected)
|
||||
{
|
||||
mSelected = Selected;
|
||||
}
|
||||
|
||||
void CSceneNode::SetVisible(bool Visible)
|
||||
{
|
||||
mVisible = Visible;
|
||||
}
|
||||
|
||||
@@ -58,15 +58,15 @@ public:
|
||||
virtual ENodeType NodeType() = 0;
|
||||
virtual void PostLoad() {}
|
||||
virtual void OnTransformed() {}
|
||||
virtual void AddToRenderer(CRenderer* /*pRenderer*/, const SViewInfo& /*ViewInfo*/) {}
|
||||
virtual void AddToRenderer(CRenderer* /*pRenderer*/, const SViewInfo& /*rkViewInfo*/) {}
|
||||
virtual void DrawSelection();
|
||||
virtual void RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo);
|
||||
virtual SRayIntersection RayNodeIntersectTest(const CRay& Ray, u32 AssetID, const SViewInfo& ViewInfo) = 0;
|
||||
virtual void RayAABoxIntersectTest(CRayCollisionTester& rTester, const SViewInfo& rkViewInfo);
|
||||
virtual SRayIntersection RayNodeIntersectTest(const CRay& rkRay, u32 AssetID, const SViewInfo& rkViewInfo) = 0;
|
||||
virtual bool AllowsTranslate() const { return true; }
|
||||
virtual bool AllowsRotate() const { return true; }
|
||||
virtual bool AllowsScale() const { return true; }
|
||||
virtual bool IsVisible() const;
|
||||
virtual CColor TintColor(const SViewInfo& ViewInfo) const;
|
||||
virtual CColor TintColor(const SViewInfo& rkViewInfo) const;
|
||||
virtual CColor WireframeColor() const;
|
||||
|
||||
void OnLoadFinished();
|
||||
@@ -76,15 +76,15 @@ public:
|
||||
void SetInheritance(bool InheritPos, bool InheritRot, bool InheritScale);
|
||||
void LoadModelMatrix();
|
||||
void BuildLightList(CGameArea *pArea);
|
||||
void LoadLights(const SViewInfo& ViewInfo);
|
||||
void LoadLights(const SViewInfo& rkViewInfo);
|
||||
void DrawBoundingBox() const;
|
||||
void DrawRotationArrow() const;
|
||||
void AddSurfacesToRenderer(CRenderer *pRenderer, CModel *pModel, u32 MatSet, const SViewInfo& ViewInfo);
|
||||
void AddSurfacesToRenderer(CRenderer *pRenderer, CModel *pModel, u32 MatSet, const SViewInfo& rkViewInfo);
|
||||
|
||||
// Transform
|
||||
void Translate(const CVector3f& translation, ETransformSpace transformSpace);
|
||||
void Rotate(const CQuaternion& rotation, ETransformSpace transformSpace);
|
||||
void Scale(const CVector3f& scale);
|
||||
void Translate(const CVector3f& rkTranslation, ETransformSpace TransformSpace);
|
||||
void Rotate(const CQuaternion& rkRotation, ETransformSpace TransformSpace);
|
||||
void Scale(const CVector3f& rkScale);
|
||||
const CTransform4f& Transform() const;
|
||||
protected:
|
||||
void MarkTransformChanged() const;
|
||||
@@ -92,37 +92,38 @@ protected:
|
||||
virtual void CalculateTransform(CTransform4f& rOut) const;
|
||||
|
||||
public:
|
||||
// Getters
|
||||
TString Name() const;
|
||||
CSceneNode* Parent() const;
|
||||
CScene* Scene() const;
|
||||
u32 ID() const;
|
||||
CVector3f LocalPosition() const;
|
||||
CVector3f AbsolutePosition() const;
|
||||
CQuaternion LocalRotation() const;
|
||||
CQuaternion AbsoluteRotation() const;
|
||||
CVector3f LocalScale() const;
|
||||
CVector3f AbsoluteScale() const;
|
||||
CAABox AABox() const;
|
||||
CVector3f CenterPoint() const;
|
||||
u32 LightLayerIndex() const;
|
||||
bool MarkedVisible() const;
|
||||
bool IsMouseHovering() const;
|
||||
bool IsSelected() const;
|
||||
bool InheritsPosition() const;
|
||||
bool InheritsRotation() const;
|
||||
bool InheritsScale() const;
|
||||
|
||||
// Inline Accessors
|
||||
TString Name() const { return mName; }
|
||||
CSceneNode* Parent() const { return mpParent; }
|
||||
CScene* Scene() const { return mpScene; }
|
||||
u32 ID() const { return _mID; }
|
||||
CVector3f LocalPosition() const { return mPosition; }
|
||||
CQuaternion LocalRotation() const { return mRotation; }
|
||||
CVector3f LocalScale() const { return mScale; }
|
||||
CVector3f CenterPoint() const { return AABox().Center(); }
|
||||
u32 LightLayerIndex() const { return mLightLayerIndex; }
|
||||
bool MarkedVisible() const { return mVisible; }
|
||||
bool IsMouseHovering() const { return mMouseHovering; }
|
||||
bool IsSelected() const { return mSelected; }
|
||||
bool InheritsPosition() const { return _mInheritsPosition; }
|
||||
bool InheritsRotation() const { return _mInheritsRotation; }
|
||||
bool InheritsScale() const { return _mInheritsScale; }
|
||||
|
||||
// Setters
|
||||
void SetName(const TString& Name);
|
||||
void SetPosition(const CVector3f& position);
|
||||
void SetRotation(const CQuaternion& rotation);
|
||||
void SetRotation(const CVector3f& rotEuler);
|
||||
void SetScale(const CVector3f& scale);
|
||||
void SetLightLayerIndex(u32 index);
|
||||
void SetMouseHovering(bool Hovering);
|
||||
void SetSelected(bool Selected);
|
||||
void SetVisible(bool Visible);
|
||||
void SetName(const TString& rkName) { mName = rkName; }
|
||||
void SetPosition(const CVector3f& rkPosition) { mPosition = rkPosition; MarkTransformChanged(); }
|
||||
void SetRotation(const CQuaternion& rkRotation) { mRotation = rkRotation; MarkTransformChanged(); }
|
||||
void SetRotation(const CVector3f& rkRotEuler) { mRotation = CQuaternion::FromEuler(rkRotEuler); MarkTransformChanged(); }
|
||||
void SetScale(const CVector3f& rkScale) { mScale = rkScale; MarkTransformChanged(); }
|
||||
void SetLightLayerIndex(u32 Index) { mLightLayerIndex = Index; }
|
||||
void SetMouseHovering(bool Hovering) { mMouseHovering = Hovering; }
|
||||
void SetSelected(bool Selected) { mSelected = Selected; }
|
||||
void SetVisible(bool Visible) { mVisible = Visible; }
|
||||
|
||||
// Static
|
||||
inline static int NumNodes() { return smNumNodes; }
|
||||
|
||||
@@ -7,20 +7,19 @@
|
||||
#include "Core/Resource/Script/CMasterTemplate.h"
|
||||
#include "Core/Resource/Script/CScriptLayer.h"
|
||||
#include "Core/ScriptExtra/CScriptExtra.h"
|
||||
#include <Common/AnimUtil.h>
|
||||
#include <Math/MathUtil.h>
|
||||
|
||||
CScriptNode::CScriptNode(CScene *pScene, u32 NodeID, CSceneNode *pParent, CScriptObject *pObject)
|
||||
CScriptNode::CScriptNode(CScene *pScene, u32 NodeID, CSceneNode *pParent, CScriptObject *pInstance)
|
||||
: CSceneNode(pScene, NodeID, pParent)
|
||||
, mGameModeVisibility(eUntested)
|
||||
, mpVolumePreviewNode(nullptr)
|
||||
, mHasVolumePreview(false)
|
||||
, mpInstance(pInstance)
|
||||
, mpBillboard(nullptr)
|
||||
{
|
||||
mpVolumePreviewNode = nullptr;
|
||||
mHasVolumePreview = false;
|
||||
|
||||
// Evaluate instance
|
||||
mpInstance = pObject;
|
||||
SetActiveModel(nullptr);
|
||||
mpBillboard = nullptr;
|
||||
mpCollisionNode = new CCollisionNode(pScene, -1, this);
|
||||
mpCollisionNode->SetInheritance(true, true, false);
|
||||
|
||||
@@ -57,7 +56,7 @@ CScriptNode::CScriptNode(CScene *pScene, u32 NodeID, CSceneNode *pParent, CScrip
|
||||
}
|
||||
|
||||
// Fetch LightParameters
|
||||
mpLightParameters = new CLightParameters(mpInstance->LightParameters(), mpInstance->MasterTemplate()->GetGame());
|
||||
mpLightParameters = new CLightParameters(mpInstance->LightParameters(), mpInstance->MasterTemplate()->Game());
|
||||
SetLightLayerIndex(mpLightParameters->LightLayerIndex());
|
||||
}
|
||||
|
||||
@@ -104,15 +103,15 @@ void CScriptNode::OnTransformed()
|
||||
mpExtra->OnTransformed();
|
||||
}
|
||||
|
||||
void CScriptNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
|
||||
void CScriptNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo)
|
||||
{
|
||||
if (!mpInstance) return;
|
||||
|
||||
// Add script extra to renderer first
|
||||
if (mpExtra) mpExtra->AddToRenderer(pRenderer, ViewInfo);
|
||||
if (mpExtra) mpExtra->AddToRenderer(pRenderer, rkViewInfo);
|
||||
|
||||
// If we're in game mode, then override other visibility settings.
|
||||
if (ViewInfo.GameMode)
|
||||
if (rkViewInfo.GameMode)
|
||||
{
|
||||
if (mGameModeVisibility == eUntested)
|
||||
TestGameModeVisibility();
|
||||
@@ -127,12 +126,12 @@ void CScriptNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
|
||||
if (ShouldDraw)
|
||||
{
|
||||
// Otherwise, we proceed as normal
|
||||
if ((ViewInfo.ShowFlags & eShowObjectCollision) && (!ViewInfo.GameMode))
|
||||
mpCollisionNode->AddToRenderer(pRenderer, ViewInfo);
|
||||
if ((rkViewInfo.ShowFlags & eShowObjectCollision) && (!rkViewInfo.GameMode))
|
||||
mpCollisionNode->AddToRenderer(pRenderer, rkViewInfo);
|
||||
|
||||
if (ViewInfo.ShowFlags & eShowObjectGeometry || ViewInfo.GameMode)
|
||||
if (rkViewInfo.ShowFlags & eShowObjectGeometry || rkViewInfo.GameMode)
|
||||
{
|
||||
if (ViewInfo.ViewFrustum.BoxInFrustum(AABox()))
|
||||
if (rkViewInfo.ViewFrustum.BoxInFrustum(AABox()))
|
||||
{
|
||||
if (!mpActiveModel)
|
||||
pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawMesh);
|
||||
@@ -142,13 +141,13 @@ void CScriptNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
|
||||
if (!mpActiveModel->HasTransparency(0))
|
||||
pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawMesh);
|
||||
else
|
||||
AddSurfacesToRenderer(pRenderer, mpActiveModel, 0, ViewInfo);
|
||||
AddSurfacesToRenderer(pRenderer, mpActiveModel, 0, rkViewInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (IsSelected() && !ViewInfo.GameMode)
|
||||
if (IsSelected() && !rkViewInfo.GameMode)
|
||||
{
|
||||
// Script nodes always draw their selections regardless of frustum planes
|
||||
// in order to ensure that script connection lines don't get improperly culled.
|
||||
@@ -156,11 +155,11 @@ void CScriptNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
|
||||
pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawSelection);
|
||||
|
||||
if (mHasVolumePreview && (!mpExtra || mpExtra->ShouldDrawVolume()))
|
||||
mpVolumePreviewNode->AddToRenderer(pRenderer, ViewInfo);
|
||||
mpVolumePreviewNode->AddToRenderer(pRenderer, rkViewInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void CScriptNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo)
|
||||
void CScriptNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& rkViewInfo)
|
||||
{
|
||||
if (!mpInstance) return;
|
||||
|
||||
@@ -187,7 +186,7 @@ void CScriptNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewIn
|
||||
}
|
||||
|
||||
else
|
||||
LoadLights(ViewInfo);
|
||||
LoadLights(rkViewInfo);
|
||||
}
|
||||
|
||||
LoadModelMatrix();
|
||||
@@ -198,7 +197,7 @@ void CScriptNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewIn
|
||||
if (mpExtra) CGraphics::sPixelBlock.TevColor = mpExtra->TevColor();
|
||||
else CGraphics::sPixelBlock.TevColor = CColor::skWhite;
|
||||
|
||||
CGraphics::sPixelBlock.TintColor = TintColor(ViewInfo);
|
||||
CGraphics::sPixelBlock.TintColor = TintColor(rkViewInfo);
|
||||
CGraphics::UpdatePixelBlock();
|
||||
|
||||
if (ComponentIndex < 0)
|
||||
@@ -214,14 +213,14 @@ void CScriptNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewIn
|
||||
glDepthMask(GL_TRUE);
|
||||
CGraphics::UpdateVertexBlock();
|
||||
CGraphics::UpdatePixelBlock();
|
||||
CDrawUtil::DrawShadedCube(CColor::skTransparentPurple * TintColor(ViewInfo));
|
||||
CDrawUtil::DrawShadedCube(CColor::skTransparentPurple * TintColor(rkViewInfo));
|
||||
}
|
||||
}
|
||||
|
||||
// Draw billboard
|
||||
else if (mpBillboard)
|
||||
{
|
||||
CDrawUtil::DrawBillboard(mpBillboard, mPosition, BillboardScale(), TintColor(ViewInfo));
|
||||
CDrawUtil::DrawBillboard(mpBillboard, mPosition, BillboardScale(), TintColor(rkViewInfo));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,7 +274,7 @@ void CScriptNode::DrawSelection()
|
||||
}
|
||||
}
|
||||
|
||||
void CScriptNode::RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo)
|
||||
void CScriptNode::RayAABoxIntersectTest(CRayCollisionTester& rTester, const SViewInfo& rkViewInfo)
|
||||
{
|
||||
if (!mpInstance)
|
||||
return;
|
||||
@@ -283,7 +282,7 @@ void CScriptNode::RayAABoxIntersectTest(CRayCollisionTester& Tester, const SView
|
||||
// Let script extra do ray check first
|
||||
if (mpExtra)
|
||||
{
|
||||
mpExtra->RayAABoxIntersectTest(Tester, ViewInfo);
|
||||
mpExtra->RayAABoxIntersectTest(rTester, rkViewInfo);
|
||||
|
||||
// If the extra doesn't want us rendering, then don't do the ray test either
|
||||
if (!mpExtra->ShouldDrawNormalAssets())
|
||||
@@ -291,7 +290,7 @@ void CScriptNode::RayAABoxIntersectTest(CRayCollisionTester& Tester, const SView
|
||||
}
|
||||
|
||||
// If we're in game mode, then check whether we're visible before proceeding with the ray test.
|
||||
if (ViewInfo.GameMode)
|
||||
if (rkViewInfo.GameMode)
|
||||
{
|
||||
if (mGameModeVisibility == eUntested)
|
||||
TestGameModeVisibility();
|
||||
@@ -301,16 +300,16 @@ void CScriptNode::RayAABoxIntersectTest(CRayCollisionTester& Tester, const SView
|
||||
}
|
||||
|
||||
// Otherwise, proceed with the ray test as normal...
|
||||
const CRay& Ray = Tester.Ray();
|
||||
const CRay& rkRay = rTester.Ray();
|
||||
|
||||
if (UsesModel())
|
||||
{
|
||||
std::pair<bool,float> BoxResult = AABox().IntersectsRay(Ray);
|
||||
std::pair<bool,float> BoxResult = AABox().IntersectsRay(rkRay);
|
||||
|
||||
if (BoxResult.first)
|
||||
{
|
||||
if (mpActiveModel) Tester.AddNodeModel(this, mpActiveModel);
|
||||
else Tester.AddNode(this, 0, BoxResult.second);
|
||||
if (mpActiveModel) rTester.AddNodeModel(this, mpActiveModel);
|
||||
else rTester.AddNode(this, 0, BoxResult.second);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,43 +317,43 @@ void CScriptNode::RayAABoxIntersectTest(CRayCollisionTester& Tester, const SView
|
||||
{
|
||||
// Because the billboard rotates a lot, expand the AABox on the X/Y axes to cover any possible orientation
|
||||
CVector2f BillScale = BillboardScale();
|
||||
float ScaleXY = (BillScale.x > BillScale.y ? BillScale.x : BillScale.y);
|
||||
float ScaleXY = (BillScale.X > BillScale.Y ? BillScale.X : BillScale.Y);
|
||||
|
||||
CAABox BillBox = CAABox(mPosition + CVector3f(-ScaleXY, -ScaleXY, -BillScale.y),
|
||||
mPosition + CVector3f( ScaleXY, ScaleXY, BillScale.y));
|
||||
CAABox BillBox = CAABox(mPosition + CVector3f(-ScaleXY, -ScaleXY, -BillScale.Y),
|
||||
mPosition + CVector3f( ScaleXY, ScaleXY, BillScale.Y));
|
||||
|
||||
std::pair<bool,float> BoxResult = BillBox.IntersectsRay(Ray);
|
||||
if (BoxResult.first) Tester.AddNode(this, 0, BoxResult.second);
|
||||
std::pair<bool,float> BoxResult = BillBox.IntersectsRay(rkRay);
|
||||
if (BoxResult.first) rTester.AddNode(this, 0, BoxResult.second);
|
||||
}
|
||||
}
|
||||
|
||||
SRayIntersection CScriptNode::RayNodeIntersectTest(const CRay& Ray, u32 AssetID, const SViewInfo& ViewInfo)
|
||||
SRayIntersection CScriptNode::RayNodeIntersectTest(const CRay& rkRay, u32 AssetID, const SViewInfo& rkViewInfo)
|
||||
{
|
||||
FRenderOptions Options = ViewInfo.pRenderer->RenderOptions();
|
||||
FRenderOptions Options = rkViewInfo.pRenderer->RenderOptions();
|
||||
|
||||
SRayIntersection out;
|
||||
out.pNode = this;
|
||||
out.ComponentIndex = AssetID;
|
||||
SRayIntersection Out;
|
||||
Out.pNode = this;
|
||||
Out.ComponentIndex = AssetID;
|
||||
|
||||
// Model test
|
||||
if (UsesModel())
|
||||
{
|
||||
CModel *pModel = (mpActiveModel ? mpActiveModel : CDrawUtil::GetCubeModel());
|
||||
|
||||
CRay TransformedRay = Ray.Transformed(Transform().Inverse());
|
||||
CRay TransformedRay = rkRay.Transformed(Transform().Inverse());
|
||||
std::pair<bool,float> Result = pModel->GetSurface(AssetID)->IntersectsRay(TransformedRay, ((Options & eEnableBackfaceCull) == 0));
|
||||
|
||||
if (Result.first)
|
||||
{
|
||||
out.Hit = true;
|
||||
Out.Hit = true;
|
||||
|
||||
CVector3f HitPoint = TransformedRay.PointOnRay(Result.second);
|
||||
CVector3f WorldHitPoint = Transform() * HitPoint;
|
||||
out.Distance = Math::Distance(Ray.Origin(), WorldHitPoint);
|
||||
Out.Distance = Math::Distance(rkRay.Origin(), WorldHitPoint);
|
||||
}
|
||||
|
||||
else
|
||||
out.Hit = false;
|
||||
Out.Hit = false;
|
||||
}
|
||||
|
||||
// Billboard test
|
||||
@@ -362,51 +361,51 @@ SRayIntersection CScriptNode::RayNodeIntersectTest(const CRay& Ray, u32 AssetID,
|
||||
else
|
||||
{
|
||||
// Step 1: check whether the ray intersects with the plane the billboard is on
|
||||
CPlane BillboardPlane(-ViewInfo.pCamera->Direction(), mPosition);
|
||||
std::pair<bool,float> PlaneTest = Math::RayPlaneIntersecton(Ray, BillboardPlane);
|
||||
CPlane BillboardPlane(-rkViewInfo.pCamera->Direction(), mPosition);
|
||||
std::pair<bool,float> PlaneTest = Math::RayPlaneIntersecton(rkRay, BillboardPlane);
|
||||
|
||||
if (PlaneTest.first)
|
||||
{
|
||||
// Step 2: transform the hit point into the plane's local space
|
||||
CVector3f PlaneHitPoint = Ray.PointOnRay(PlaneTest.second);
|
||||
CVector3f PlaneHitPoint = rkRay.PointOnRay(PlaneTest.second);
|
||||
CVector3f RelHitPoint = PlaneHitPoint - mPosition;
|
||||
|
||||
CVector3f PlaneForward = -ViewInfo.pCamera->Direction();
|
||||
CVector3f PlaneRight = -ViewInfo.pCamera->RightVector();
|
||||
CVector3f PlaneUp = ViewInfo.pCamera->UpVector();
|
||||
CVector3f PlaneForward = -rkViewInfo.pCamera->Direction();
|
||||
CVector3f PlaneRight = -rkViewInfo.pCamera->RightVector();
|
||||
CVector3f PlaneUp = rkViewInfo.pCamera->UpVector();
|
||||
CQuaternion PlaneRot = CQuaternion::FromAxes(PlaneRight, PlaneForward, PlaneUp);
|
||||
|
||||
CVector3f RotatedHitPoint = PlaneRot.Inverse() * RelHitPoint;
|
||||
CVector2f LocalHitPoint = RotatedHitPoint.xz() / BillboardScale();
|
||||
CVector2f LocalHitPoint = RotatedHitPoint.XZ() / BillboardScale();
|
||||
|
||||
// Step 3: check whether the transformed hit point is in the -1 to 1 range
|
||||
if ((LocalHitPoint.x >= -1.f) && (LocalHitPoint.x <= 1.f) && (LocalHitPoint.y >= -1.f) && (LocalHitPoint.y <= 1.f))
|
||||
if ((LocalHitPoint.X >= -1.f) && (LocalHitPoint.X <= 1.f) && (LocalHitPoint.Y >= -1.f) && (LocalHitPoint.Y <= 1.f))
|
||||
{
|
||||
// Step 4: look up the hit texel and check whether it's transparent or opaque
|
||||
CVector2f TexCoord = (LocalHitPoint + CVector2f(1.f)) * 0.5f;
|
||||
TexCoord.x = -TexCoord.x + 1.f;
|
||||
TexCoord.X = -TexCoord.X + 1.f;
|
||||
float TexelAlpha = mpBillboard->ReadTexelAlpha(TexCoord);
|
||||
|
||||
if (TexelAlpha < 0.25f)
|
||||
out.Hit = false;
|
||||
Out.Hit = false;
|
||||
|
||||
else
|
||||
{
|
||||
// It's opaque... we have a hit!
|
||||
out.Hit = true;
|
||||
out.Distance = PlaneTest.second;
|
||||
Out.Hit = true;
|
||||
Out.Distance = PlaneTest.second;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
out.Hit = false;
|
||||
Out.Hit = false;
|
||||
}
|
||||
|
||||
else
|
||||
out.Hit = false;
|
||||
Out.Hit = false;
|
||||
}
|
||||
|
||||
return out;
|
||||
return Out;
|
||||
}
|
||||
|
||||
bool CScriptNode::AllowsRotate() const
|
||||
@@ -539,7 +538,7 @@ void CScriptNode::GeneratePosition()
|
||||
if (!mHasValidPosition)
|
||||
{
|
||||
// Default to center of the active area; this is to preven recursion issues
|
||||
CTransform4f& AreaTransform = mpScene->GetActiveArea()->GetTransform();
|
||||
CTransform4f& AreaTransform = mpScene->ActiveArea()->Transform();
|
||||
mPosition = CVector3f(AreaTransform[0][3], AreaTransform[1][3], AreaTransform[2][3]);
|
||||
mHasValidPosition = true;
|
||||
MarkTransformChanged();
|
||||
@@ -555,9 +554,9 @@ void CScriptNode::GeneratePosition()
|
||||
CScriptNode *pNode = mpScene->NodeForInstanceID(LinkedID);
|
||||
pNode->GeneratePosition();
|
||||
mPosition = pNode->AbsolutePosition();
|
||||
mPosition.z += (pNode->AABox().Size().z / 2.f);
|
||||
mPosition.z += (AABox().Size().z / 2.f);
|
||||
mPosition.z += 2.f;
|
||||
mPosition.Z += (pNode->AABox().Size().Z / 2.f);
|
||||
mPosition.Z += (AABox().Size().Z / 2.f);
|
||||
mPosition.Z += 2.f;
|
||||
}
|
||||
|
||||
// For two or more links, average out the position of the connected objects.
|
||||
@@ -588,7 +587,7 @@ void CScriptNode::GeneratePosition()
|
||||
}
|
||||
|
||||
mPosition = NewPos / (float) NumLinks;
|
||||
mPosition.x += 2.f;
|
||||
mPosition.X += 2.f;
|
||||
}
|
||||
|
||||
MarkTransformChanged();
|
||||
@@ -611,7 +610,7 @@ CColor CScriptNode::WireframeColor() const
|
||||
return CColor::Integral(12, 135, 194);
|
||||
}
|
||||
|
||||
CScriptObject* CScriptNode::Object() const
|
||||
CScriptObject* CScriptNode::Instance() const
|
||||
{
|
||||
return mpInstance;
|
||||
}
|
||||
@@ -651,8 +650,8 @@ CAABox CScriptNode::PreviewVolumeAABox() const
|
||||
|
||||
CVector2f CScriptNode::BillboardScale() const
|
||||
{
|
||||
CVector2f out = (Template()->ScaleType() == CScriptTemplate::eScaleEnabled ? AbsoluteScale().xz() : CVector2f(1.f));
|
||||
return out * 0.5f * Template()->PreviewScale();
|
||||
CVector2f Out = (Template()->ScaleType() == CScriptTemplate::eScaleEnabled ? AbsoluteScale().XZ() : CVector2f(1.f));
|
||||
return Out * 0.5f * Template()->PreviewScale();
|
||||
}
|
||||
|
||||
// ************ PROTECTED ************
|
||||
|
||||
@@ -34,15 +34,15 @@ public:
|
||||
ENodeType NodeType();
|
||||
void PostLoad();
|
||||
void OnTransformed();
|
||||
void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo);
|
||||
void Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo);
|
||||
void AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo);
|
||||
void Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& rkViewInfo);
|
||||
void DrawSelection();
|
||||
void RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo);
|
||||
SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo);
|
||||
void RayAABoxIntersectTest(CRayCollisionTester& rTester, const SViewInfo& rkViewInfo);
|
||||
SRayIntersection RayNodeIntersectTest(const CRay& rkRay, u32 AssetID, const SViewInfo& rkViewInfo);
|
||||
bool AllowsRotate() const;
|
||||
bool AllowsScale() const;
|
||||
bool IsVisible() const;
|
||||
CColor TintColor(const SViewInfo &ViewInfo) const;
|
||||
CColor TintColor(const SViewInfo& rkViewInfo) const;
|
||||
CColor WireframeColor() const;
|
||||
|
||||
void LinksModified();
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
void UpdatePreviewVolume();
|
||||
void GeneratePosition();
|
||||
void TestGameModeVisibility();
|
||||
CScriptObject* Object() const;
|
||||
CScriptObject* Instance() const;
|
||||
CScriptTemplate* Template() const;
|
||||
CScriptExtra* Extra() const;
|
||||
CModel* ActiveModel() const;
|
||||
|
||||
@@ -2,15 +2,14 @@
|
||||
#include "Core/Render/CGraphics.h"
|
||||
#include "Core/Render/CDrawUtil.h"
|
||||
#include "Core/Render/CRenderer.h"
|
||||
#include <Common/AnimUtil.h>
|
||||
#include <Math/MathUtil.h>
|
||||
|
||||
CStaticNode::CStaticNode(CScene *pScene, u32 NodeID, CSceneNode *pParent, CStaticModel *pModel)
|
||||
: CSceneNode(pScene, NodeID, pParent)
|
||||
, mpModel(pModel)
|
||||
{
|
||||
mpModel = pModel;
|
||||
mLocalAABox = mpModel->AABox();
|
||||
mScale = CVector3f(1.f, 1.f, 1.f);
|
||||
mScale = CVector3f::skOne;
|
||||
SetName("Static Node");
|
||||
}
|
||||
|
||||
@@ -28,11 +27,11 @@ void CStaticNode::PostLoad()
|
||||
}
|
||||
}
|
||||
|
||||
void CStaticNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
|
||||
void CStaticNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo)
|
||||
{
|
||||
if (!mpModel) return;
|
||||
if (mpModel->IsOccluder()) return;
|
||||
if (!ViewInfo.ViewFrustum.BoxInFrustum(AABox())) return;
|
||||
if (!rkViewInfo.ViewFrustum.BoxInFrustum(AABox())) return;
|
||||
|
||||
if (!mpModel->IsTransparent())
|
||||
pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawMesh);
|
||||
@@ -44,20 +43,20 @@ void CStaticNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
|
||||
{
|
||||
CAABox TransformedBox = mpModel->GetSurfaceAABox(iSurf).Transformed(Transform());
|
||||
|
||||
if (ViewInfo.ViewFrustum.BoxInFrustum(TransformedBox))
|
||||
if (rkViewInfo.ViewFrustum.BoxInFrustum(TransformedBox))
|
||||
pRenderer->AddTransparentMesh(this, iSurf, TransformedBox, eDrawMesh);
|
||||
}
|
||||
}
|
||||
|
||||
if (mSelected && !ViewInfo.GameMode)
|
||||
if (mSelected && !rkViewInfo.GameMode)
|
||||
pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawSelection);
|
||||
}
|
||||
|
||||
void CStaticNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo)
|
||||
void CStaticNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& rkViewInfo)
|
||||
{
|
||||
if (!mpModel) return;
|
||||
|
||||
bool IsLightingEnabled = CGraphics::sLightMode == CGraphics::eWorldLighting || ViewInfo.GameMode;
|
||||
bool IsLightingEnabled = CGraphics::sLightMode == CGraphics::eWorldLighting || rkViewInfo.GameMode;
|
||||
bool UseWhiteAmbient = (mpModel->GetMaterial()->Options() & CMaterial::eDrawWhiteAmbientDKCR) != 0;
|
||||
|
||||
if (IsLightingEnabled)
|
||||
@@ -70,14 +69,14 @@ void CStaticNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewIn
|
||||
|
||||
else
|
||||
{
|
||||
LoadLights(ViewInfo);
|
||||
LoadLights(rkViewInfo);
|
||||
if (CGraphics::sLightMode == CGraphics::eNoLighting || UseWhiteAmbient)
|
||||
CGraphics::sVertexBlock.COLOR0_Amb = CColor::skWhite;
|
||||
}
|
||||
|
||||
float Mul = CGraphics::sWorldLightMultiplier;
|
||||
CGraphics::sPixelBlock.TevColor = CColor(Mul,Mul,Mul);
|
||||
CGraphics::sPixelBlock.TintColor = TintColor(ViewInfo);
|
||||
CGraphics::sPixelBlock.TintColor = TintColor(rkViewInfo);
|
||||
LoadModelMatrix();
|
||||
|
||||
if (ComponentIndex < 0)
|
||||
@@ -93,47 +92,47 @@ void CStaticNode::DrawSelection()
|
||||
mpModel->DrawWireframe(eNoRenderOptions, WireframeColor());
|
||||
}
|
||||
|
||||
void CStaticNode::RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& /*ViewInfo*/)
|
||||
void CStaticNode::RayAABoxIntersectTest(CRayCollisionTester& rTester, const SViewInfo& /*rkViewInfo*/)
|
||||
{
|
||||
if ((!mpModel) || (mpModel->IsOccluder()))
|
||||
return;
|
||||
|
||||
const CRay& Ray = Tester.Ray();
|
||||
std::pair<bool,float> BoxResult = AABox().IntersectsRay(Ray);
|
||||
const CRay& rkRay = rTester.Ray();
|
||||
std::pair<bool,float> BoxResult = AABox().IntersectsRay(rkRay);
|
||||
|
||||
if (BoxResult.first)
|
||||
{
|
||||
for (u32 iSurf = 0; iSurf < mpModel->GetSurfaceCount(); iSurf++)
|
||||
{
|
||||
std::pair<bool,float> SurfResult = mpModel->GetSurfaceAABox(iSurf).Transformed(Transform()).IntersectsRay(Ray);
|
||||
std::pair<bool,float> SurfResult = mpModel->GetSurfaceAABox(iSurf).Transformed(Transform()).IntersectsRay(rkRay);
|
||||
|
||||
if (SurfResult.first)
|
||||
Tester.AddNode(this, iSurf, SurfResult.second);
|
||||
rTester.AddNode(this, iSurf, SurfResult.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SRayIntersection CStaticNode::RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo)
|
||||
SRayIntersection CStaticNode::RayNodeIntersectTest(const CRay& rkRay, u32 AssetID, const SViewInfo& rkViewInfo)
|
||||
{
|
||||
SRayIntersection out;
|
||||
out.pNode = this;
|
||||
out.ComponentIndex = AssetID;
|
||||
SRayIntersection Out;
|
||||
Out.pNode = this;
|
||||
Out.ComponentIndex = AssetID;
|
||||
|
||||
CRay TransformedRay = Ray.Transformed(Transform().Inverse());
|
||||
FRenderOptions options = ViewInfo.pRenderer->RenderOptions();
|
||||
std::pair<bool,float> Result = mpModel->GetSurface(AssetID)->IntersectsRay(TransformedRay, ((options & eEnableBackfaceCull) == 0));
|
||||
CRay TransformedRay = rkRay.Transformed(Transform().Inverse());
|
||||
FRenderOptions Options = rkViewInfo.pRenderer->RenderOptions();
|
||||
std::pair<bool,float> Result = mpModel->GetSurface(AssetID)->IntersectsRay(TransformedRay, ((Options & eEnableBackfaceCull) == 0));
|
||||
|
||||
if (Result.first)
|
||||
{
|
||||
out.Hit = true;
|
||||
Out.Hit = true;
|
||||
|
||||
CVector3f HitPoint = TransformedRay.PointOnRay(Result.second);
|
||||
CVector3f WorldHitPoint = Transform() * HitPoint;
|
||||
out.Distance = Math::Distance(Ray.Origin(), WorldHitPoint);
|
||||
Out.Distance = Math::Distance(rkRay.Origin(), WorldHitPoint);
|
||||
}
|
||||
|
||||
else
|
||||
out.Hit = false;
|
||||
Out.Hit = false;
|
||||
|
||||
return out;
|
||||
return Out;
|
||||
}
|
||||
|
||||
@@ -12,11 +12,11 @@ public:
|
||||
CStaticNode(CScene *pScene, u32 NodeID, CSceneNode *pParent = 0, CStaticModel *pModel = 0);
|
||||
ENodeType NodeType();
|
||||
void PostLoad();
|
||||
void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo);
|
||||
void Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo);
|
||||
void AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo);
|
||||
void Draw(FRenderOptions Options, int ComponentIndex, const SViewInfo& rkViewInfo);
|
||||
void DrawSelection();
|
||||
void RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo);
|
||||
SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo);
|
||||
void RayAABoxIntersectTest(CRayCollisionTester& rTester, const SViewInfo& rkViewInfo);
|
||||
SRayIntersection RayNodeIntersectTest(const CRay& rkRay, u32 AssetID, const SViewInfo& rkViewInfo);
|
||||
};
|
||||
|
||||
#endif // CSTATICNODE_H
|
||||
|
||||
Reference in New Issue
Block a user