X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fgrid.cpp;fp=source%2Fgrid.cpp;h=524f2c5a175aca054951fafb2c8636c6a93c01d8;hb=aa9884e69bc543682d1fe36ec5d054fdf11bcfac;hp=0000000000000000000000000000000000000000;hpb=bbfb79181f716736df413f463b55825866400ed8;p=libs%2Fgl.git diff --git a/source/grid.cpp b/source/grid.cpp new file mode 100644 index 00000000..524f2c5a --- /dev/null +++ b/source/grid.cpp @@ -0,0 +1,131 @@ +/* $Id$ + +This file is part of libmspgl +Copyright © 2011 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + +#include +#include "grid.h" +#include "primitivebuilder.h" + +using namespace std; + +namespace Msp { +namespace GL { + +GridBuilder::GridBuilder(float w, float h, unsigned u, unsigned v): + origin(-w/2, -h/2, 0), + side1(w, 0, 0), + side2(0, h, 0), + norm(0, 0, 1), + binorm(0, 1, 0), + u_div(u), + v_div(v) +{ + init(false); +} + +GridBuilder::GridBuilder(const Vector3 &o, const Vector3 &s, unsigned u, unsigned v): + origin(o), + u_div(u), + v_div(v) +{ + if(abs(s.z)=0) + builder.attrib(tangent_attr, side1.x, side1.y, side1.z); + if(binormal_attr>=0) + builder.attrib(tangent_attr, binorm.x, binorm.y, binorm.z); + + for(unsigned j=0; j<=v_div; ++j) + { + float v = j*1.0/v_div; + Vector3 row(origin.x+side2.x*v, origin.y+side2.y*v, origin.z+side2.z*v); + v = (row.x*binorm.x+row.y*binorm.y+row.z*binorm.z)*v_scale; + for(unsigned i=0; i<=u_div; ++i) + { + float u = i*1.0/u_div; + Vector3 p(row.x+side1.x*u, row.y+side1.y*u, row.z+side1.z*u); + u = (p.x*side1.x+p.y*side1.y+p.z*side1.z)*u_scale; + builder.texcoord(u, v); + builder.vertex(p); + } + } + + for(unsigned j=0; j