JMEditorEnvironment
Loading...
Searching...
No Matches
SimObject Class Reference

#include <SimEnvironment.h>

Public Member Functions

 SimObject (SimObject &)=delete
SimObjectoperator= (const SimObject &)=delete
 SimObject (SimObject &&)=default
SimObjectoperator= (SimObject &&)=default
virtual void display (JMGraphics *gr)
double sizex () const
 Returns object/bounding box size on the X axis.
double sizey () const
 Returns object/bounding box size on the Y axis.
double sizez () const
 Returns object/bounding box size on the Z axis.
glm::dvec3 size () const
 Returns object/bounding box size as a vector.
double posx () const
 Returns the objects position on the X axis.
double posy () const
 Returns the objects position on the Y axis.
double posz () const
 Returns the objects position on the Z axis.
glm::dvec3 pos () const
 Returns the objects position as a vector. Position is at the center of the bounding box.
double rotx () const
 Returns the objects Euler angle on the X axis.
double roty () const
 Returns the objects Euler angle on the Y axis.
double rotz () const
 Returns the objects Euler angle on the Z axis.
glm::dvec3 rot () const
 Returns the objects Euler angle as a vector. Euler angles are always applied in XYZ order.
glm::dquat rotq () const
 Returns the objects angle as a quaternion.
glm::dmat4 positionMatrix () const
 Returns a matrix containing the objects position and rotation transformations.
bool setSize (double x, double y, double z)
 Set the object/bounding box size. Returns true if allowed.
bool setSize (glm::dvec3 size)
 Set the object/bounding box size. Returns true if allowed.
bool setPos (double x, double y, double z)
 Set the objects position. Position is the center of the bounding box. Returns true if allowed.
bool setPos (glm::dvec3 pos)
 Set the objects position. Position is the center of the bounding box. Returns true if allowed.
bool setRot (double x, double y, double z)
 Set the objects rotation from Euler angles. Angles are applied in XYZ order. Returns true if allowed.
bool setRot (glm::dvec3 rot)
 Set the objects rotation from Euler angles. Angles are applied in XYZ order. Returns true if allowed.
bool setRot (glm::dquat rot)
 Set the objects angle from a quaternion. Returns true if allowed.
SimObjectclone ()
 Returns a copy of this object.
virtual void setupMenu1 (TabbedMenu *tabbedMenu)
 Override this to set up the first properties menu.
virtual void setupMenu2 (TabbedMenu *tabbedMenu)
 Override this to set up the second properties menu.
void setupGeneralMenu (TabbedMenu *tabbedMenu)
 Sets up the general settings menu.
void setupDataWindowInternal (JMwindow *window, float dataX, float dataY)
 Is called by the object handler. Calls setupDataWindow if needed.
virtual void setupDataWindow (JMwindow *window, float dataX, float dataY)
virtual void displayDataWindow (JMwindow *window, float localMouseX, float localMouseY, float dataX, float dataY)
 Is called by the object handler to display the data window.
std::string objectCategory () const
 Returns the object category string.
void setupMenus (TabbedMenu *tabbedMenu)
 is called by the object handler if the properties menus are needed.
void save (std::ostream &stream)
 Writes this objects data to a stream. Used to save to a file.
void load (std::istream &stream)
 Reads object data from a stream. Used to load from a file.
void linkObject (SimObject *obj)
 Establishes a two way link with a specific sim object.
void unlinkObject (SimObject *obj)
 Removes the two way link with a specific sim object.
std::vector< SimObject * > allLinkedOjects ()
 Returns all sim objects that are linked with this one.
void reestablishLinks ()
void unlinkAll ()
 Removes all sim object links.

Public Attributes

glm::mat4 renderMatrix = glm::mat4(1.0f)
std::string name = "Object - 001"
 The name that's displayed on the screen and can be set by the user.
std::string menu1Name = "Properties"
 This name is used to label the tabs on the propertiesMenu.
std::string menu2Name = "Properties 2"
 This name is used to label the tabs on the propertiesMenu.
bool isSelected = false
 Is set to true by the SimEnvironment if this is the primary selection. Avoid seting this yourself.
bool isSecondSelected = false
 Is set to true by the SimEnvironment if this is a secondary selection. Avoid seting this yourself.
bool hide = false
 If set to true, the object can't be selected in the viewer and is not rendered.
bool viewportSelectable = true
 Set to false to disable selection in the viewport.
GuiElementHandler * generalMenu = nullptr
 This is displayed in tbe SimEnvironments properties menu if it is set up and displayed. It is created and set up by the SimObject base class.
GuiElementHandler * menu1 = nullptr
GuiElementHandler * menu2 = nullptr
SimEnvironmenthandler = nullptr
 A pointer to the SimEnvironment instance containing this SimObject.

Protected Member Functions

virtual bool readData (std::istream &stream)
virtual bool writeData (std::ostream &stream)
virtual SimObjectcloneInternal ()

Protected Attributes

bool lockSize = false
bool lockPos = false
bool lockRot = false
std::string ObjectCategory = "General"
 This can be used to filter for objects of a specific catagory.
std::string ObjectType = "BASE"
 The object type name used when saving and loading from a file. Must be unique to the derived class.
float dataWinX = 0.0
float dataWinY = 0.0
JMGraphics * graphicsObject = nullptr
 the graphics object used to render the object.

Detailed Description

A base class for sim objects. These can be added to a SimEnvironment. If you want the object to be rendered as anything other than a cube, override display(JMGraphics* gr). If you want settings menus besides the general settings, override setupMenu1(TabbedMenu* tabbedMenu) or setupMenu2(TabbedMenu* tabbedMenu). In these functions, make sure to initialize the correct GuiElementHandler objects (menu1 or menu2). A pointer to the TabbedMenu object that they will appear in is passed as a parameter by the SimEnvironment so that your gui elements can be scaled/position appropriately.

The cloneInternal function must be overridden if you want undo-redo, duplicating and save-load to work correctly. It needs to return a pointer to a copy of itself, only set the copies data that is specific to the subclass, base class data is handled by a wrapper function.

For saving and loading from a file to work, the objectType string must be set in the constructor to something unique to the derived class, and it must be added using the simEnvironments registerDerivedSimObject function. readData() and writeData() functions must be overriden to read and write data unique to the derived class in order to save and load from a file. Saving and loading base data is handled by the save and load wrapper functions.

Member Function Documentation

◆ cloneInternal()

virtual SimObject * SimObject::cloneInternal ( )
protectedvirtual

Override this to clone all derived class data. Must return a pointer to the new object. Does not need to write base class data to the clone.

◆ display()

virtual void SimObject::display ( JMGraphics * gr)
virtual

Render the object in the parameter graphics object. Does not apply tranforms for this object, transform the graphics objects matrix using this objects positionMatrix function first, or it will be rendered at 0, 0, 0 with no rotation.

◆ readData()

virtual bool SimObject::readData ( std::istream & stream)
protectedvirtual

Reads data for loading from a file. Override this and read only data unique to the derived class. Base class data is read by wrapper function.

◆ reestablishLinks()

void SimObject::reestablishLinks ( )

Will try to re link all previously linked sim objects. If sim objects are cloned or loaded from a file, link pointers are cleared so this must be called.

◆ setupDataWindow()

virtual void SimObject::setupDataWindow ( JMwindow * window,
float dataX,
float dataY )
virtual

Sets up the data window that the object can render to. Inputs are the windows size. coordinates 0, 0 will be the center of the window. Note: this may be called multiple times if the user re-sizes the data window.

◆ writeData()

virtual bool SimObject::writeData ( std::ostream & stream)
protectedvirtual

Writes data for saving to a file. Override this and write only data unique to the derived class. Base class data is written by wrapper function.

Member Data Documentation

◆ renderMatrix

glm::mat4 SimObject::renderMatrix = glm::mat4(1.0f)

A stored copy of the render engines transformation matrix when the object was last rendered. This includes all object transformations, and view/camera transformations. All transormations are done in pixel coordinates, not NDC.


The documentation for this class was generated from the following file: