35 _square_inscribed =
false;
36 _square_radius = 1.0f;
47 _half_fov_rad = deg_2_rad(_fov * 0.5f);
57 int max_vertices_per_array = 100;
58 int max_vertices_per_primitive = 10000;
59 bool prefers_triangle_strips =
true;
77 PN_stdfloat vertices_per_unit = csqrt(_num_vertices / MathNumbers::pi_f);
78 PN_stdfloat two_pi = 2.0f * MathNumbers::pi_f;
82 int num_rings = (int)floor(vertices_per_unit + 0.5f);
86 (InternalName::get_vertex(), 3,
87 Geom::NT_stdfloat, Geom::C_point,
88 InternalName::get_texcoord(), 3,
89 Geom::NT_stdfloat, Geom::C_texcoord));
98 tristrips->set_shade_model(Geom::SM_uniform);
102 int last_ring_size = 3;
103 int last_ring_vertex = 0;
104 PN_stdfloat last_r = 1.0f / (PN_stdfloat)num_rings;
108 for (
int vi = 0; vi < last_ring_size; ++vi) {
109 add_vertex(vertex, texcoord, last_r,
110 two_pi * (PN_stdfloat)vi / (PN_stdfloat)last_ring_size);
111 tristrips->add_vertex(vi);
115 tristrips->add_vertex(2);
116 tristrips->close_primitive();
119 for (
int ri = 1; ri < num_rings; ++ri) {
120 PN_stdfloat r = (PN_stdfloat)(ri + 1) / (PN_stdfloat)num_rings;
123 PN_stdfloat c = two_pi * r;
124 int ring_size = (int)floor(c * vertices_per_unit + 0.5f);
128 if (ring_size < last_ring_size * 2) {
130 ring_size = last_ring_size;
133 ring_size = last_ring_size * 2;
136 if (vdata->get_num_rows() + ring_size > max_vertices_per_array) {
138 if (tristrips->get_num_vertices() != 0) {
139 geom->add_primitive(tristrips);
141 if (geom->get_num_primitives() != 0) {
142 if (prefers_triangle_strips) {
143 geom_node->add_geom(geom);
145 geom_node->add_geom(geom->decompose());
152 geom =
new Geom(vdata);
154 tristrips->set_shade_model(Geom::SM_uniform);
157 last_ring_vertex = 0;
158 for (
int vi = 0; vi < last_ring_size; ++vi) {
159 add_vertex(vertex, texcoord, last_r,
160 two_pi * (PN_stdfloat)vi / (PN_stdfloat)last_ring_size);
165 int ring_vertex = vdata->get_num_rows();
166 for (
int vi = 0; vi < ring_size; ++vi) {
167 add_vertex(vertex, texcoord, r,
168 two_pi * (PN_stdfloat)vi / (PN_stdfloat)ring_size);
172 if (ring_size == last_ring_size) {
174 if ((ring_size + 1) * 2 > max_vertices_per_primitive) {
177 int piece_size = max_vertices_per_primitive / 2 - 1;
179 while (vi < ring_size) {
180 int piece_end = std::min(ring_size + 1, piece_size + 1 + vi);
181 for (
int pi = vi; pi < piece_end; ++pi) {
182 tristrips->add_vertex(last_ring_vertex + pi % last_ring_size);
183 tristrips->add_vertex(ring_vertex + pi % ring_size);
185 tristrips->close_primitive();
191 if (tristrips->get_num_vertices() > 0 &&
192 tristrips->get_num_vertices() + ring_size * 2 > max_vertices_per_primitive) {
193 geom->add_primitive(tristrips);
195 tristrips->set_shade_model(Geom::SM_uniform);
197 for (
int vi = 0; vi < ring_size; ++vi) {
198 tristrips->add_vertex(last_ring_vertex + vi);
199 tristrips->add_vertex(ring_vertex + vi);
201 tristrips->add_vertex(last_ring_vertex);
202 tristrips->add_vertex(ring_vertex);
203 tristrips->close_primitive();
212 while (vi < last_ring_size) {
213 if (tristrips->get_num_vertices() + 10 > max_vertices_per_primitive) {
214 geom->add_primitive(tristrips);
216 tristrips->set_shade_model(Geom::SM_uniform);
218 tristrips->add_vertex(ring_vertex + (vi * 2 + 1) % ring_size);
219 tristrips->add_vertex(ring_vertex + (vi * 2 + 2) % ring_size);
220 tristrips->add_vertex(last_ring_vertex + (vi + 1) % last_ring_size);
221 tristrips->add_vertex(ring_vertex + (vi * 2 + 3) % ring_size);
222 tristrips->add_vertex(last_ring_vertex + (vi + 2) % last_ring_size);
223 tristrips->add_vertex(ring_vertex + (vi * 2 + 4) % ring_size);
224 tristrips->close_primitive();
226 tristrips->add_vertex(ring_vertex + (vi * 2 + 4) % ring_size);
227 tristrips->add_vertex(ring_vertex + (vi * 2 + 5) % ring_size);
228 tristrips->add_vertex(last_ring_vertex + (vi + 2) % last_ring_size);
229 tristrips->add_vertex(last_ring_vertex + (vi + 3) % last_ring_size);
230 tristrips->close_primitive();
236 last_ring_size = ring_size;
237 last_ring_vertex = ring_vertex;
241 if (_square_inscribed) {
243 int ring_size = last_ring_size;
245 if (vdata->get_num_rows() + ring_size > max_vertices_per_array) {
247 if (tristrips->get_num_vertices() != 0) {
248 geom->add_primitive(tristrips);
250 if (geom->get_num_primitives() != 0) {
251 if (prefers_triangle_strips) {
252 geom_node->add_geom(geom);
254 geom_node->add_geom(geom->decompose());
261 geom =
new Geom(vdata);
263 tristrips->set_shade_model(Geom::SM_uniform);
266 last_ring_vertex = 0;
267 for (
int vi = 0; vi < last_ring_size; ++vi) {
268 add_vertex(vertex, texcoord, last_r,
269 two_pi * (PN_stdfloat)vi / (PN_stdfloat)last_ring_size);
274 int ring_vertex = vdata->get_num_rows();
275 for (
int vi = 0; vi < ring_size; ++vi) {
276 add_square_vertex(vertex, texcoord,
277 two_pi * (PN_stdfloat)vi / (PN_stdfloat)ring_size);
281 if ((ring_size + 1) * 2 > max_vertices_per_primitive) {
284 int piece_size = max_vertices_per_primitive / 2 - 1;
286 while (vi < ring_size) {
287 int piece_end = std::min(ring_size + 1, piece_size + 1 + vi);
288 for (
int pi = vi; pi < piece_end; ++pi) {
289 tristrips->add_vertex(last_ring_vertex + pi % last_ring_size);
290 tristrips->add_vertex(ring_vertex + pi % ring_size);
292 tristrips->close_primitive();
298 if (tristrips->get_num_vertices() > 0 &&
299 tristrips->get_num_vertices() + ring_size * 2 > max_vertices_per_primitive) {
300 geom->add_primitive(tristrips);
302 tristrips->set_shade_model(Geom::SM_uniform);
304 for (
int vi = 0; vi < ring_size; ++vi) {
305 tristrips->add_vertex(last_ring_vertex + vi);
306 tristrips->add_vertex(ring_vertex + vi);
308 tristrips->add_vertex(last_ring_vertex);
309 tristrips->add_vertex(ring_vertex);
310 tristrips->close_primitive();
314 if (tristrips->get_num_vertices() != 0) {
315 geom->add_primitive(tristrips);
317 if (geom->get_num_primitives() != 0) {
318 if (prefers_triangle_strips) {
319 geom_node->add_geom(geom);
321 geom_node->add_geom(geom->decompose());
335 PN_stdfloat r, PN_stdfloat a) {
336 PN_stdfloat sina, cosa;
337 csincos(a, &sina, &cosa);
340 LPoint3 point(r * cosa, 0.0f, r * sina);
345 PN_stdfloat b = r * _half_fov_rad;
346 if (b >= MathNumbers::pi_f) {
351 PN_stdfloat sinb, cosb;
352 csincos(b, &sinb, &cosb);
353 LPoint3 tc(sinb * cosa, cosb * _reflect, sinb * sina);
368 PN_stdfloat sina, cosa;
369 csincos(a, &sina, &cosa);
372 if (cabs(sina) > cabs(cosa)) {
373 PN_stdfloat y = (sina > 0.0f) ? _square_radius : -_square_radius;
374 PN_stdfloat x = y * cosa / sina;
375 LPoint3 point(x, 0.0f, y);
379 PN_stdfloat x = (cosa > 0.0f) ? _square_radius : -_square_radius;
380 PN_stdfloat y = x * sina / cosa;
381 LPoint3 point(x, 0.0f, y);
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Defines a series of triangle strips.
void set_fov(PN_stdfloat fov)
Specifies the field of view of the fisheye projection.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
void reset()
Resets all the parameters to their initial defaults.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_reflection(bool reflection)
Sets the flag indicating whether the texture image should be mirrored (true) or normal (false).
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A node that holds Geom objects, renderable pieces of geometry.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PT(PandaNode) FisheyeMaker
Generates a GeomNode that renders the specified geometry.