notesObject.cpp
Engine/source/T3D/notesObject.cpp
Public Variables
bool
For frame signal.
Public Functions
Detailed Description
Public Variables
bool gEditingMission
For frame signal.
Public Functions
IMPLEMENT_CO_NETOBJECT_V1(NotesObject )
1 2#include "T3D/notesObject.h" 3 4#include "math/mathIO.h" 5#include "scene/sceneRenderState.h" 6#include "core/stream/bitStream.h" 7#include "materials/sceneData.h" 8#include "gfx/gfxDebugEvent.h" 9#include "gfx/gfxTransformSaver.h" 10#include "renderInstance/renderPassManager.h" 11#include "math/mathUtils.h" 12#include "gfx/gfxDrawUtil.h" 13 14IMPLEMENT_CO_NETOBJECT_V1(NotesObject); 15 16extern bool gEditingMission; 17 18//----------------------------------------------------------------------------- 19// Object setup and teardown 20//----------------------------------------------------------------------------- 21NotesObject::NotesObject() 22{ 23 // Flag this object so that it will always 24 // be sent across the network to clients 25 mNetFlags.set(Ghostable | ScopeAlways); 26 27 // Set it as a "static" object 28 mTypeMask |= StaticObjectType | StaticShapeObjectType; 29 30 mShowArrow = true; 31 mArrowLength = 5; 32 mArrowRadius = 0.25; 33} 34 35NotesObject::~NotesObject() 36{ 37} 38 39//----------------------------------------------------------------------------- 40// Object Editing 41//----------------------------------------------------------------------------- 42void NotesObject::initPersistFields() 43{ 44 Parent::initPersistFields(); 45 46 addField("Note", TypeCommand, Offset(mNote, NotesObject), ""); 47 48 addField("showArrow", TypeBool, Offset(mShowArrow, NotesObject), ""); 49 50 addField("arrowColor", TypeColorF, Offset(mArrowColor, NotesObject), ""); 51} 52 53void NotesObject::inspectPostApply() 54{ 55 // Apply any transformations set in the editor 56 Parent::inspectPostApply(); 57 58 if (isServerObject()) 59 { 60 setMaskBits(-1); 61 } 62} 63 64bool NotesObject::onAdd() 65{ 66 if (!Parent::onAdd()) 67 return false; 68 69 // Set up a 1x1x1 bounding box 70 mObjBox.set(Point3F(-0.5f, -0.5f, -0.5f), 71 Point3F(0.5f, 0.5f, 0.5f)); 72 73 resetWorldBox(); 74 75 // Add this object to the scene 76 addToScene(); 77 78 return true; 79} 80 81void NotesObject::onRemove() 82{ 83 // Remove this object from the scene 84 removeFromScene(); 85 86 Parent::onRemove(); 87} 88 89void NotesObject::setTransform(const MatrixF& mat) 90{ 91 // Let SceneObject handle all of the matrix manipulation 92 Parent::setTransform(mat); 93 94 // Dirty our network mask so that the new transform gets 95 // transmitted to the client object 96 setMaskBits(TransformMask); 97} 98 99U32 NotesObject::packUpdate(NetConnection* conn, U32 mask, BitStream* stream) 100{ 101 // Allow the Parent to get a crack at writing its info 102 U32 retMask = Parent::packUpdate(conn, mask, stream); 103 104 // Write our transform information 105 //if (stream->writeFlag(mask & TransformMask)) 106 { 107 mathWrite(*stream, getTransform()); 108 mathWrite(*stream, getScale()); 109 stream->write(mShowArrow); 110 111 stream->write(mArrowColor); 112 } 113 114 return retMask; 115} 116 117void NotesObject::unpackUpdate(NetConnection* conn, BitStream* stream) 118{ 119 // Let the Parent read any info it sent 120 Parent::unpackUpdate(conn, stream); 121 122 //if (stream->readFlag()) // TransformMask 123 { 124 mathRead(*stream, &mObjToWorld); 125 mathRead(*stream, &mObjScale); 126 127 setTransform(mObjToWorld); 128 129 stream->read(&mShowArrow); 130 stream->read(&mArrowColor); 131 } 132} 133 134void NotesObject::prepRenderImage(SceneRenderState* state) 135{ 136 if (!gEditingMission) 137 return; 138 139 ObjectRenderInst* ri = state->getRenderPass()->allocInst<ObjectRenderInst>(); 140 ri->renderDelegate.bind(this, &NotesObject::_render); 141 ri->type = RenderPassManager::RIT_Editor; 142 state->getRenderPass()->addInst(ri); 143} 144 145void NotesObject::_render(ObjectRenderInst* ri, SceneRenderState* state, BaseMatInstance* overrideMat) 146{ 147 if (showArrow()) 148 { 149 GFXStateBlockDesc desc; 150 desc.setBlend(true); 151 desc.setZReadWrite(true, false); 152 153 VectorF forwardVec = getTransform().getForwardVector(); 154 forwardVec.normalize(); 155 156 Point3F startPos = forwardVec * -(mArrowLength * 0.5) + getPosition(); 157 Point3F endPos = forwardVec * (mArrowLength * 0.5) + getPosition(); 158 159 ColorI arrowColor = mArrowColor.toColorI(); 160 arrowColor.alpha = 128; 161 162 GFX->getDrawUtil()->drawArrow(desc, startPos, endPos, arrowColor, mArrowRadius); 163 } 164} 165