From: Mikko Rasa Date: Sun, 5 Dec 2010 19:16:12 +0000 (+0000) Subject: Add a MatrixStack to VertexBuilder X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=524515ae47ea553e8e1b9381c2027208f2d096db;p=libs%2Fgl.git Add a MatrixStack to VertexBuilder Change the vertex handler function to take a Vector4 as parameter --- diff --git a/source/primitivebuilder.cpp b/source/primitivebuilder.cpp index 22106a34..42e9d39c 100644 --- a/source/primitivebuilder.cpp +++ b/source/primitivebuilder.cpp @@ -53,7 +53,7 @@ PrimitiveType PrimitiveBuilder::get_type() const 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); @@ -61,7 +61,7 @@ void PrimitiveBuilder::vertex_(float x, float y, float z, float w) vab.multitexcoord(i->first, i->second); for(std::map::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); diff --git a/source/primitivebuilder.h b/source/primitivebuilder.h index 8cc1e729..a4e34a67 100644 --- a/source/primitivebuilder.h +++ b/source/primitivebuilder.h @@ -38,7 +38,7 @@ public: void element(unsigned); PrimitiveType get_type() const; protected: - virtual void vertex_(float, float, float, float); + virtual void vertex_(const Vector4 &); virtual void begin_() =0; virtual void end_() =0; virtual void element_(unsigned) =0; diff --git a/source/vertexarraybuilder.cpp b/source/vertexarraybuilder.cpp index 5c0a0196..c31a60a6 100644 --- a/source/vertexarraybuilder.cpp +++ b/source/vertexarraybuilder.cpp @@ -20,7 +20,7 @@ VertexArrayBuilder::~VertexArrayBuilder() 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) @@ -30,10 +30,10 @@ void VertexArrayBuilder::vertex_(float x, float y, float z, float w) 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; diff --git a/source/vertexarraybuilder.h b/source/vertexarraybuilder.h index 3b1f8216..b6af0b95 100644 --- a/source/vertexarraybuilder.h +++ b/source/vertexarraybuilder.h @@ -28,7 +28,7 @@ public: ~VertexArrayBuilder(); private: - virtual void vertex_(float, float, float, float); + virtual void vertex_(const Vector4 &); }; } // namespace GL diff --git a/source/vertexbuilder.h b/source/vertexbuilder.h index e7f9b132..764fef50 100644 --- a/source/vertexbuilder.h +++ b/source/vertexbuilder.h @@ -10,6 +10,7 @@ Distributed under the LGPL #include #include "color.h" +#include "matrix.h" #include "vector.h" namespace Msp { @@ -26,11 +27,21 @@ data. Attributes can be read from protected member variables. */ class VertexBuilder { +protected: + MatrixStack mtx; + Vector3 nor; + Color col; + std::map texc; + std::map attr; + public: VertexBuilder(): nor(0, 0, 1) { } virtual ~VertexBuilder() { } + MatrixStack &matrix() + { return mtx; } + void vertex(float x, float y) { vertex(x, y, 0, 1); } @@ -38,20 +49,23 @@ public: { 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); } @@ -112,12 +126,6 @@ public: void attrib(unsigned i, const Vector4 &a) { attr[i] = a; } - -protected: - Vector3 nor; - Color col; - std::map texc; - std::map attr; }; } // namespace GL