15 #include "cardMaker.h"
17 #include "transformState.h"
18 #include "colorAttrib.h"
19 #include "sceneGraphReducer.h"
21 #include "geomTristrips.h"
22 #include "geomVertexWriter.h"
23 #include "geomVertexFormat.h"
36 _color.set(1.0f, 1.0f, 1.0f, 1.0f);
40 _source_frame.set(0.0f, 0.0f, 0.0f, 0.0f);
52 if (_source_geometry != (
PandaNode *)NULL) {
53 return rescale_source_geometry();
58 CPT(GeomVertexFormat) format;
62 format = GeomVertexFormat::register_format
63 (
new GeomVertexArrayFormat
64 (InternalName::get_vertex(), 3,
65 GeomEnums::NT_stdfloat, GeomEnums::C_point,
66 InternalName::get_normal(), 3,
67 GeomEnums::NT_stdfloat, GeomEnums::C_vector,
68 InternalName::get_texcoord(), 3,
69 GeomEnums::NT_stdfloat, GeomEnums::C_texcoord));
71 format = GeomVertexFormat::get_v3n3t2();
74 format = GeomVertexFormat::get_v3n3();
79 format = GeomVertexFormat::register_format
80 (
new GeomVertexArrayFormat
81 (InternalName::get_vertex(), 3,
82 GeomEnums::NT_stdfloat, GeomEnums::C_point,
83 InternalName::get_texcoord(), 3,
84 GeomEnums::NT_stdfloat, GeomEnums::C_texcoord));
86 format = GeomVertexFormat::get_v3t2();
89 format = GeomVertexFormat::get_v3();
94 ("card", format,
Geom::UH_static);
97 vertex.add_data3(_ul_pos);
98 vertex.add_data3(_ll_pos);
99 vertex.add_data3(_ur_pos);
100 vertex.add_data3(_lr_pos);
104 texcoord.add_data3(_ul_tex);
105 texcoord.add_data3(_ll_tex);
106 texcoord.add_data3(_ur_tex);
107 texcoord.add_data3(_lr_tex);
113 n = (_ll_pos - _ul_pos).cross(_ur_pos - _ul_pos);
116 n = (_lr_pos - _ll_pos).cross(_ul_pos - _ll_pos);
119 n = (_ul_pos - _ur_pos).cross(_lr_pos - _ur_pos);
122 n = (_ur_pos - _lr_pos).cross(_ll_pos - _lr_pos);
128 strip->set_shade_model(
Geom::SM_uniform);
129 strip->add_next_vertices(4);
130 strip->close_primitive();
133 geom->add_primitive(strip);
137 state = RenderState::make(ColorAttrib::make_flat(_color));
140 gnode->add_geom(geom, state);
175 _ll_tex.set(ll[0], ll[1], 0.0f);
176 _lr_tex.set(lr[0], lr[1], 0.0f);
177 _ur_tex.set(ur[0], ur[1], 0.0f);
178 _ul_tex.set(ul[0], ul[1], 0.0f);
194 _ll_tex.set(ll[0], ll[1], 0.0f);
195 _lr_tex.set(ur[0], ll[1], 0.0f);
196 _ur_tex.set(ur[0], ur[1], 0.0f);
197 _ul_tex.set(ll[0], ur[1], 0.0f);
213 _ll_tex.set(x[0], y[0], z[0]);
214 _lr_tex.set(x[1], y[1], z[1]);
215 _ur_tex.set(x[2], y[2], z[2]);
216 _ul_tex.set(x[3], y[3], z[3]);
254 double maxu = (nonpadx*1.0) / tex->
get_x_size();
255 double maxv = (nonpady*1.0) / tex->
get_y_size();
266 rescale_source_geometry() {
267 PT(
PandaNode) root = _source_geometry->copy_subgraph();
270 LVector3 frame_max = _ll_pos.fmax(_lr_pos.fmax(_ur_pos.fmax(_ul_pos)));
271 LVector3 frame_min = _ll_pos.fmin(_lr_pos.fmin(_ur_pos.fmax(_ul_pos)));
272 LVector3 frame_ctr = (frame_max + frame_min) * 0.5f;
274 LVector3 geom_center((_source_frame[0] + _source_frame[1]) * 0.5f,
276 (_source_frame[2] + _source_frame[3]) * 0.5f);
278 LVector3 scale((frame_max[0] - frame_min[0]) / (_source_frame[1] - _source_frame[0]),
280 (frame_max[2] - frame_min[2]) / (_source_frame[3] - _source_frame[2]));
282 LVector3 trans = frame_ctr - geom_center;
284 CPT(TransformState) transform =
285 TransformState::make_pos_hpr_scale(trans,
LPoint3(0.0f, 0.0f, 0.0f), scale);
286 root->set_transform(transform);
289 root->
set_attrib(ColorAttrib::make_flat(_color));
A basic node of the scene graph or data graph.
This object provides a high-level interface for quickly writing a sequence of numeric values from a v...
void set_frame(PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top)
Sets the size of the card.
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
An interface for simplifying ("flattening") scene graphs by eliminating unneeded nodes and collapsing...
void set_attrib(const RenderAttrib *attrib, int priority=0)
Adds the indicated render attribute to the scene graph on this node.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Defines a series of triangle strips.
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
void set_uv_range_cube(int face)
Sets the range of UV's that will be applied to the vertices appropriately for a cube-map face...
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
A container for geometry primitives.
This class generates 2-d "cards", that is, rectangular polygons, particularly useful for showing text...
This is a four-component vector distance.
int flatten(PandaNode *root, int combine_siblings_bits)
Simplifies the graph by removing unnecessary nodes and nodes.
TextureType get_texture_type() const
Returns the overall interpretation of the texture.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
void apply_attribs(PandaNode *node, int attrib_types=~(TT_clip_plane|TT_cull_face|TT_apply_texture_color))
Walks the scene graph, accumulating attribs of the indicated types, applying them to the vertices...
int get_pad_y_size() const
Returns size of the pad region.
int get_pad_x_size() const
Returns size of the pad region.
void set_uv_range(const LTexCoord &ll, const LTexCoord &ur)
Sets the range of UV's that will be applied to the vertices.
This is a two-component point in space.
bool normalize()
Normalizes the vector in place.
int get_y_size() const
Returns the height of the texture image in texels.
int get_x_size() const
Returns the width of the texture image in texels.
A node that holds Geom objects, renderable pieces of geometry.
void reset()
Resets all the parameters to their initial defaults.