From 3cec0f9d98af1b831ffe20beefde4116c1994409 Mon Sep 17 00:00:00 2001 From: Azaezel Date: Tue, 27 Mar 2018 14:57:23 -0500 Subject: [PATCH 1/3] augmentation to drawArrow to allow one to explicitly define a radius. --- Engine/source/gfx/gfxDrawUtil.cpp | 8 ++++---- Engine/source/gfx/gfxDrawUtil.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Engine/source/gfx/gfxDrawUtil.cpp b/Engine/source/gfx/gfxDrawUtil.cpp index 0e7a4b3e9..ac25b3f15 100644 --- a/Engine/source/gfx/gfxDrawUtil.cpp +++ b/Engine/source/gfx/gfxDrawUtil.cpp @@ -1382,7 +1382,7 @@ void GFXDrawUtil::drawCylinder( const GFXStateBlockDesc &desc, const Point3F &ba mDevice->popWorldMatrix(); } -void GFXDrawUtil::drawArrow( const GFXStateBlockDesc &desc, const Point3F &start, const Point3F &end, const ColorI &color ) +void GFXDrawUtil::drawArrow( const GFXStateBlockDesc &desc, const Point3F &start, const Point3F &end, const ColorI &color, F32 baseRad ) { GFXTransformSaver saver; @@ -1398,8 +1398,8 @@ void GFXDrawUtil::drawArrow( const GFXStateBlockDesc &desc, const Point3F &start // Calculate the radius of the cone given that we want the cone to have // an angle of 25 degrees (just because it looks good). - F32 coneLen = ( end - coneBase ).len(); - F32 coneDiameter = mTan( mDegToRad(25.0f) ) * coneLen; + F32 coneLen = (baseRad != 0.0f) ? baseRad * 4.0 :( end - coneBase ).len(); + F32 coneDiameter = (baseRad != 0.0f) ? baseRad*4.0f : mTan( mDegToRad(25.0f) ) * coneLen; // Draw the cone on at the arrow's tip. drawCone( desc, coneBase, end, coneDiameter / 2.0f, color ); @@ -1412,7 +1412,7 @@ void GFXDrawUtil::drawArrow( const GFXStateBlockDesc &desc, const Point3F &start Point3F coneDiff = end - coneBase; // Draw the cylinder. - F32 stickRadius = len * 0.025f; + F32 stickRadius = (baseRad != 0.0f) ? baseRad : len * 0.025f; drawCylinder( desc, start, end - coneDiff, stickRadius, color ); } diff --git a/Engine/source/gfx/gfxDrawUtil.h b/Engine/source/gfx/gfxDrawUtil.h index 7decad785..47f6581cf 100644 --- a/Engine/source/gfx/gfxDrawUtil.h +++ b/Engine/source/gfx/gfxDrawUtil.h @@ -115,7 +115,7 @@ public: void drawCapsule( const GFXStateBlockDesc &desc, const Point3F ¢er, F32 radius, F32 height, const ColorI &color, const MatrixF *xfm = NULL ); void drawCone( const GFXStateBlockDesc &desc, const Point3F &basePnt, const Point3F &tipPnt, F32 baseRadius, const ColorI &color ); void drawCylinder( const GFXStateBlockDesc &desc, const Point3F &basePnt, const Point3F &tipPnt, F32 baseRadius, const ColorI &color ); - void drawArrow( const GFXStateBlockDesc &desc, const Point3F &start, const Point3F &end, const ColorI &color ); + void drawArrow( const GFXStateBlockDesc &desc, const Point3F &start, const Point3F &end, const ColorI &color, F32 baseRad = 0.0f); void drawFrustum( const Frustum& f, const ColorI &color ); /// Draw a solid or wireframe (depending on fill mode of @a desc) polyhedron with the given color. From 80e34d88a0931aaf8916c720e196813e6627cb0c Mon Sep 17 00:00:00 2001 From: Azaezel Date: Tue, 27 Mar 2018 14:58:40 -0500 Subject: [PATCH 2/3] visualization augmentations for PhysicalZone. colorizes based on force vector, scales based on lengths --- Engine/source/T3D/physicalZone.cpp | 89 +++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 15 deletions(-) diff --git a/Engine/source/T3D/physicalZone.cpp b/Engine/source/T3D/physicalZone.cpp index f8454be5b..cd7da39d0 100644 --- a/Engine/source/T3D/physicalZone.cpp +++ b/Engine/source/T3D/physicalZone.cpp @@ -212,8 +212,10 @@ void PhysicalZone::onRemove() void PhysicalZone::inspectPostApply() { - setPolyhedron(mPolyhedron); Parent::inspectPostApply(); + + setPolyhedron(mPolyhedron); + setMaskBits(PolyhedronMask | MoveMask | SettingsMask | FadeMask); } //------------------------------------------------------------------------------ @@ -248,30 +250,87 @@ void PhysicalZone::prepRenderImage( SceneRenderState *state ) } -void PhysicalZone::renderObject( ObjectRenderInst *ri, - SceneRenderState *state, - BaseMatInstance *overrideMat ) +void PhysicalZone::renderObject(ObjectRenderInst *ri, + SceneRenderState *state, + BaseMatInstance *overrideMat) { if (overrideMat) return; - + GFXStateBlockDesc desc; - desc.setZReadWrite( true, false ); - desc.setBlend( true ); - desc.setCullMode( GFXCullNone ); - + desc.setZReadWrite(true, false); + desc.setBlend(true); + desc.setCullMode(GFXCullNone); + GFXTransformSaver saver; + + GFXDrawUtil *drawer = GFX->getDrawUtil(); + + Point3F start = getBoxCenter(); + Box3F obb = mObjBox; //object bounding box + + F32 baseForce = 10000; //roughly the ammount of force needed to push a player back as it walks into a zone. (used for visual scaling) + + Point3F forceDir = getForce(&start); + F32 forceLen = forceDir.len()/ baseForce; + forceDir.normalizeSafe(); + ColorI guideCol = LinearColorF(mFabs(forceDir.x), mFabs(forceDir.y), mFabs(forceDir.z), 0.125).toColorI(); + + if (force_type == VECTOR) + { + Point3F endPos = start + (forceDir * mMax(forceLen,0.75f)); + drawer->drawArrow(desc, start, endPos, guideCol, 0.05f); + } MatrixF mat = getRenderTransform(); - mat.scale( getScale() ); + mat.scale(getScale()); + + GFX->multWorld(mat); + start = obb.getCenter(); + + if (force_type == VECTOR) + { + drawer->drawPolyhedron(desc, mPolyhedron, ColorI(0, 255, 0, 45)); + } + else if (force_type == SPHERICAL) + { + F32 rad = obb.getBoundingSphere().radius/ 2; + drawer->drawSphere(desc, rad, start, ColorI(0, 255, 0, 45)); - GFX->multWorld( mat ); + rad = (rad + forceLen / 2)/2; + desc.setFillModeWireframe(); + drawer->drawSphere(desc, rad, start, ColorI(0, 0, 255, 255)); + } + else + { + Point3F bottomPos = start; + bottomPos.z -= obb.len_z() / 2; + + Point3F topPos = start; + topPos.z += obb.len_z() / 2; + F32 rad = obb.len_x() / 2; + drawer->drawCylinder(desc, bottomPos, topPos, rad, ColorI(0, 255, 0, 45)); - GFXDrawUtil *drawer = GFX->getDrawUtil(); - drawer->drawPolyhedron( desc, mPolyhedron, ColorI( 0, 255, 0, 45 ) ); + Point3F force_vec = mAppliedForce; //raw relative-applied force here as oposed to derived + F32 hieght = (force_vec.z / baseForce); + if (force_vec.z<0) + bottomPos.z = (bottomPos.z + hieght)/2; + else + topPos.z = (topPos.z + hieght) / 2; + + if (force_vec.x > force_vec.y) + rad = (rad + (force_vec.x / baseForce)) / 2; + else + rad = (rad + (force_vec.y / baseForce)) / 2; + + + desc.setFillModeWireframe(); + drawer->drawCylinder(desc, bottomPos, topPos, rad, guideCol); + } + desc.setFillModeWireframe(); - drawer->drawPolyhedron( desc, mPolyhedron, ColorI::BLACK ); + drawer->drawPolyhedron(desc, mPolyhedron, ColorI::BLACK); } //-------------------------------------------------------------------------- @@ -325,7 +384,7 @@ U32 PhysicalZone::packUpdate(NetConnection* con, U32 mask, BitStream* stream) stream->writeFlag(mActive); - return retMask; + return retMask; } void PhysicalZone::unpackUpdate(NetConnection* con, BitStream* stream) From 04444104864e218d1dc69940a2b360b6e043d326 Mon Sep 17 00:00:00 2001 From: Azaezel Date: Tue, 27 Mar 2018 20:25:46 -0500 Subject: [PATCH 3/3] retooled spherical force ammount display to be based on mAppliedForce --- Engine/source/T3D/physicalZone.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/source/T3D/physicalZone.cpp b/Engine/source/T3D/physicalZone.cpp index cd7da39d0..fac190b67 100644 --- a/Engine/source/T3D/physicalZone.cpp +++ b/Engine/source/T3D/physicalZone.cpp @@ -297,7 +297,7 @@ void PhysicalZone::renderObject(ObjectRenderInst *ri, F32 rad = obb.getBoundingSphere().radius/ 2; drawer->drawSphere(desc, rad, start, ColorI(0, 255, 0, 45)); - rad = (rad + forceLen / 2)/2; + rad = (rad + (mAppliedForce.most() / baseForce))/2; desc.setFillModeWireframe(); drawer->drawSphere(desc, rad, start, ColorI(0, 0, 255, 255)); }