Wraith  0.1.5
Basic 3D game engine in C++
Visualizer

The Visualizer is used for visualizing many things such as the Collision Volume of a Game Object, points in space, line segments, and rays. More...

Collaboration diagram for Visualizer:

Functions

static void Visualizer::ShowCollisionVolume (const CollisionVolume &collisionVolume)
 Shows the Collision Volume to be rendered. More...
 
static void Visualizer::ShowCollisionVolume (const CollisionVolume &collisionVolume, const Vect &color)
 Shows the Collision Volume to be rendered. More...
 
static void Visualizer::ShowCollisionVolume (const CollisionVolume &collisionVolume, const Vect &color, int depth)
 Shows the Collision Volume to be rendered. More...
 
static void Visualizer::ShowRay (const Vect &start, const Vect &direction, float length, const Vect &color=Visualizer::DEFAULT_COLOR)
 Shows a ray in space to be rendered. More...
 
static void Visualizer::ShowRay (const Vect &start, const Vect &direction, const Vect &color=Visualizer::DEFAULT_COLOR)
 Shows a ray in space to be rendered. More...
 
static void Visualizer::ShowPointAt (const Vect &position, const Vect &color=Visualizer::DEFAULT_COLOR)
 Shows a point in space to be rendered. More...
 
static void Visualizer::ShowLineSegment (const Vect &position_1, const Vect &position_2, const Vect &color=Visualizer::DEFAULT_COLOR)
 Shows a line segment in space to be rendered. More...
 

Detailed Description

The Visualizer is used for visualizing many things such as the Collision Volume of a Game Object, points in space, line segments, and rays.

The Visualizer is a tool for the user to use to for visualzing collider model. This can aid in debugging collisions. To use it you must include Visualizer.h header file. You may pass in a Vector for the color or use the Colors namespace for using preset color.

Here are some methods that you may want to call (shown with some input examples)

- Visualizer::ShowCollisionVolume(this->Collidable::getCollisionVolume(), Colors::Red) -> or any other color from Color namespace.
- Visualizer::ShowCollisionVolume(this->Collidable::getCollisionVolume(), Colors::Blue, 4) -> Depth value only used for Octree.
- Visualizer::ShowRay(myPosition, moveDirection, Colors::Red) -> ray length based on moveDirection vector length
- Visualizer::ShowRay(myPosition, moveDirection, 8, Colors::Red) -> ray length set to 8 due to extra length parameter
- Visualizer::ShowPointAt(myPosition, Color::Green);
- Visualizer::ShowLineSegment(myPosition, targetPosition, Colors::Blue);
const CollisionVolume & getCollisionVolume() const
Gets the current collsion volume being used.
Definition: Collidable.cpp:32
static void ShowRay(const Vect &start, const Vect &direction, float length, const Vect &color=Visualizer::DEFAULT_COLOR)
Shows a ray in space to be rendered.
Definition: Visualizer.h:211
static void ShowCollisionVolume(const CollisionVolume &collisionVolume)
Shows the Collision Volume to be rendered.
Definition: Visualizer.h:168
static void ShowPointAt(const Vect &position, const Vect &color=Visualizer::DEFAULT_COLOR)
Shows a point in space to be rendered.
Definition: Visualizer.h:238
static void ShowLineSegment(const Vect &position_1, const Vect &position_2, const Vect &color=Visualizer::DEFAULT_COLOR)
Shows a line segment in space to be rendered.
Definition: Visualizer.h:252

Here is an example of how this can be used for debugging collisions.

#include "Visualizer.h"
#include "Colors.h"
// NOTE: Tank class has a bool variable call _hasCollidedDebug which is used
// for visualizing a collision with color change
Tank::Tank()
{
// IMPORTANT: Set collidable group here using the class type of the object.
// Also set collider model
GameObject::setCollidableGroup<Tank>();
GameObject::setColliderModel(_pTankModel, VolumeType::OBB);
// Submit Registration
}
void Tank::update()
{
// IMPORTANT: For objects with changing world matrix (translating, rotating, scaling)
// A call to update collider data must be made
this->move(); // call to move changes position thus changes world matrix
// This is where the Visualizer tool is used AFTER updating collision data
if(_hasCollidedDebug) // if it has collided show red sphere
{
// Colors::Red is just a Vect object.
// You may pass in Vect object or use Colors namespace for quick access to colors
}
else // else show blue sphere
{
}
// Set _hasCollidedDebug to false afterwards
_hasCollidedDebug = false;
}
void Tank::collision(Tank* pTank)
{
// In any collision callback set _hasCollidedDebug to true
_hasCollidedDebug = true;
}
void Tank::collision(Bullet* pBullet)
{
// In any collision callback set _hasCollidedDebug to true
_hasCollidedDebug = true;
}
void submitCollisionRegistration()
Submit collision registration to current scene.
Definition: Collidable.cpp:80
void setColliderModel(Model *pColliderModel, VolumeType volumeType)
Sets collider model and Collision Volume type.
Definition: Collidable.cpp:37
void updateCollisionData(const Matrix &world)
Updates the collision data described by world matrix.
Definition: Collidable.cpp:71
void submitUpdateRegistration()
Submit update registration to current scene.
Definition: Updatable.cpp:24

Here is an example of how this can be used for debugging collisions with Octree.

#include "Visualizer.h"
#include "Colors.h"
#include "MathTools.h"
// NOTE: WindMill class has a bool variable call _hasCollidedDebug which is used
// for visualizing a collision with color change
WindMill::WindMill()
{
// IMPORTANT: Set collidable group here using the class type of the object.
// Also set collider model
GameObject::setCollidableGroup<WindMill>();
GameObject::setColliderModel(_pWindMillModel, VolumeHierarchyType::OCTREE, 4);
// Submit Registration
// Keys used for changing render levels
submitKeyRegistration(AZUL_KEY::KEY_1, InputEvent::KEY_PRESS);
submitKeyRegistration(AZUL_KEY::KEY_2, InputEvent::KEY_PRESS);
_renderLevel = 0;
}
void WindMill::update()
{
// This is where the Visualizer tool is used AFTER updating collision data
if(_hasCollidedDebug) // if it has collided show red sphere
{
// Colors::Red is just a Vect object.
// You may pass in Vect object or use Colors namespace for quick access to colors
}
else // else show blue sphere
{
}
// Set _hasCollidedDebug to false afterwards
_hasCollidedDebug = false;
}
void WindMill::collision(Tank* pTank)
{
// In any collision callback set _hasCollidedDebug to true
_hasCollidedDebug = true;
}
void WindMill::collision(Bullet* pBullet)
{
// In any collision callback set _hasCollidedDebug to true
_hasCollidedDebug = true;
}
// Used for changing render level my clamping value
// between 0 and the max depth through getCollisionVolume.getMaxDepth()
void WindMill::keyPressed(AZUL_KEY key)
{
if (key == AZUL_KEY::KEY_1) _renderLevel -= 1;
if (key == AZUL_KEY::KEY_2) _renderLevel += 1;
_renderLevel = MathTools::Clamp(_renderLevel, 0, getCollisionVolume().getMaxDepth());
}
Vect Clamp(const Vect &value, const Vect &min, const Vect &max)
Clamps the given Vect .
Definition: MathTools.cpp:595

Here is another example of how the visualizing the point, line segment, and ray could be used.

#include "Visualizer.h"
#include "Colors.h"
Tank::Tank()
{
// IMPORTANT: Set collidable group here using the class type of the object.
// Also set collider model
GameObject::setCollidableGroup<Tank>();
// Submit Registration
}
void Tank::update()
{
// Visualize the current direction of the tank
Vect moveDirection = getMoveDirection();
Vect position = getPosition();
Visualizer::ShowRay(position, moveDirection, Colors::Red);
// Visualize the leading point in front of the target to shoot at.
Tank* pTarget = getTarget();
Vect leadingPoint = computeLeadingPoint(pTarget);
Visualizer::ShowPointAt(leadingPoint, Color::Green);
// Visualizing the line of slight between tank and target
Vect myPosition = getPosition();
Vect targetPosition = pTarget->getPosition();
Visualizer::ShowLineSegment(myPosition, targetPosition, Colors::Blue);
}

Function Documentation

◆ ShowCollisionVolume() [1/3]

static void Visualizer::ShowCollisionVolume ( const CollisionVolume collisionVolume)
inlinestatic

Shows the Collision Volume to be rendered.

Depth is only used for Octree Collision models. All other collsion volumes ignore depth value.

Parameters
collisionVolumeThe collision volume.

◆ ShowCollisionVolume() [2/3]

static void Visualizer::ShowCollisionVolume ( const CollisionVolume collisionVolume,
const Vect &  color 
)
inlinestatic

Shows the Collision Volume to be rendered.

Parameters
collisionVolumeThe collision volume.
colorThe color.

◆ ShowCollisionVolume() [3/3]

static void Visualizer::ShowCollisionVolume ( const CollisionVolume collisionVolume,
const Vect &  color,
int  depth 
)
inlinestatic

Shows the Collision Volume to be rendered.

Depth is only used for Octree Collision models. All other collsion volumes ignore depth value.

Parameters
collisionVolumeThe collision volume.
colorThe color.
depthThe depth.

◆ ShowLineSegment()

static void Visualizer::ShowLineSegment ( const Vect &  position_1,
const Vect &  position_2,
const Vect &  color = Visualizer::DEFAULT_COLOR 
)
inlinestatic

Shows a line segment in space to be rendered.

Parameters
position_1The position of the segment.
position_2The position of the segment.
color(Optional) The color.

◆ ShowPointAt()

static void Visualizer::ShowPointAt ( const Vect &  position,
const Vect &  color = Visualizer::DEFAULT_COLOR 
)
inlinestatic

Shows a point in space to be rendered.

Parameters
positionThe position of the point.
color(Optional) The color.

◆ ShowRay() [1/2]

static void Visualizer::ShowRay ( const Vect &  start,
const Vect &  direction,
const Vect &  color = Visualizer::DEFAULT_COLOR 
)
inlinestatic

Shows a ray in space to be rendered.

The length is determined by the direction.

Parameters
startThe position of the segment.
directionThe position of the segment.
color(Optional) The color.

◆ ShowRay() [2/2]

static void Visualizer::ShowRay ( const Vect &  start,
const Vect &  direction,
float  length,
const Vect &  color = Visualizer::DEFAULT_COLOR 
)
inlinestatic

Shows a ray in space to be rendered.

By using the length, direction is normalized

Parameters
startThe position of the segment.
directionThe position of the segment.
lengthlength of ray.
color(Optional) The color.