32 #define MAX_GL_TEXTURE_IDS 0x10000
33 #define MAX_GL_TEXTURE_IDS_MASK 0x0FFFF
58 CRenderizable::CRenderizable() :
61 m_color(255,255,255,255),
63 m_scale_x(1), m_scale_y(1), m_scale_z(1),
85 unsigned int ret = booker.next_free_texture;
86 unsigned int tries = 0;
87 while (ret!=0 && booker.freeTextureNames[ret])
96 booker.freeTextureNames[ret] =
true;
97 booker.next_free_texture = ret+1;
123 const uint8_t serialization_version = 0;
126 const bool all_scales_unity = (all_scales_equal &&
m_scale_x==1.0f);
128 const uint8_t magic_signature[2] = {
133 static_cast<uint8_t>( serialization_version | (all_scales_unity ? 0xC0 : (all_scales_equal ? 0xA0 : 0x80) ) )
136 out << magic_signature[0] << magic_signature[1];
150 if (!all_scales_unity)
152 if (all_scales_equal)
173 in >> magic_signature[0] >> magic_signature[1];
175 const bool is_new_format = (magic_signature[0]==0xFF) && ((magic_signature[1]&0x80)!=0);
180 uint8_t serialization_version = (magic_signature[1] & 0x1F);
181 const bool all_scales_unity = ((magic_signature[1]&0x40)!=0);
182 const bool all_scales_equal_but_not_unity = ((magic_signature[1]&0x20)!=0);
184 switch(serialization_version)
203 if (all_scales_unity)
206 if (all_scales_equal_but_not_unity)
219 THROW_EXCEPTION_FMT(
"Can't parse CRenderizable standard data field: corrupt data stream or format in a newer MRPT format? (serialization version=%u)",
static_cast<unsigned int>(serialization_version))
227 in >> magic_signature[2] >> magic_signature[3];
229 const uint32_t nameLen = magic_signature_uint32;
236 float yaw_deg,pitch_deg,roll_deg;
239 in >> col.
R >> col.
G >> col.
B >> col.
A;
247 in >> f; roll_deg = f;
250 if (f!=16.0f && f!=17.0f)
#define MAX_GL_TEXTURE_IDS
#define MAX_GL_TEXTURE_IDS_MASK
#define IMPLEMENTS_VIRTUAL_SERIALIZABLE(class_name, base_class_name, NameSpace)
This must be inserted as implementation of some required members for virtual CSerializable classes:
The base class of 3D objects that can be directly rendered through OpenGL.
static void releaseTextureName(unsigned int i)
float m_scale_z
Scale components to apply to the object (default=1)
mrpt::poses::CPose3D m_pose
6D pose wrt the parent coordinate reference. This class automatically holds the cached 3x3 rotation m...
static unsigned int getNewTextureNumber()
Returns the lowest next free texture name (avoid using OpenGL's own function since we may call them f...
virtual CRenderizable & setColor_u8(const mrpt::utils::TColor &c)
static int textBitmapWidth(const std::string &str, mrpt::opengl::TOpenGLFont font=mrpt::opengl::MRPT_GLUT_BITMAP_TIMES_ROMAN_24)
Return the exact width in pixels for a given string, as will be rendered by renderTextBitmap().
bool m_visible
Is the object visible? (default=true)
void writeToStreamRender(utils::CStream &out) const
static void renderTextBitmap(const char *str, void *fontStyle)
This method is safe for calling from within ::render() methods.
virtual bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const
Simulation of ray-trace, given a pose.
static void checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
void readFromStreamRender(utils::CStream &in)
CRenderizable & setPose(const mrpt::poses::CPose3D &o)
Set the 3D pose from a mrpt::poses::CPose3D object (return a ref to this)
mrpt::math::TPose3D getPose() const
Returns the 3D pose of the object as TPose3D.
mrpt::utils::TColor m_color
Color components in the range [0,255].
A class used to store a 2D point.
A class used to store a 3D point.
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
double pitch() const
Get the PITCH angle (in radians)
double roll() const
Get the ROLL angle (in radians)
void setFromValues(const double x0, const double y0, const double z0, const double yaw=0, const double pitch=0, const double roll=0)
Set the pose from a 3D position (meters) and yaw/pitch/roll angles (radians) - This method recomputes...
double yaw() const
Get the YAW angle (in radians)
void setYawPitchRoll(const double yaw_, const double pitch_, const double roll_)
Set the 3 angles of the 3D pose (in radians) - This method recomputes the internal rotation coordinat...
double x() const
Common members of all points & poses classes.
A class acquiring a CCriticalSection at its constructor, and releasing it at destructor.
Recursive mutex: allow recursive locks by the owner thread.
The virtual base class which provides a unified interface for all persistent objects in MRPT.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
void WriteBuffer(const void *Buffer, size_t Count)
Writes a block of bytes to the stream from Buffer.
GLdouble GLdouble GLdouble r
GLsizei const GLchar ** string
TOpenGLFont
Existing fonts for 2D texts in mrpt::opengl methods.
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
int OPENGL_IMPEXP textBitmapWidth(const std::string &str, mrpt::opengl::TOpenGLFont font=mrpt::opengl::MRPT_GLUT_BITMAP_TIMES_ROMAN_24)
Return the exact width in pixels for a given string, as will be rendered by renderTextBitmap().
void OPENGL_IMPEXP checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
void OPENGL_IMPEXP renderTextBitmap(const char *str, void *fontStyle)
This method is safe for calling from within ::render() methods.
The namespace for 3D scene representation and rendering.
OPENGL_IMPEXP mrpt::utils::CStream & operator<<(mrpt::utils::CStream &out, const mrpt::opengl::CLight &o)
This namespace provides multitask, synchronization utilities.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values,...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
unsigned __int16 uint16_t
unsigned __int32 uint32_t
synch::CCriticalSectionRecursive cs
std::vector< bool > freeTextureNames
static TOpenGLNameBooker & instance()
unsigned int next_free_texture
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
A RGB color - floats in the range [0,1].