I am trying to place 100 spheres in different positions of the the screen, i am
attempting this by using a for loop that loops 100 times and each time
generates random X, Y, Z values that I then use in the setPosition() method.
What i have written compiles but when I run it I get an exception and i just
cant seem to see the problem.
Below is the code, its very basic so i though it would run without any
problems, can anyone spot the problem.
Code:
int main(int argc,char *argv[])
{
Group *my_Group = new Group();
Geode *my_Geode = new Geode();
ShapeDrawable *my_Shape = new ShapeDrawable();
Sphere *my_Sphere = new Sphere();
my_Sphere->setRadius(1);
my_Shape->setShape(my_Sphere);
my_Geode->addDrawable(my_Shape);
my_Group->addChild(my_Geode);
PositionAttitudeTransform *my_Trans[100];
srand((unsigned)time(0));
int lowest=0, highest=50;
int range=(highest-lowest)+1;
double xpos, ypos, zpos;
for(int i=1; i<100; i++)
{
xpos = lowest+int(range*rand()/(RAND_MAX + 1.0));
cout<<"x position: "<<xpos<<endl;
ypos = lowest+int(range*rand()/(RAND_MAX + 1.0));
cout<<"y position: "<<ypos<<endl;
zpos = lowest+int(range*rand()/(RAND_MAX + 1.0));
cout<<"z position: "<<zpos<<endl;
my_Trans[i]->setPosition(Vec3(xpos, ypos, zpos));
my_Trans[i]->addChild(my_Geode);
my_Group->addChild(my_Trans[i]);
}
Viewer *simpleViewer = new Viewer;
simpleViewer->setSceneData(my_Group);
simpleViewer->setCameraManipulator(new osgGA::TrackballManipulator);
simpleViewer->setUpViewInWindow(32, 32, 1024, 800);
simpleViewer->getCamera()->setProjectionMatrixAsPerspective(30, 1.3, 1,
2);
simpleViewer->realize();
while (!simpleViewer->done())
{
simpleViewer->run();
}
}
I have #included the necessary files and am using the needed namespaces.
Thanks.
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=25369#25369
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org