notesObject.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #pragma once
  2. #ifndef _SCENEOBJECT_H_
  3. #include "scene/sceneObject.h"
  4. #endif
  5. #ifndef _GFXSTATEBLOCK_H_
  6. #include "gfx/gfxStateBlock.h"
  7. #endif
  8. #ifndef _GFXVERTEXBUFFER_H_
  9. #include "gfx/gfxVertexBuffer.h"
  10. #endif
  11. #ifndef _GFXPRIMITIVEBUFFER_H_
  12. #include "gfx/gfxPrimitiveBuffer.h"
  13. #endif
  14. //-----------------------------------------------------------------------------
  15. // This class implements a basic SceneObject that can exist in the world at a
  16. // 3D position and render itself. Note that NotesObject handles its own
  17. // rendering by submitting itself as an ObjectRenderInst (see
  18. // renderInstance\renderPassmanager.h) along with a delegate for its render()
  19. // function. However, the preffered rendering method in the engine is to submit
  20. // a MeshRenderInst along with a Material, vertex buffer, primitive buffer, and
  21. // transform and allow the RenderMeshMgr handle the actual rendering. You can
  22. // see this implemented in RenderMeshExample.
  23. //-----------------------------------------------------------------------------
  24. class NotesObject : public SceneObject
  25. {
  26. typedef SceneObject Parent;
  27. String mNote;
  28. bool mShowArrow;
  29. F32 mArrowLength;
  30. F32 mArrowRadius;
  31. LinearColorF mArrowColor;
  32. // Networking masks
  33. // We need to implement at least one of these to allow
  34. // the client version of the object to receive updates
  35. // from the server version (like if it has been moved
  36. // or edited)
  37. enum MaskBits
  38. {
  39. TransformMask = Parent::NextFreeMask << 0,
  40. NextFreeMask = Parent::NextFreeMask << 1
  41. };
  42. //--------------------------------------------------------------------------
  43. // Rendering variables
  44. //--------------------------------------------------------------------------
  45. // Define our vertex format here so we don't have to
  46. // change it in multiple spots later
  47. typedef GFXVertexPCN VertexType;
  48. // The handles for our StateBlocks
  49. GFXStateBlockRef mNormalSB;
  50. GFXStateBlockRef mReflectSB;
  51. // The GFX vertex and primitive buffers
  52. GFXVertexBufferHandle< VertexType > mVertexBuffer;
  53. public:
  54. NotesObject();
  55. virtual ~NotesObject();
  56. // Declare this object as a ConsoleObject so that we can
  57. // instantiate it into the world and network it
  58. DECLARE_CONOBJECT(NotesObject);
  59. //--------------------------------------------------------------------------
  60. // Object Editing
  61. // Since there is always a server and a client object in Torque and we
  62. // actually edit the server object we need to implement some basic
  63. // networking functions
  64. //--------------------------------------------------------------------------
  65. // Set up any fields that we want to be editable (like position)
  66. static void initPersistFields();
  67. void inspectPostApply();
  68. // Handle when we are added to the scene and removed from the scene
  69. bool onAdd();
  70. void onRemove();
  71. // Override this so that we can dirty the network flag when it is called
  72. void setTransform(const MatrixF& mat);
  73. // This function handles sending the relevant data from the server
  74. // object to the client object
  75. U32 packUpdate(NetConnection* conn, U32 mask, BitStream* stream);
  76. // This function handles receiving relevant data from the server
  77. // object and applying it to the client object
  78. void unpackUpdate(NetConnection* conn, BitStream* stream);
  79. // This is the function that allows this object to submit itself for rendering
  80. void prepRenderImage(SceneRenderState* state);
  81. void _render(ObjectRenderInst* ri, SceneRenderState* state, BaseMatInstance* overrideMat);
  82. String getNote() { return mNote; }
  83. bool showArrow() { return mShowArrow; }
  84. };