made the meshDrawer take rec instead of a frame, drepricating the limited plate/frame system

This commit is contained in:
treeform 2010-01-13 06:33:39 +00:00
parent 33dca73f9e
commit 38bb5593ad
3 changed files with 88 additions and 111 deletions

View File

@ -29,8 +29,6 @@ MeshDrawer() {
_uv = NULL;
_color = NULL;
_budget = 5000;
_plate_size = 16;
_frame_size = 1.0f / float(_plate_size);
}
////////////////////////////////////////////////////////////////////
@ -47,38 +45,6 @@ INLINE MeshDrawer::
if (_color != NULL) delete _color;
}
////////////////////////////////////////////////////////////////////
// Function: MeshDrawer::set_plate_size
// Access: Published
// Description: Sets the number of images are on one side
// of a sqare plate.
// Geom drawer expects a plate of square image for
// most of its billboard operatoins. If plate size is
// 3 the frame numbering would look like this:
// 0 1 2
// 3 4 5
// 6 7 8
// you can select any frame you like for many of the
// billboards and segments.
////////////////////////////////////////////////////////////////////
INLINE void MeshDrawer::
set_plate_size(int one_side_size) {
_plate_size = one_side_size;
_frame_size = 1.0f / float(_plate_size);
}
////////////////////////////////////////////////////////////////////
// Function: MeshDrawer::get_plate_size
// Access: Published
// Description: Gets the number of images are on one side
// of a sqare plate.
////////////////////////////////////////////////////////////////////
INLINE int MeshDrawer::
get_plate_size() {
return _plate_size;
}
////////////////////////////////////////////////////////////////////
// Function: MeshDrawer::get_root
// Access: Published

View File

@ -152,7 +152,8 @@ void MeshDrawer::end() {
// Description: Draws a particle that is sort of like a bill board
// but has an extra rotation component.
////////////////////////////////////////////////////////////////////
void MeshDrawer::particle(LVector3f pos, int frame, float size, LVector4f color, float rotation) {
void MeshDrawer::particle(LVector3f pos, LVector4f frame, float size,
LVector4f color, float rotation) {
rotation = rotation / 57.29578;
@ -161,16 +162,18 @@ void MeshDrawer::particle(LVector3f pos, int frame, float size, LVector4f color,
LVector3f v3 = pos + _b3*size*sin(rotation) + _b4*size*cos(rotation);
LVector3f v4 = pos + _b4*size*sin(rotation) + _b1*size*cos(rotation);
float u = float(int(frame%_plate_size))*_frame_size;
float v = 1.0f-float(int(frame/_plate_size+1))*_frame_size;
float u = frame.get_x();
float v = frame.get_y();
float us = frame.get_z();
float vs = frame.get_w();
tri(
v1, color, LVector2f(u,v),
v2, color, LVector2f(u+_frame_size,v),
v3, color, LVector2f(u+_frame_size,v+_frame_size));
v2, color, LVector2f(u+us,v),
v3, color, LVector2f(u+us,v+vs));
tri(
v3, color, LVector2f(u+_frame_size,v+_frame_size),
v4, color, LVector2f(u,v+_frame_size),
v3, color, LVector2f(u+us,v+vs),
v4, color, LVector2f(u,v+vs),
v1, color, LVector2f(u,v));
}
@ -180,8 +183,8 @@ void MeshDrawer::particle(LVector3f pos, int frame, float size, LVector4f color,
// Description: Works just like particle but accepts 2 frames and
// a blend (from 0 to 1) component between them
////////////////////////////////////////////////////////////////////
void MeshDrawer::blended_particle(LVector3f pos, int frame1, int frame2,
float blend, float size, LVector4f color, float rotation) {
void MeshDrawer::blended_particle(LVector3f pos, LVector4f frame1,
LVector4f frame2, float blend, float size, LVector4f color, float rotation) {
float original_w = color.get_w();
color.set_w((1.f-blend)*original_w);
@ -197,23 +200,26 @@ void MeshDrawer::blended_particle(LVector3f pos, int frame1, int frame2,
// Description: Draws a billboard - particle with no rotation.
// Billboards always face the camera.
////////////////////////////////////////////////////////////////////
void MeshDrawer::billboard(LVector3f pos, int frame, float size, LVector4f _color) {
void MeshDrawer::billboard(LVector3f pos, LVector4f frame, float size,
LVector4f _color) {
LVector3f v1 = pos + _b1*size;
LVector3f v2 = pos + _b2*size;
LVector3f v3 = pos + _b3*size;
LVector3f v4 = pos + _b4*size;
float u = float(int(frame%_plate_size))*_frame_size;
float v = 1.0f-float(int(frame/_plate_size+1))*_frame_size;
float u = frame.get_x();
float v = frame.get_y();
float us = frame.get_z();
float vs = frame.get_w();
tri(
v1, _color, LVector2f(u,v),
v2, _color, LVector2f(u+_frame_size,v),
v3, _color, LVector2f(u+_frame_size,v+_frame_size));
v2, _color, LVector2f(u+us,v),
v3, _color, LVector2f(u+us,v+vs));
tri(
v3, _color, LVector2f(u+_frame_size,v+_frame_size),
v4, _color, LVector2f(u,v+_frame_size),
v3, _color, LVector2f(u+us,v+vs),
v4, _color, LVector2f(u,v+vs),
v1, _color, LVector2f(u,v));
}
@ -224,7 +230,7 @@ void MeshDrawer::billboard(LVector3f pos, int frame, float size, LVector4f _colo
// Description: Draws a segment a line with a thickness. That has
// billboarding effect.
////////////////////////////////////////////////////////////////////
void MeshDrawer::segment(LVector3f start, LVector3f stop, int frame,
void MeshDrawer::segment(LVector3f start, LVector3f stop, LVector4f frame,
float thickness, LVector4f color) {
link_segment(start, frame, thickness, color);
link_segment(stop, frame, thickness, color);
@ -237,10 +243,13 @@ void MeshDrawer::segment(LVector3f start, LVector3f stop, int frame,
// segment does not use the bill boarding behavior
// and instead draws 2 planes in a cross.
////////////////////////////////////////////////////////////////////
void MeshDrawer::cross_segment(LVector3f start, LVector3f stop, int frame,
void MeshDrawer::cross_segment(LVector3f start, LVector3f stop, LVector4f frame,
float thickness, LVector4f color) {
float u = float(int(frame%_plate_size))*_frame_size;
float v = 1.0f-float(int(frame/_plate_size+1))*_frame_size;
float u = frame.get_x();
float v = frame.get_y();
float us = frame.get_z();
float vs = frame.get_w();
LVector3f v1 = start - _up*thickness;
LVector3f v2 = stop - _up*thickness;
@ -248,10 +257,10 @@ void MeshDrawer::cross_segment(LVector3f start, LVector3f stop, int frame,
LVector3f v4 = start + _up*thickness;
tri(v1, color, LVector2f(u,v),
v2, color, LVector2f(u+_frame_size,v),
v3, color, LVector2f(u+_frame_size,v+_frame_size));
tri(v3, color, LVector2f(u+_frame_size,v+_frame_size),
v4, color, LVector2f(u,v+_frame_size),
v2, color, LVector2f(u+us,v),
v3, color, LVector2f(u+us,v+vs));
tri(v3, color, LVector2f(u+us,v+vs),
v4, color, LVector2f(u,v+vs),
v1, color, LVector2f(u,v));
v1 = start - _right*thickness;
@ -260,10 +269,10 @@ void MeshDrawer::cross_segment(LVector3f start, LVector3f stop, int frame,
v4 = start + _right*thickness;
tri(v1, color, LVector2f(u,v),
v2, color, LVector2f(u+_frame_size,v),
v3, color, LVector2f(u+_frame_size,v+_frame_size));
tri(v3, color, LVector2f(u+_frame_size,v+_frame_size),
v4, color, LVector2f(u,v+_frame_size),
v2, color, LVector2f(u+us,v),
v3, color, LVector2f(u+us,v+vs));
tri(v3, color, LVector2f(u+us,v+vs),
v4, color, LVector2f(u,v+vs),
v1, color, LVector2f(u,v));
}
@ -278,11 +287,13 @@ void MeshDrawer::cross_segment(LVector3f start, LVector3f stop, int frame,
// and color on both sides.
////////////////////////////////////////////////////////////////////
void MeshDrawer::uneven_segment(LVector3f start, LVector3f stop,
int frame, int multi_frame,
float thickness_start, LVector4f color_start,
float thickness_stop, LVector4f color_stop) {
float u = float(int(frame%_plate_size))*_frame_size;
float v = 1.0f-float(int(frame/_plate_size+1))*_frame_size;
LVector4f frame, float thickness_start, LVector4f color_start,
float thickness_stop, LVector4f color_stop) {
float u = frame.get_x();
float v = frame.get_y();
float us = frame.get_z();
float vs = frame.get_w();
LVector3f v1 = start - _up*thickness_start;
LVector3f v2 = stop - _up*thickness_stop;
@ -290,10 +301,10 @@ void MeshDrawer::uneven_segment(LVector3f start, LVector3f stop,
LVector3f v4 = start + _up*thickness_start;
tri(v1, color_start, LVector2f(u,v),
v2, color_stop, LVector2f(u+_frame_size*multi_frame,v),
v3, color_stop, LVector2f(u+_frame_size*multi_frame,v+_frame_size));
tri(v3, color_stop, LVector2f(u+_frame_size*multi_frame,v+_frame_size),
v4, color_start, LVector2f(u,v+_frame_size),
v2, color_stop, LVector2f(u+us,v),
v3, color_stop, LVector2f(u+us,v+vs));
tri(v3, color_stop, LVector2f(u+us,v+vs),
v4, color_start, LVector2f(u,v+vs),
v1, color_start, LVector2f(u,v));
v1 = start - _right*thickness_start;
@ -302,10 +313,10 @@ void MeshDrawer::uneven_segment(LVector3f start, LVector3f stop,
v4 = start + _right*thickness_start;
tri(v1, color_start, LVector2f(u,v),
v2, color_stop, LVector2f(u+_frame_size*multi_frame,v),
v3, color_stop, LVector2f(u+_frame_size*multi_frame,v+_frame_size));
tri(v3, color_stop, LVector2f(u+_frame_size*multi_frame,v+_frame_size),
v4, color_start, LVector2f(u,v+_frame_size),
v2, color_stop, LVector2f(u+us,v),
v3, color_stop, LVector2f(u+us,v+vs));
tri(v3, color_stop, LVector2f(u+us,v+vs),
v4, color_start, LVector2f(u,v+vs),
v1, color_start, LVector2f(u,v));
}
@ -315,7 +326,7 @@ void MeshDrawer::uneven_segment(LVector3f start, LVector3f stop,
// Description: Draws number of particles in a sphere like emitter.
////////////////////////////////////////////////////////////////////
void MeshDrawer::explosion(
LVector3f pos, int frame, float size, LVector4f _color,
LVector3f pos, LVector4f frame, float size, LVector4f _color,
int seed, int number, float distance) {
srand(seed);
LVector3f relative_pos;
@ -333,7 +344,7 @@ void MeshDrawer::explosion(
// Description: Draws a number of particles in a big line with a
// shift dictated by the offset.
////////////////////////////////////////////////////////////////////
void MeshDrawer::stream(LVector3f start, LVector3f stop, int frame, float size, LVector4f _color,
void MeshDrawer::stream(LVector3f start, LVector3f stop, LVector4f frame, float size, LVector4f _color,
int number, float offset) {
offset = offset-floor(offset);
@ -422,7 +433,7 @@ void MeshDrawer::geometry(NodePath draw_node) {
// Control position, frame, thickness and color with
// parameters.
////////////////////////////////////////////////////////////////////
void MeshDrawer::link_segment(LVector3f pos, int frame,
void MeshDrawer::link_segment(LVector3f pos, LVector4f frame,
float thickness, LVector4f color) {
assert(_render.get_error_type() == NodePath::ET_ok);
assert(_camera.get_error_type() == NodePath::ET_ok);
@ -493,14 +504,16 @@ void MeshDrawer::link_segment(LVector3f pos, int frame,
LVector3f v4 = _last_v4;
// compute this frame
float u = float(int(frame%_plate_size))*_frame_size;
float v = 1.0f-float(int(frame/_plate_size+1))*_frame_size;
float u = frame.get_x();
float v = frame.get_y();
float us = frame.get_z();
float vs = frame.get_w();
tri(v1, _last_color, LVector2f(u,v),
v2, color, LVector2f(u+_frame_size,v),
v3, color, LVector2f(u+_frame_size,v+_frame_size));
tri(v3, color, LVector2f(u+_frame_size,v+_frame_size),
v4, _last_color, LVector2f(u,v+_frame_size),
v2, color, LVector2f(u+us,v),
v3, color, LVector2f(u+us,v+vs));
tri(v3, color, LVector2f(u+us,v+vs),
v4, _last_color, LVector2f(u,v+vs),
v1, _last_color, LVector2f(u,v));
// save this segment
@ -522,16 +535,18 @@ void MeshDrawer::link_segment(LVector3f pos, int frame,
// two calls to link_segment before it can end
// the linked segment.
////////////////////////////////////////////////////////////////////
void MeshDrawer::link_segment_end(int frame, LVector4f color)
void MeshDrawer::link_segment_end(LVector4f frame, LVector4f color)
{
float u = float(int(frame%_plate_size))*_frame_size;
float v = 1.0f-float(int(frame/_plate_size+1))*_frame_size;
float u = frame.get_x();
float v = frame.get_y();
float us = frame.get_z();
float vs = frame.get_w();
tri(_last_v1, _last_color, LVector2f(u,v),
_last_v2, color, LVector2f(u+_frame_size,v),
_last_v3, color, LVector2f(u+_frame_size,v+_frame_size));
tri(_last_v3, color, LVector2f(u+_frame_size,v+_frame_size),
_last_v4, _last_color, LVector2f(u,v+_frame_size),
_last_v2, color, LVector2f(u+us,v),
_last_v3, color, LVector2f(u+us,v+vs));
tri(_last_v3, color, LVector2f(u+us,v+vs),
_last_v4, _last_color, LVector2f(u,v+vs),
_last_v1, _last_color, LVector2f(u,v));
_at_start = 0;

View File

@ -48,8 +48,6 @@ PUBLISHED:
INLINE MeshDrawer();
INLINE ~MeshDrawer();
INLINE void set_plate_size(int plate_size);
INLINE int get_plate_size();
INLINE void set_budget(int budget);
INLINE int get_budget();
@ -59,24 +57,24 @@ PUBLISHED:
INLINE void tri(LVector3f v1, LVector4f c1, LVector2f uv1,
LVector3f v2, LVector4f c2, LVector2f uv2,
LVector3f v3, LVector4f c3, LVector2f uv3);
void particle(LVector3f pos, int frame, float size, LVector4f color, float rotation);
void blended_particle(LVector3f pos, int frame1, int frame2,
float blend, float size, LVector4f color, float rotation);
void billboard(LVector3f pos, int frame, float size, LVector4f color);
void segment(LVector3f start, LVector3f stop, int frame, float thickness, LVector4f color);
void cross_segment(LVector3f start, LVector3f stop, int frame, float thickness, LVector4f color);
void particle(LVector3f pos, LVector4f frame, float size, LVector4f color, float rotation);
void blended_particle(LVector3f pos, LVector4f frame1, LVector4f frame2,
float blend, float size, LVector4f color, float rotation);
void billboard(LVector3f pos, LVector4f frame, float size, LVector4f color);
void segment(LVector3f start, LVector3f stop, LVector4f frame, float thickness, LVector4f color);
void cross_segment(LVector3f start, LVector3f stop, LVector4f frame, float thickness, LVector4f color);
void uneven_segment(LVector3f start, LVector3f stop,
int frame, int multi_frame,
float thickness_start, LVector4f color_start,
float thickness_stop, LVector4f color_stop);
LVector4f frame, float thickness_start, LVector4f color_start,
float thickness_stop, LVector4f color_stop);
void link_segment(LVector3f pos, int frame, float thickness, LVector4f color);
void link_segment_end(int frame, LVector4f color);
void link_segment(LVector3f pos, LVector4f frame, float thickness, LVector4f color);
void link_segment_end(LVector4f frame, LVector4f color);
void explosion(LVector3f pos, int frame, float size, LVector4f color,
int seed, int number, float distance);
void stream(LVector3f start, LVector3f stop, int frame, float size, LVector4f color,
int number, float offset);
void explosion(LVector3f pos, LVector4f frame, float size, LVector4f color,
int seed, int number, float distance);
void stream(LVector3f start, LVector3f stop, LVector4f frame, float size, LVector4f color,
int number, float offset);
void geometry(NodePath node);
void end();
@ -85,8 +83,6 @@ private:
// use vars
NodePath _root;
NodePath _camera, _render;
int _plate_size;
float _frame_size;
int _budget;
// store regeneration geoms & nodes