Hi guys, I'm new to OpenSceneGraph, I'm doing a Uni course and I need some help.
Here's my code.
Code:
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <osg/Group>
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/ShapeDrawable>
#include <osg/MatrixTransform>
#include <osgViewer/Viewer>
#include <osg/Texture2D>
#include <osgDB/ReadFile>
#include <osgText/Font>
#include <osgText/Text>
using namespace std;
using namespace osg;
using namespace osgViewer;
using namespace osgDB;
using namespace osgText;
class PlanetCallback : public osg::NodeCallback
{
public:
PlanetCallback()
{
angle = 0.0;
}
virtual void operator()( osg::Node* node,
osg::NodeVisitor* nv )
{
// Normally, check to make sure we have an update
// visitor, not necessary in this simple example.
osg::MatrixTransform* mt =
dynamic_cast<osg::MatrixTransform*>( node );
osg::Matrix mR, mT;
// Move the planet away from the sun
mT.makeTranslate(Vec3(4, 0, 0));
mR.makeRotate(angle, Vec3(0, 0, 1));
mt->setMatrix( mT * mR );
angle=angle+0.001;
// Continue traversing so that OSG can process
// any other nodes with callbacks.
traverse( node, nv );
}
private:
double angle;
};
int main()
{
srand((unsigned)time(0));
// the viewer
Viewer *viewer=new Viewer();
// the root node
osg::Group *root=new Group();
// the planets
const int NUM=9;
Geode *geode[NUM];
Sphere *sphere[NUM];
ShapeDrawable *draw[NUM];
MatrixTransform *rot[NUM];
// setup the planets
for(int k=0;k<NUM;k++)
{
geode[k]=new Geode();
sphere[k]=new Sphere(Vec3(k,0,0),0.4);
draw[k]=new ShapeDrawable(sphere[k]);
draw[k]->setColor(Vec4(1,0,0,1));
geode[k]->addDrawable(draw[k]);
//add texture
//Texture2D *tex=new Texture2D();
//Image*image=readImageFile("C:/Mars.jpg");
//tex->setImage(image);
//StateSet* state=draw[k]->getOrCreateStateSet();
//state->setTextureAttributeAndModes(0,tex,StateAttribute::ON);
//geode[k]->addDrawable(draw[k]);
// rotate the sphere(s)
rot[k]=new MatrixTransform();
rot[k]->setUpdateCallback(new PlanetCallback());
rot[k]->addChild(geode[k]);
root->addChild(rot[k]);
}
//add test
Text *textX=new text();
textX->setText('Hello, this is a project about planets moving around
the sun");
textX->setPosition (Vec3 (1.1,0,0));
textX->setCharacterSize(0.2);
textX->setColor (Vec4(1,0,0,1));
sxsgeode->addDrawable(textX);
textX->setAxisAlignment(Text::VZ_PLANE);
// add the sun
Geode *geodeSun = new Geode();
Sphere *sphereSun = new Sphere(Vec3(0,0,0),1);
ShapeDrawable * drawSun = new ShapeDrawable(sphereSun);
drawSun->setColor(Vec4(1, 1, 0, 1));
geodeSun->addDrawable(drawSun);
root->addChild(geodeSun);
viewer->setSceneData(root);
viewer->setUpViewInWindow(100,100,512,512);
viewer->run();
}
Here are the errors.
> 1>------ Build started: Project: Planets, Configuration: Release Win32 ------
> 1>Compiling...
> 1>MainThread.cpp
> 1>.\MainThread.cpp(104) : error C2061: syntax error : identifier 'text'
> 1>.\MainThread.cpp(105) : error C2001: newline in constant
> 1>.\MainThread.cpp(105) : error C2015: too many characters in constant
> 1>.\MainThread.cpp(106) : error C2146: syntax error : missing ')' before
> identifier 'textX'
> 1>.\MainThread.cpp(109) : error C2065: 'sxsgeode' : undeclared identifier
> 1>.\MainThread.cpp(109) : error C2227: left of '->addDrawable' must point to
> class/struct/union/generic type
> 1> type is ''unknown-type''
> 1>.\MainThread.cpp(110) : error C2039: 'VZ_PLANE' : is not a member of
> 'osgText::Text'
> 1> C:\Users\J\Desktop\OpenSceneGraph-2.8.2\include\osgText/Text(27) :
> see declaration of 'osgText::Text'
> 1>.\MainThread.cpp(110) : error C2065: 'VZ_PLANE' : undeclared identifier
> 1>Build log was saved at
> "file://c:\Users\J\Desktop\Planets\Planets\Release\BuildLog.htm"
> 1>Planets - 8 error(s), 0 warning(s)
> ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I also have 4 questions please.
1. I can't get textures working to make the circles look like the 9 planets,
how do I do this?
2. How can I get 5 planets to go the way they're going now, and 4 planets to go
the other way?
3. How can I add names to make the planets.
4. How can I do a space like background, not just the blue one I have now?
Thanks all.
(Please Note: I'm basically a 1st grader on my first day at school, so please
try and use simple English).
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=27579#27579
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org