15 #include "meshDrawer2D.h" 17 #include "geomVertexFormat.h" 18 #include "geomVertexArrayFormat.h" 19 #include "geomVertexData.h" 20 #include "geomVertexWriter.h" 21 #include "geomVertexRewriter.h" 23 #include "boundingSphere.h" 24 #include "geomTristrips.h" 25 #include "geomTriangles.h" 28 #include "pnmPainter.h" 30 #include "lvecBase4.h" 32 #include "pandaNode.h" 37 #define RANDF ((PN_stdfloat) rand() / (PN_stdfloat) 0x7fffffff) 45 void MeshDrawer2D::generator(
int budget) {
55 for(
int i = 0; i < budget; i++) {
56 for(
int vert = 0; vert < 4; vert++) {
62 tvertex->add_data3(vec3);
68 _prim->add_vertices(i*4+0, i*4+1, i*4+2);
69 _prim->close_primitive();
71 _prim->add_vertices(i*4+1, i*4+2, i*4+3);
72 _prim->close_primitive();
76 _geom =
new Geom(_vdata);
77 _geom->add_primitive(_prim);
78 _geomnode =
new GeomNode(
"__MeshDrawer_GeomNode");
79 _geomnode->add_geom(_geom);
81 _last_clear_index = budget;
97 if (_vertex != NULL)
delete _vertex;
98 if (_uv != NULL)
delete _uv;
99 if (_color != NULL)
delete _color;
104 _dprim = _prim->decompose();
107 _start_clear_index = 0;
108 _end_clear_index = _budget;
109 _clear_index = _start_clear_index;
122 for(
int i = _clear_index ; i < _last_clear_index; i ++ ) {
129 _last_clear_index = _clear_index;
132 delete _vertex; _vertex = NULL;
133 delete _uv; _uv = NULL;
134 delete _color; _color = NULL;
148 PN_stdfloat u, PN_stdfloat v, PN_stdfloat us, PN_stdfloat vs,
152 PN_stdfloat x_fit = w/us;
153 PN_stdfloat y_fit = h/vs;
154 PN_stdfloat x_pos = x;
157 PN_stdfloat y_pos = y;
161 PN_stdfloat fixed_us = us;
162 PN_stdfloat fixed_vs = vs;
167 while (fixed_us > us){
175 while (fixed_vs > vs){
180 rectangle(x_pos,y_pos,fixed_us,fixed_vs,u,v,fixed_us,fixed_vs,color);
201 PN_stdfloat x, PN_stdfloat y, PN_stdfloat w, PN_stdfloat h,
202 PN_stdfloat r, PN_stdfloat t, PN_stdfloat l, PN_stdfloat b,
203 PN_stdfloat tr, PN_stdfloat tt, PN_stdfloat tl, PN_stdfloat tb,
204 PN_stdfloat u, PN_stdfloat v, PN_stdfloat us, PN_stdfloat vs,
210 rectangle(x, y+h, w, t, u, v+vs, us, tt, color);
211 rectangle(x, y-b, w, b, u, v-tb, us, tb, color);
214 rectangle(x-l, y, l, h, u-tl, v, tl, vs, color);
215 rectangle(x+w, y, r, h, r, v, tr, vs, color);
233 PN_stdfloat x, PN_stdfloat y, PN_stdfloat w, PN_stdfloat h,
234 PN_stdfloat r, PN_stdfloat t, PN_stdfloat l, PN_stdfloat b,
235 PN_stdfloat tr, PN_stdfloat tt, PN_stdfloat tl, PN_stdfloat tb,
236 PN_stdfloat u, PN_stdfloat v, PN_stdfloat us, PN_stdfloat vs,
This object provides a high-level interface for quickly writing a sequence of numeric values from a v...
void rectangle_tiled(PN_stdfloat x, PN_stdfloat y, PN_stdfloat w, PN_stdfloat h, PN_stdfloat u, PN_stdfloat v, PN_stdfloat us, PN_stdfloat vs, const LVector4 &color)
Draws a tiled rectangle, size of tiles is in us and vs.
void end()
Finish the drawing and clearing off the remaining vertexes.
void add_data2(PN_stdfloat x, PN_stdfloat y)
Sets the write row to a particular 2-component value, and advances the write row. ...
void rectangle(PN_stdfloat x, PN_stdfloat y, PN_stdfloat w, PN_stdfloat h, PN_stdfloat u, PN_stdfloat v, PN_stdfloat us, PN_stdfloat vs, const LVector4 &color)
Draws a 2d rectangle, that can be cliped.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
void add_data4(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z, PN_stdfloat w)
Sets the write row to a particular 4-component value, and advances the write row. ...
NodePath attach_new_node(PandaNode *node, int sort=0, Thread *current_thread=Thread::get_current_thread()) const
Attaches a new node, with or without existing parents, to the scene graph below the referenced node o...
string get_name() const
Returns the name of the referenced node.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
A container for geometry primitives.
void add_data3(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Sets the write row to a particular 3-component value, and advances the write row. ...
This is a four-component vector distance.
void rectangle_border_tiled(PN_stdfloat x, PN_stdfloat y, PN_stdfloat w, PN_stdfloat h, PN_stdfloat r, PN_stdfloat t, PN_stdfloat l, PN_stdfloat b, PN_stdfloat tr, PN_stdfloat tt, PN_stdfloat tl, PN_stdfloat tb, PN_stdfloat u, PN_stdfloat v, PN_stdfloat us, PN_stdfloat vs, const LVector4 &color)
Draws a 2d rectangle, with borders and corders, taken from the surrounding texture.
This is a two-component vector offset.
void begin()
Opens up the geom for drawing, don't forget to call MeshDrawer2D::end()
Defines a series of disconnected triangles.
TypeHandle is the identifier used to differentiate C++ class types.
void rectangle_border(PN_stdfloat x, PN_stdfloat y, PN_stdfloat w, PN_stdfloat h, PN_stdfloat r, PN_stdfloat t, PN_stdfloat l, PN_stdfloat b, PN_stdfloat tr, PN_stdfloat tt, PN_stdfloat tl, PN_stdfloat tb, PN_stdfloat u, PN_stdfloat v, PN_stdfloat us, PN_stdfloat vs, const LVector4 &color)
Draws a 2d rectangle, with borders and corders, taken from the surrounding texture.
A node that holds Geom objects, renderable pieces of geometry.
This object provides the functionality of both a GeomVertexReader and a GeomVertexWriter, combined together into one convenient package.