added backend functionality for Quads

This commit is contained in:
Josh Holtrop 2010-12-19 00:11:35 -05:00
parent 6e35afb4ad
commit 791fb14925
2 changed files with 114 additions and 0 deletions

View File

@ -1303,3 +1303,78 @@ Engine::PickedObject::PickedObject(OdeWorld::PickedObjectRef por)
normal[1] = por->normal[1]; normal[1] = por->normal[1];
normal[2] = por->normal[2]; normal[2] = por->normal[2];
} }
/******** Engine::Quad functions ********/
Engine::Quad::Quad(float cx, float cy, float cz,
float v1x, float v1y, float v1z,
float v2x, float v2y, float v2z)
{
m_center[0] = cx;
m_center[1] = cy;
m_center[2] = cz;
m_v1[0] = v1x;
m_v1[1] = v1y;
m_v1[2] = v1z;
m_v2[0] = v2x;
m_v2[1] = v2y;
m_v2[2] = v2z;
dNormalize3(m_normal);
m_dl = 0;
m_visible = true;
m_offset = 0.0f;
m_texture = 0;
m_enable_blending = false;
dCROSS(m_normal, =, m_v1, m_v2);
render();
}
Engine::Quad::~Quad()
{
if (m_dl != 0)
{
glDeleteLists(m_dl, 1);
}
}
int Engine::Quad::render()
{
if (m_dl == 0)
{
m_dl = glGenLists(1);
}
glNewList(m_dl, GL_COMPILE);
bool do_offset = !FP_EQ(m_offset, 0.0f);
glPushAttrib(GL_POLYGON_BIT | GL_TEXTURE_BIT | GL_COLOR_BUFFER_BIT);
if (do_offset)
{
glEnable(GL_POLYGON_OFFSET_FILL);
}
if (m_texture != 0)
{
glBindTexture(GL_TEXTURE_2D, m_texture);
}
if (m_enable_blending)
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
glBegin(GL_QUADS);
glNormal3f(m_normal[0], m_normal[1], m_normal[2]);
glVertex3f(m_center[0] + m_v1[0] + m_v2[0],
m_center[1] + m_v1[1] + m_v2[1],
m_center[2] + m_v1[2] + m_v2[2]);
glVertex3f(m_center[0] - m_v1[0] + m_v2[0],
m_center[1] - m_v1[1] + m_v2[1],
m_center[2] - m_v1[2] + m_v2[2]);
glVertex3f(m_center[0] - m_v1[0] - m_v2[0],
m_center[1] - m_v1[1] - m_v2[1],
m_center[2] - m_v1[2] - m_v2[2]);
glVertex3f(m_center[0] + m_v1[0] - m_v2[0],
m_center[1] + m_v1[1] - m_v2[1],
m_center[2] + m_v1[2] - m_v2[2]);
glEnd();
glPopAttrib();
glEndList();
return m_dl;
}

View File

@ -154,6 +154,45 @@ class Engine
}; };
typedef refptr<PickedObject> PickedObjectRef; typedef refptr<PickedObject> PickedObjectRef;
class Quad
{
public:
Quad(float cx, float cy, float cz,
float v1x, float v1y, float v1z,
float v2x, float v2y, float v2z);
~Quad();
int render();
void setVisible(bool v) { m_visible = v; }
void draw()
{
if (m_visible && m_dl > 0)
glCallList(m_dl);
}
void setOffset(float f)
{
m_offset = f;
render();
}
void setTexture(int t)
{
m_texture = t;
render();
}
void setBlending(bool b)
{
m_enable_blending = b;
render();
}
protected:
dVector3 m_center;
dVector3 m_v1, m_v2, m_normal;
int m_dl;
bool m_visible;
float m_offset;
int m_texture;
bool m_enable_blending;
};
Engine(const std::string & path, AV & av); Engine(const std::string & path, AV & av);
~Engine(); ~Engine();