Draw wire sphere on selected lights to visualize light radius

This commit is contained in:
parax0 2015-11-29 03:00:18 -07:00
parent 9b2dd838ea
commit 7622bb2032
8 changed files with 79 additions and 10 deletions

View File

@ -153,12 +153,23 @@ std::pair<bool,float> CAABox::IntersectsRay(const CRay &Ray) const
return Math::RayBoxIntersection(Ray, *this);
}
bool CAABox::operator==(const CAABox& Other)
// ************ OPERATORS ************
CAABox CAABox::operator+(const CVector3f& translate) const
{
return CAABox(mMin + translate, mMax + translate);
}
CAABox CAABox::operator*(float scalar) const
{
return CAABox(mMin * scalar, mMax * scalar);
}
bool CAABox::operator==(const CAABox& Other) const
{
return ((mMin == Other.mMin) && (mMax == Other.mMax));
}
bool CAABox::operator!=(const CAABox& Other)
bool CAABox::operator!=(const CAABox& Other) const
{
return (!(*this == Other));
}

View File

@ -42,8 +42,10 @@ public:
std::pair<bool,float> IntersectsRay(const CRay& Ray) const;
// Operators
bool operator==(const CAABox& Other);
bool operator!=(const CAABox& Other);
CAABox operator+(const CVector3f& translate) const;
CAABox operator*(float scalar) const;
bool operator==(const CAABox& Other) const;
bool operator!=(const CAABox& Other) const;
// Constants
static const CAABox skInfinite;

View File

@ -26,6 +26,9 @@ CModel *CDrawUtil::mpDoubleSidedSphereModel;
CToken CDrawUtil::mSphereToken;
CToken CDrawUtil::mDoubleSidedSphereToken;
CModel *CDrawUtil::mpWireSphereModel;
CToken CDrawUtil::mWireSphereToken;
CShader *CDrawUtil::mpColorShader;
CShader *CDrawUtil::mpColorShaderLighting;
CShader *CDrawUtil::mpBillboardShader;
@ -199,6 +202,28 @@ void CDrawUtil::DrawSphere(const CColor &kColor)
DrawSphere(false);
}
void CDrawUtil::DrawWireSphere(const CVector3f& Position, float Radius, const CColor& Color /*= CColor::skWhite*/)
{
Init();
// Create model matrix
CTransform4f Transform;
Transform.Scale(Radius);
Transform.Translate(Position);
CGraphics::sMVPBlock.ModelMatrix = Transform.ToMatrix4f();
CGraphics::UpdateMVPBlock();
// Set other render params
UseColorShader(Color);
CMaterial::KillCachedMaterial();
glBlendFunc(GL_ONE, GL_ZERO);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDepthMask(GL_TRUE);
// Draw
mpWireSphereModel->Draw(eNoMaterialSetup, 0);
}
void CDrawUtil::DrawBillboard(CTexture* pTexture, const CVector3f& Position, const CVector2f& Scale /*= CVector2f::skOne*/, const CColor& Tint /*= CColor::skWhite*/)
{
Init();
@ -375,6 +400,7 @@ void CDrawUtil::Init()
InitCube();
InitWireCube();
InitSphere();
InitWireSphere();
InitShaders();
InitTextures();
mDrawUtilInitialized = true;
@ -512,6 +538,13 @@ void CDrawUtil::InitSphere()
mDoubleSidedSphereToken = CToken(mpDoubleSidedSphereModel);
}
void CDrawUtil::InitWireSphere()
{
Log::Write("Creating wire sphere");
mpWireSphereModel = (CModel*) gResCache.GetResource("../resources/WireSphere.cmdl");
mWireSphereToken = CToken(mpWireSphereModel);
}
void CDrawUtil::InitShaders()
{
Log::Write("Creating shaders");

View File

@ -38,6 +38,10 @@ class CDrawUtil
static CToken mSphereToken;
static CToken mDoubleSidedSphereToken;
// Wire Sphere
static CModel *mpWireSphereModel;
static CToken mWireSphereToken;
// Shaders
static CShader *mpColorShader;
static CShader *mpColorShaderLighting;
@ -81,6 +85,8 @@ public:
static void DrawSphere(bool DoubleSided = false);
static void DrawSphere(const CColor& Color);
static void DrawWireSphere(const CVector3f& Position, float Radius, const CColor& Color = CColor::skWhite);
static void DrawBillboard(CTexture* pTexture, const CVector3f& Position, const CVector2f& Scale = CVector2f::skOne, const CColor& Tint = CColor::skWhite);
static void DrawLightBillboard(ELightType Type, const CColor& LightColor, const CVector3f& Position, const CVector2f& Scale = CVector2f::skOne, const CColor& Tint = CColor::skWhite);
@ -106,6 +112,7 @@ private:
static void InitCube();
static void InitWireCube();
static void InitSphere();
static void InitWireSphere();
static void InitShaders();
static void InitTextures();

View File

@ -27,20 +27,28 @@ ENodeType CLightNode::NodeType()
void CLightNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
{
if (!ViewInfo.ViewFrustum.BoxInFrustum(AABox())) return;
if (ViewInfo.GameMode) return;
pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawMesh);
if (ViewInfo.ViewFrustum.BoxInFrustum(AABox()))
pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawMesh);
if (IsSelected() && mpLight->GetType() == eCustom)
{
CAABox RadiusBox = (CAABox::skOne * 2.f * mpLight->GetRadius()) + mPosition;
if (ViewInfo.ViewFrustum.BoxInFrustum(RadiusBox))
pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawSelection);
}
}
void CLightNode::Draw(ERenderOptions /*Options*/, int /*ComponentIndex*/, const SViewInfo& ViewInfo)
{
CDrawUtil::DrawLightBillboard(mpLight->GetType(), mpLight->GetColor(), mPosition, BillboardScale(), TintColor(ViewInfo));
}
// Below commented-out code is for light radius visualization as a bounding box
/*float r = mLight->GetRadius();
CAABox AABB(Position + r, Position - r);
pRenderer->DrawBoundingBox(mLight->GetColor(), AABB);*/
void CLightNode::DrawSelection()
{
CDrawUtil::DrawWireSphere(mPosition, mpLight->GetRadius(), mpLight->GetColor());
}
void CLightNode::RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& /*ViewInfo*/)

View File

@ -12,6 +12,7 @@ public:
ENodeType NodeType();
void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo);
void Draw(ERenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo);
void DrawSelection();
void RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo);
SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo);
CLight* Light();

View File

@ -205,6 +205,7 @@ void CDamageableTriggerExtra::Draw(ERenderOptions Options, int /*ComponentIndex*
CGraphics::sPixelBlock.TintColor = mpParent->TintColor(ViewInfo).ToVector4f();
mpMat->SetCurrent(Options);
// Note: The plane the game renders this onto is 5x4.5, which is why we divide the tex coords by this value
CVector2f TexUL(0.f, mCoordScale.y / 4.5f);
CVector2f TexUR(mCoordScale.x / 5.f, mCoordScale.y / 4.5f);
CVector2f TexBR(mCoordScale.x / 5.f, 0.f);

View File

@ -811,6 +811,12 @@ void CModelEditorWindow::on_actionImport_triggered()
aiProcess_RemoveRedundantMaterials |
aiProcess_OptimizeGraph);
if (!pScene)
{
QMessageBox::warning(this, "Error", "Error: Couldn't import file!");
return;
}
CModel *pModel = nullptr;
CMaterialSet *pSet = CMaterialLoader::ImportAssimpMaterials(pScene, ePrime);
pModel = CModelLoader::ImportAssimpNode(pScene->mRootNode, pScene, *pSet);