return type;
}
-void PrimitiveBuilder::vertex_(float x, float y, float z, float w)
+void PrimitiveBuilder::vertex_(const Vector4 &v)
{
vab.color(col);
vab.normal(nor);
vab.multitexcoord(i->first, i->second);
for(std::map<unsigned, Vector4>::iterator i=attr.begin(); i!=attr.end(); ++i)
vab.attrib(i->first, i->second);
- vab.vertex(x, y, z, w);
+ vab.vertex(v);
if(in_batch)
element_(array.size()-1);
array.update_data();
}
-void VertexArrayBuilder::vertex_(float x, float y, float z, float w)
+void VertexArrayBuilder::vertex_(const Vector4 &v)
{
float *ptr = array.append();
for(const unsigned char *c=array.get_format().begin(); c!=array.get_format().end(); ++c)
switch(t)
{
case 0:
- *ptr++ = x;
- *ptr++ = y;
- if(sz>=3) *ptr++ = z;
- if(sz>=4) *ptr++ = w;
+ *ptr++ = v.x;
+ *ptr++ = v.y;
+ if(sz>=3) *ptr++ = v.z;
+ if(sz>=4) *ptr++ = v.w;
break;
case 1:
*ptr++ = nor.x;
#include <map>
#include "color.h"
+#include "matrix.h"
#include "vector.h"
namespace Msp {
*/
class VertexBuilder
{
+protected:
+ MatrixStack mtx;
+ Vector3 nor;
+ Color col;
+ std::map<unsigned, Vector4> texc;
+ std::map<unsigned, Vector4> attr;
+
public:
VertexBuilder(): nor(0, 0, 1) { }
virtual ~VertexBuilder() { }
+ MatrixStack &matrix()
+ { return mtx; }
+
void vertex(float x, float y)
{ vertex(x, y, 0, 1); }
{ vertex(x, y, z, 1); }
void vertex(float x, float y, float z, float w)
- { vertex_(x, y, z, w); }
+ { vertex(Vector4(x, y, z, w)); }
void vertex(const Vector4 &v)
- { vertex(v.x, v.y, v.z, v.w); }
+ { vertex_(mtx.top()*v); }
protected:
- virtual void vertex_(float x, float y, float z, float w) =0;
+ virtual void vertex_(const Vector4 &) = 0;
public:
void normal(float x, float y, float z)
{ normal(Vector3(x, y, z)); }
void normal(const Vector3 &n)
- { nor = n; }
+ {
+ Vector4 tn = mtx.top()*Vector4(n.x, n.y, n.z, 0);
+ nor = Vector3(tn.x, tn.y, tn.z);
+ }
void texcoord(float s)
{ texcoord(s, 0, 0, 1); }
void attrib(unsigned i, const Vector4 &a)
{ attr[i] = a; }
-
-protected:
- Vector3 nor;
- Color col;
- std::map<unsigned, Vector4> texc;
- std::map<unsigned, Vector4> attr;
};
} // namespace GL