hello,
how come this code works :
#include "pandaFramework.h"
#include "pandaSystem.h"
#include "GeomNode.h"
#include "GeomTriangles.h"
PandaFramework framework;
WindowFramework *window;
float HALF_BOX_DIM = 10.0f;
const LVector3f gsBoxVertOffsets[8] =
{
//top
(-HALF_BOX_DIM, -HALF_BOX_DIM, HALF_BOX_DIM),
(HALF_BOX_DIM, -HALF_BOX_DIM, HALF_BOX_DIM),
(HALF_BOX_DIM, HALF_BOX_DIM, HALF_BOX_DIM),
(-HALF_BOX_DIM, HALF_BOX_DIM, HALF_BOX_DIM),
//bottom
(-HALF_BOX_DIM, -HALF_BOX_DIM, -HALF_BOX_DIM),
(HALF_BOX_DIM, -HALF_BOX_DIM, -HALF_BOX_DIM),
(HALF_BOX_DIM, HALF_BOX_DIM, -HALF_BOX_DIM),
(-HALF_BOX_DIM, HALF_BOX_DIM, -HALF_BOX_DIM)
};
int main(int argc, char *argv[])
{
framework.open_framework(argc, argv);
WindowProperties prop;
framework.get_default_window_props(prop);
prop.set_title("Test Panda 3D");
prop.set_cursor_hidden(true);
window = framework.open_window(prop,0);
window->set_background_type(WindowFramework::BT_gray);
window->setup_trackball();
PT(Geom) mVertexGeom;
PT(GeomVertexData) mBoxVData;
GeomVertexRewriter mBoxVertices;
GeomVertexRewriter mBoxColors;
mBoxVData = new GeomVertexData("Vertex", GeomVertexFormat::get_v3c4(), Geom::UH_dynamic);
mBoxVertices = GeomVertexRewriter(mBoxVData, "vertex");
mBoxColors = GeomVertexRewriter(mBoxVData, "color");
mVertexGeom = new Geom(mBoxVData);
LVector4f vertexColor(0 ,1.0f ,0 ,1.0f);
//LVector3f v0 = gsBoxVertOffsets[0];
//LVector3f v1 = gsBoxVertOffsets[1];
//LVector3f v2 = gsBoxVertOffsets[2];
LVector3f v0 = LVector3f(-HALF_BOX_DIM, -HALF_BOX_DIM, HALF_BOX_DIM);
LVector3f v1 = LVector3f(HALF_BOX_DIM, -HALF_BOX_DIM, HALF_BOX_DIM);
LVector3f v2 = LVector3f(HALF_BOX_DIM, HALF_BOX_DIM, HALF_BOX_DIM);
mBoxVertices.add_data3f(v0);
mBoxColors.add_data4f(vertexColor);
mBoxVertices.add_data3f(v1);
mBoxColors.add_data4f(vertexColor);
mBoxVertices.add_data3f(v2);
mBoxColors.add_data4f(vertexColor);
PT(GeomTriangles) prim = new GeomTriangles(Geom::UH_dynamic);
prim->add_vertex(0);
prim->add_vertex(1);
prim->add_vertex(2);
prim->close_primitive();
mVertexGeom->add_primitive(prim);
PT(GeomNode) pTestGeom = new GeomNode("TestBox");
pTestGeom->add_geom(mVertexGeom);
NodePath vertexNodePath = window->get_render().attach_new_node(pTestGeom);
vertexNodePath.set_two_sided(true);
vertexNodePath.show();
framework.main_loop();
framework.close_framework();
return (0);
}
but if this is used
//LVector3f v0 = gsBoxVertOffsets[0];
//LVector3f v1 = gsBoxVertOffsets[1];
//LVector3f v2 = gsBoxVertOffsets[2];
instead of
LVector3f v0 = LVector3f(-HALF_BOX_DIM, -HALF_BOX_DIM, HALF_BOX_DIM);
LVector3f v1 = LVector3f(HALF_BOX_DIM, -HALF_BOX_DIM, HALF_BOX_DIM);
LVector3f v2 = LVector3f(HALF_BOX_DIM, HALF_BOX_DIM, HALF_BOX_DIM);
it doesn’t seem to work ?
I can’t think of any reason why that would be different ?
Chrys