Skip to content

Commit

Permalink
GuiTexture Canvas
Browse files Browse the repository at this point in the history
Based on http://www.garagegames.com/community/resources/view/10899 Additional note: to cut down on confusion, the UV returned by collisions when enabling    info.generateTexCoord = true; for a RayInfo info; has been altered to          info.mUVtexCoord from info.texCoord to differentiate it from visually mapped UV storage, retrieval, and manipulation to cut down on false positives when code-tracing.
  • Loading branch information
Azaezel committed Jan 5, 2015
1 parent 33a0579 commit a2429f5
Show file tree
Hide file tree
Showing 15 changed files with 793 additions and 16 deletions.
57 changes: 55 additions & 2 deletions Engine/source/T3D/fps/guiCrossHairHud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
#include "T3D/shapeBase.h"
#include "gfx/gfxDrawUtil.h"
#include "console/engineAPI.h"

#include "gui/core/guiTextureCanvas.h"
#include "T3D/tsStatic.h"

//-----------------------------------------------------------------------------
/// Vary basic cross hair hud.
Expand All @@ -54,6 +55,7 @@ class GuiCrossHairHud : public GuiBitmapCtrl
GuiCrossHairHud();

void onRender( Point2I, const RectI &);
bool testGuiInteraction();
static void initPersistFields();
DECLARE_CONOBJECT( GuiCrossHairHud );
DECLARE_CATEGORY( "Gui Game" );
Expand Down Expand Up @@ -110,6 +112,51 @@ void GuiCrossHairHud::initPersistFields()


//-----------------------------------------------------------------------------
bool GuiCrossHairHud::testGuiInteraction()

{
bool interacting = false;
// Must have a connection and player control object
GameConnection* conn = GameConnection::getConnectionToServer();
if (!conn)
return false;
ShapeBase* control = dynamic_cast<ShapeBase*>(conn->getControlObject());
if (!control || !(control->getTypeMask() & ObjectMask) || !conn->isFirstPerson())
return false;

// Get control camera info
MatrixF cam;
Point3F camPos;
conn->getControlCameraTransform(0, &cam);
cam.getColumn(3, &camPos);

// Extend the camera vector to create an endpoint for our ray
Point3F endPos;
cam.getColumn(1, &endPos);
endPos *= GuiTextureCanvas::getRayLength();
endPos += camPos;

// Collision info. We're going to be running LOS tests and we
// don't want to collide with the control object.
static U32 losMask = TerrainObjectType | ShapeBaseObjectType | StaticShapeObjectType;
control->disableCollision();

RayInfo info;
info.generateTexCoord = true;
if (gClientContainer.castRay(camPos, endPos, losMask, &info)) {
// Hit something... but we'll only display health for named
// ShapeBase objects. Could mask against the object type here
// and do a static cast if it's a ShapeBaseObjectType, but this
// isn't a performance situation, so I'll just use dynamic_cast.
if (TSStatic * obj = dynamic_cast<TSStatic*>(info.object))
interacting = GuiTextureCanvas::castRay(obj, camPos, endPos, &info);
}

// Restore control object collision
control->enableCollision();
GuiTextureCanvas::setInteract(interacting, &info);
return interacting;
}

void GuiCrossHairHud::onRender(Point2I offset, const RectI &updateRect)
{
Expand All @@ -121,6 +168,10 @@ void GuiCrossHairHud::onRender(Point2I offset, const RectI &updateRect)
if (!control || !(control->getTypeMask() & ObjectMask) || !conn->isFirstPerson())
return;

//if we're interacting with a gui, skip rendering
if (testGuiInteraction())
return;

// Parent render.
Parent::onRender(offset,updateRect);

Expand All @@ -138,7 +189,7 @@ void GuiCrossHairHud::onRender(Point2I offset, const RectI &updateRect)

// Collision info. We're going to be running LOS tests and we
// don't want to collide with the control object.
static U32 losMask = TerrainObjectType | ShapeBaseObjectType;
static U32 losMask = TerrainObjectType | ShapeBaseObjectType | StaticShapeObjectType;
control->disableCollision();

RayInfo info;
Expand All @@ -148,11 +199,13 @@ void GuiCrossHairHud::onRender(Point2I offset, const RectI &updateRect)
// and do a static cast if it's a ShapeBaseObjectType, but this
// isn't a performance situation, so I'll just use dynamic_cast.
if (ShapeBase* obj = dynamic_cast<ShapeBase*>(info.object))
{
if (obj->getShapeName()) {
offset.x = updateRect.point.x + updateRect.extent.x / 2;
offset.y = updateRect.point.y + updateRect.extent.y / 2;
drawDamage(offset + mDamageOffset, obj->getDamageValue(), 1);
}
}
}

// Restore control object collision
Expand Down
2 changes: 1 addition & 1 deletion Engine/source/T3D/groundPlane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ bool GroundPlane::castRay( const Point3F& start, const Point3F& end, RayInfo* in
info->object = this;
info->distance = 0;
info->faceDot = 0;
info->texCoord.set( 0, 0 );
info->mUVtexCoord.set(0, 0);
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions Engine/source/collision/collision.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct Collision

// If generateTexCoord is set this will either be invalid (-1, -1)
// or a value in texture space (assuming 0..1 UV mapping)
Point2F texCoord;
Point2F mUVtexCoord;

// Face and Face dot are currently only set by the extrudedPolyList
// clipper. Values are otherwise undefined.
Expand All @@ -65,7 +65,7 @@ struct Collision
object( NULL ),
material( NULL ),
generateTexCoord(false),
texCoord(-1.0f, -1.0f)
mUVtexCoord(-1.0f, -1.0f)
{
}
};
Expand Down
6 changes: 6 additions & 0 deletions Engine/source/gui/core/guiCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@

#include "gfx/gfxInit.h"
#include "core/util/journal/process.h"
#include "gui/core/guiTextureCanvas.h"

#ifdef TORQUE_GFX_STATE_DEBUG
#include "gfx/gfxDebugStateTracker.h"
#endif

#include "GuiTextureCanvas.h"

IMPLEMENT_CONOBJECT(GuiCanvas);

ConsoleDocClass( GuiCanvas,
Expand Down Expand Up @@ -1712,6 +1715,9 @@ void GuiCanvas::renderFrame(bool preRenderOnly, bool bufferSwap /* = true */)

bool beginSceneRes = GFX->beginScene();

// Update the offscreen gui texture canvases.
GuiTextureCanvas::updateCanvases();

PROFILE_END();

// Can't render if waiting for device to reset.
Expand Down
Loading

0 comments on commit a2429f5

Please sign in to comment.