osg::Node* createModel()
{
    // create the root node which will hold the model.
    osg::Group *root = new osg::Group();

    // add the drawable into a single geode to be shared...
    osg::Billboard *center = new osg::Billboard();

    center->setMode(osg::Billboard::POINT_ROT_EYE);
    center->addDrawable(
        createSquare(osg::Vec3(-0.5f, 0.0f, -0.5f), osg::Vec3(1.0f, 0.0f, 0.0f), osg::Vec3(0.0f, 0.0f, 1.0f), osgDB::readImageFile("Images/reflect.rgb")),
        osg::Vec3(0.0f, 0.0f, 0.0f));

    osg::Billboard *x_arrow = new osg::Billboard();
    x_arrow->setMode(osg::Billboard::AXIAL_ROT);
    x_arrow->setAxis(osg::Vec3(1.0f, 0.0f, 0.0f));
    x_arrow->setNormal(osg::Vec3(0.0f, -1.0f, 0.0f));
    x_arrow->addDrawable(
        createSquare(osg::Vec3(-0.5f, 0.0f, -0.5f), osg::Vec3(1.0f, 0.0f, 0.0f), osg::Vec3(0.0f, 0.0f, 1.0f), osgDB::readImageFile("Cubemap_axis/posx.png")),
        osg::Vec3(5.0f, 0.0f, 0.0f));

    osg::Billboard *y_arrow = new osg::Billboard();
    y_arrow->setMode(osg::Billboard::AXIAL_ROT);
    y_arrow->setAxis(osg::Vec3(0.0f, 1.0f, 0.0f));
    y_arrow->setNormal(osg::Vec3(1.0f, 0.0f, 0.0f));
    y_arrow->addDrawable(
        createSquare(osg::Vec3(0.0f, -0.5f, -0.5f), osg::Vec3(0.0f, 1.0f, 0.0f), osg::Vec3(0.0f, 0.0f, 1.0f), osgDB::readImageFile("Cubemap_axis/posy.png")),
        osg::Vec3(0.0f, 5.0f, 0.0f));

    osg::Billboard *z_arrow = new osg::Billboard();
    z_arrow->setMode(osg::Billboard::AXIAL_ROT);
    z_arrow->setAxis(osg::Vec3(0.0f, 0.0f, 1.0f));
    z_arrow->setNormal(osg::Vec3(0.0f, -1.0f, 0.0f));
    z_arrow->addDrawable(
        createSquare(osg::Vec3(-0.5f, 0.0f, -0.5f), osg::Vec3(1.0f, 0.0f, 0.0f), osg::Vec3(0.0f, 0.0f, 1.0f), osgDB::readImageFile("Cubemap_axis/posz.png")),
        osg::Vec3(0.0f, 0.0f, 5.0f));



    osg::Geode *axis = new osg::Geode();
    axis->addDrawable(createAxis(osg::Vec3(0.0f, 0.0f, 0.0f), osg::Vec3(5.0f, 0.0f, 0.0f), osg::Vec3(0.0f, 5.0f, 0.0f), osg::Vec3(0.0f, 0.0f, 5.0f)));


    root->addChild(center);
    root->addChild(x_arrow);
    root->addChild(y_arrow);
    root->addChild(z_arrow);
    root->addChild(axis);

    return root;
}
示例#2
0
int main(int argc, char **argv)
{
  testInit(argc, argv, 400,400, "ShivaVG: Radial Gradient Test");
  testCallback(TEST_CALLBACK_DISPLAY, (CallbackFunc)display);
  testCallback(TEST_CALLBACK_BUTTON, (CallbackFunc)click);
  testCallback(TEST_CALLBACK_DRAG, (CallbackFunc)drag);
  testCallback(TEST_CALLBACK_KEY, (CallbackFunc)key);
  
  p = testCreatePath();
  center = testCreatePath();
  focus = testCreatePath();
  radius = testCreatePath();
  
  cx = testWidth()/2;
  cy = testHeight()/2;
  fx = cx;
  fy = cy;
  r = sqx/2;
  
  radialFill = vgCreatePaint();
  blackFill = vgCreatePaint();
  vgSetParameterfv(blackFill, VG_PAINT_COLOR, 4, black);
  
  createSquare(p);
  createRadial();
  
  testOverlayString("Press H for a list of commands");
  testOverlayColor(1,1,1,1);
  testRun();
  
  return EXIT_SUCCESS;
}
示例#3
0
文件: maze.c 项目: jauthier/cis2520
void parseFile(char * fileName){
    
    FILE * fp;
    char temp;
    int xCount;
    int yCount;
    Square * hold;
    
    fp = fopen(fileName, "r");
    if (fp == NULL){ // check to make sure file opened
        printf("no such file\n");
        exit(0);
    }
    
    yCount = 0;
    temp = fgetc(fp);
    
    while (temp != EOF){ // while we are not at the end of the file
        xCount = 0;
        while(temp != '\n'){ //while we are not at the end of the line
            hold = createSquare(temp, xCount, yCount);
            maze[xCount][yCount] = hold;   
            if (temp == 'S')
                current = hold;
            temp = fgetc(fp);
            xCount++; // increment in the x direction
        }
	temp = fgetc(fp);
        yCount++;
    }
    fclose(fp);
    sizeX = xCount;
    sizeY = yCount;
}
示例#4
0
int main(int argc, char **argv)
{
  testInit(argc, argv, 400,400, "ShivaVG: Linear Gradient Test");
  testCallback(TEST_CALLBACK_DISPLAY, (CallbackFunc)display);
  testCallback(TEST_CALLBACK_BUTTON, (CallbackFunc)click);
  testCallback(TEST_CALLBACK_DRAG, (CallbackFunc)drag);
  testCallback(TEST_CALLBACK_KEY, (CallbackFunc)key);
  testCallback(TEST_CALLBACK_RESHAPE, (CallbackFunc)reshape);
  
  p = testCreatePath();
  org = testCreatePath();
  
  blackFill = vgCreatePaint();
  vgSetParameterfv(blackFill, VG_PAINT_COLOR, 4, black);
  
  backImage = createImageFromJpeg(IMAGE_DIR"test_img_violin.jpg");
  patternImage = createImageFromJpeg(IMAGE_DIR"test_img_shivavg.jpg");
  patternFill = vgCreatePaint();
  
  createSquare(p);
  createOrigin(org);
  createPattern();
  
  testOverlayString("Press H for a list of commands");
  testOverlayColor(1,1,1,1);
  testRun();
  
  return EXIT_SUCCESS;
}
示例#5
0
文件: display.cpp 项目: lm92/CG
void myDisplay() {

  GLdouble x = TORUS_INIT_X, y = TORUS_INIT_Y, z = TORUS_INIT_Z;

  
  glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  
  glClear(GL_COLOR_BUFFER_BIT);

  createSquare(TABLE_X, TABLE_Y, TABLE_Z, TABLE_RAD);

  glPushMatrix();
  
  createTrack(x, y, z);

  glPopMatrix();

  glPushMatrix();

  x += TRACK_SIZE;
  
  createTrack(x, y, z);

  glPopMatrix();

  glFlush();


}
void init(void)
{
    // shader = new Shader();
	//assuming VOXELNUM = 4
	glGenTextures(1, &lookupTableTexture);
	glBindTexture(GL_TEXTURE_2D, lookupTableTexture);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_R8I, 16, 256, 0,  GL_RED_INTEGER, GL_BYTE, &triTable[0][0]);
	
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glBindTexture(GL_TEXTURE_2D, 0);
	//glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
	
	texID[0] = utilCreate3DVoxel(VOXELNUM);
	texID[1] = utilCreate3DVoxel(VOXELNUM);


    const char* Vshader_render = "#version 440 \n in vec3 Vertex;\nvoid "
                          "main() {	\n	gl_Position = vec4(Vertex,1.0);\n}";
    const char* Gshader_render = textFileRead("simpleG.geom");

	const char* Fshader_render = textFileRead("simpleFshader.frag");
    shader_rendering.init(Vshader_render, Fshader_render, Gshader_render, 0);



    glGenTextures(1, &incomingImage);
	glBindTexture(GL_TEXTURE_2D, incomingImage);
	glTexImage2D(GL_TEXTURE_2D, 0,  GL_R16F , pngObject.width, pngObject.height, 0,   GL_RED,  GL_UNSIGNED_SHORT, &pngObject.depthMap[0]);
	
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glBindTexture(GL_TEXTURE_2D, 0);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 4);


    ping = 0;
    glGenFramebuffers(1, &FramebufferName);
    glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
    glFramebufferTexture(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0, texID[0],0);
    glFramebufferTexture(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT1, texID[1],0);
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    const char* Gshader_merge = textFileRead("simpleLayeredRender.geom");
    const char* Fshader_merge = textFileRead("mergeVoxels.frag");

    shader_merging.init(Vshader_render, Fshader_merge, Gshader_merge, 0);

    const char* Gshader_indicator = textFileRead("cubeGeomtry.geom");
    shader_indicator.init(Vshader_render,Fshader_render,Gshader_indicator,0);
	createSquare();

	K_camera = glm::mat3(535.4, 0, 320.1, 0, 539.2, 247.6, 0, 0, 1);
	invK = glm::inverse(K_camera);
}
示例#7
0
void BoxContainer::addSquare() {
	clrscr();
	s = createSquare();
	square_found = true;
	sqrList.push_back(*s);
	delete s;
	drawAllSquares();
}
osg::Node* createModel(osg::ArgumentParser &arguments)
{
    // create the geometry of the model, just a simple 2d quad right now.
    osg::Geode *geode = new osg::Geode;

    geode->addDrawable(createSquare());

    geode->setStateSet(createState(arguments));

    return geode;
}
osg::Node* createModel()
{
    // create the geometry of the model, just a simple 2d quad right now.
    osg::Geode *geode = new osg::Geode;

    geode->addDrawable(createSquare());

    geode->setUpdateCallback(new UpdateStateCallback());

    geode->setStateSet(createState());

    return geode;
}
示例#10
0
void initializeMapSquares()
{
    aMapSquare = (SQUARE**)malloc(mapWidth * sizeof(SQUARE*));

	for(int i = 0; i < mapWidth; i++)
	{
	        aMapSquare[i] = (SQUARE*)malloc(mapWidth * sizeof(SQUARE));
	}

    for (int y = 0; y < mapWidth; y++)
    {
        for (int x = 0; x < mapWidth; x++)
        {
               createSquare(EMPTY, x, y);
        }
    }
}
示例#11
0
void HelloWorld::update(float time){
	if(!m_pLiveSquare){
		m_pLiveSquare = createSquare(m_start);
		//m_pLiveSquare->setPosition(ccp(0, m_limitSize.height/2*m_scale));
		m_nFrame = 0;
		return;
	}

	double d = m_livePoint.y - m_reference.y;
	m_nFrame++;
	if(m_nFrame%(int)FRAME_RATE == 0){
		m_nFrame = 0;
		liveMove(_DIRECTION_DWON, m_nSquareSize);
	} else {
		//check
		checkAndRemove();
	}

}
示例#12
0
int main( int argc, char **argv )
{
    // use an ArgumentParser object to manage the program arguments.
    osg::ArgumentParser arguments(&argc,argv);

    // set up the usage document, in case we need to print out how to use this program.
    arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates use of osg::AnimationPath and UpdateCallbacks for adding animation to your scenes.");
    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
    arguments.getApplicationUsage()->addCommandLineOption("-o <filename>","Write created model to file");

    // initialize the viewer.
    osgViewer::Viewer viewer;

    osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;
    viewer.setCameraManipulator( keyswitchManipulator.get() );

    SolarSystem solarSystem;

    while (arguments.read("--radiusSpace",solarSystem._radiusSpace)) { }
    while (arguments.read("--radiusSun",solarSystem._radiusSun)) { }
    while (arguments.read("--radiusMercury",solarSystem._radiusMercury)) { }
    while (arguments.read("--radiusVenus",solarSystem._radiusVenus)) { }
    while (arguments.read("--radiusEarth",solarSystem._radiusEarth)) { }
    while (arguments.read("--radiusMoon",solarSystem._radiusMoon)) { }
    while (arguments.read("--radiusMars",solarSystem._radiusMars)) { }
    while (arguments.read("--radiusJupiter",solarSystem._radiusJupiter)) { }

    while (arguments.read("--RorbitEarth",solarSystem._RorbitEarth)) { }
    while (arguments.read("--RorbitMoon",solarSystem._RorbitMoon)) { }

    while (arguments.read("--rotateSpeedEarthAndMoon",solarSystem._rotateSpeedEarthAndMoon)) { }
    while (arguments.read("--rotateSpeedEarth",solarSystem._rotateSpeedEarth)) { }
    while (arguments.read("--rotateSpeedMoon",solarSystem._rotateSpeedMoon)) { }
    while (arguments.read("--tiltEarth",solarSystem._tiltEarth)) { }

    while (arguments.read("--mapSpace",solarSystem._mapSpace)) { }
    while (arguments.read("--mapEarth",solarSystem._mapEarth)) { }
    while (arguments.read("--mapEarthNight",solarSystem._mapEarthNight)) { }
    while (arguments.read("--mapMoon",solarSystem._mapMoon)) { }

    while (arguments.read("--rotateSpeedFactor",solarSystem._rotateSpeedFactor)) { }
    while (arguments.read("--RorbitFactor",solarSystem._RorbitFactor)) { }
    while (arguments.read("--radiusFactor",solarSystem._radiusFactor)) { }

    solarSystem.rotateSpeedCorrection();
    solarSystem.RorbitCorrection();
    solarSystem.radiusCorrection();

    std::string writeFileName;
    while (arguments.read("-o",writeFileName)) { }


    osgGA::NodeTrackerManipulator::TrackerMode trackerMode = osgGA::NodeTrackerManipulator::NODE_CENTER_AND_ROTATION;
    std::string mode;
    while (arguments.read("--tracker-mode",mode))
    {
        if (mode=="NODE_CENTER_AND_ROTATION") trackerMode = osgGA::NodeTrackerManipulator::NODE_CENTER_AND_ROTATION;
        else if (mode=="NODE_CENTER_AND_AZIM") trackerMode = osgGA::NodeTrackerManipulator::NODE_CENTER_AND_AZIM;
        else if (mode=="NODE_CENTER") trackerMode = osgGA::NodeTrackerManipulator::NODE_CENTER;
        else
        {
            std::cout<<"Unrecognized --tracker-mode option "<<mode<<", valid options are:"<<std::endl;
            std::cout<<"    NODE_CENTER_AND_ROTATION"<<std::endl;
            std::cout<<"    NODE_CENTER_AND_AZIM"<<std::endl;
            std::cout<<"    NODE_CENTER"<<std::endl;
            return 1;
        }
    }


    osgGA::NodeTrackerManipulator::RotationMode rotationMode = osgGA::NodeTrackerManipulator::TRACKBALL;
    while (arguments.read("--rotation-mode",mode))
    {
        if (mode=="TRACKBALL") rotationMode = osgGA::NodeTrackerManipulator::TRACKBALL;
        else if (mode=="ELEVATION_AZIM") rotationMode = osgGA::NodeTrackerManipulator::ELEVATION_AZIM;
        else
        {
            std::cout<<"Unrecognized --rotation-mode option "<<mode<<", valid options are:"<<std::endl;
            std::cout<<"    TRACKBALL"<<std::endl;
            std::cout<<"    ELEVATION_AZIM"<<std::endl;
            return 1;
        }
    }


    // solarSystem.printParameters();

    // if user request help write it out to cout.
    if (arguments.read("-h") || arguments.read("--help"))
    {
        std::cout << "setup the following arguments: " << std::endl;
        std::cout << "\t--radiusSpace: double" << std::endl;
        std::cout << "\t--radiusSun: double" << std::endl;
        std::cout << "\t--radiusMercury: double" << std::endl;
        std::cout << "\t--radiusVenus: double" << std::endl;
        std::cout << "\t--radiusEarth: double" << std::endl;
        std::cout << "\t--radiusMoon: double" << std::endl;
        std::cout << "\t--radiusMars: double" << std::endl;
        std::cout << "\t--radiusJupiter: double" << std::endl;

        std::cout << "\t--RorbitMercury: double" << std::endl;
        std::cout << "\t--RorbitVenus: double" << std::endl;
        std::cout << "\t--RorbitEarth: double" << std::endl;
        std::cout << "\t--RorbitMoon: double" << std::endl;
        std::cout << "\t--RorbitMars: double" << std::endl;
        std::cout << "\t--RorbitJupiter: double" << std::endl;

        std::cout << "\t--rotateSpeedMercury: double" << std::endl;
        std::cout << "\t--rotateSpeedVenus: double" << std::endl;
        std::cout << "\t--rotateSpeedEarthAndMoon: double" << std::endl;
        std::cout << "\t--rotateSpeedEarth: double" << std::endl;
        std::cout << "\t--rotateSpeedMoon: double" << std::endl;
        std::cout << "\t--rotateSpeedMars: double" << std::endl;
        std::cout << "\t--rotateSpeedJupiter: double" << std::endl;

        std::cout << "\t--tiltEarth: double" << std::endl;

        std::cout << "\t--mapSpace: string" << std::endl;
        std::cout << "\t--mapSun: string" << std::endl;
        std::cout << "\t--mapMercury: string" << std::endl;
        std::cout << "\t--mapVenus: string" << std::endl;
        std::cout << "\t--mapEarth: string" << std::endl;
        std::cout << "\t--mapEarthNight: string" << std::endl;
        std::cout << "\t--mapMoon: string" << std::endl;
        std::cout << "\t--mapMars: string" << std::endl;
        std::cout << "\t--mapJupiter: string" << std::endl;

        std::cout << "\t--rotateSpeedFactor: string" << std::endl;
        std::cout << "\t--RorbitFactor: string" << std::endl;
        std::cout << "\t--radiusFactor: string" << std::endl;

        return 1;
    }

    // any option left unread are converted into errors to write out later.
    arguments.reportRemainingOptionsAsUnrecognized();

    // report any errors if they have occurred when parsing the program arguments.
    if (arguments.errors())
    {
        arguments.writeErrorMessages(std::cout);
        return 1;
    }


    osg::Group* root = new osg::Group;

    osg::ClearNode* clearNode = new osg::ClearNode;
    clearNode->setClearColor(osg::Vec4(0.0f,0.0f,0.0f,1.0f));
    root->addChild(clearNode);

    osg::Group* sunLight = solarSystem.createSunLight();
    root->addChild(sunLight);

    // create the sun
    osg::Node* solarSun = solarSystem.createPlanet( solarSystem._radiusSun, "Sun", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f), solarSystem._mapSun );
    osg::StateSet* sunStateSet = solarSun->getOrCreateStateSet();
    osg::Material* material = new osg::Material;
    material->setEmission( osg::Material::FRONT_AND_BACK, osg::Vec4( 1.0f, 1.0f, 0.0f, 0.0f ) );
    sunStateSet->setAttributeAndModes( material, osg::StateAttribute::ON );

    osg::Billboard* sunBillboard = new osg::Billboard();
    sunBillboard->setMode(osg::Billboard::POINT_ROT_EYE);
    sunBillboard->addDrawable(
        createSquare(osg::Vec3(-150.0f,0.0f,-150.0f),osg::Vec3(300.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,300.0f),createBillboardImage( osg::Vec4( 1.0, 1.0, 0, 1.0f), 64, 1.0) ),
        osg::Vec3(0.0f,0.0f,0.0f));

    sunLight->addChild( sunBillboard );


    // stick sun right under root, no transformations for the sun
    sunLight->addChild( solarSun );

    // create light source in the sun

/*
*********************************************
**  earthMoonGroup and Transformations
*********************************************
*/
    // create earth and moon
    osg::Node* earth = solarSystem.createPlanet( solarSystem._radiusEarth, "Earth", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f), solarSystem._mapEarth, solarSystem._mapEarthNight );
    osg::Node* moon = solarSystem.createPlanet( solarSystem._radiusMoon, "Moon", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f), solarSystem._mapMoon );

    // create transformations for the earthMoonGroup
    osg::MatrixTransform* aroundSunRotationEarthMoonGroup = solarSystem.createRotation( solarSystem._RorbitEarth, solarSystem._rotateSpeedEarthAndMoon );
//    osg::MatrixTransform* earthMoonGroupPosition = solarSystem.createTranslationAndTilt( solarSystem._RorbitEarth, solarSystem._tiltEarth );
    osg::MatrixTransform* earthMoonGroupPosition = solarSystem.createTranslationAndTilt( solarSystem._RorbitEarth, 0.0 );


    //Group with earth and moon under it
    osg::Group* earthMoonGroup = new osg::Group;

    //transformation to rotate the earth around itself
    osg::MatrixTransform* earthAroundItselfRotation = solarSystem.createRotation ( 0.0, solarSystem._rotateSpeedEarth );

    //transformations for the moon
    osg::MatrixTransform* moonAroundEarthRotation = solarSystem.createRotation( solarSystem._RorbitMoon, solarSystem._rotateSpeedMoon );
    osg::MatrixTransform* moonTranslation = solarSystem.createTranslationAndTilt( solarSystem._RorbitMoon, 0.0 );


    moonTranslation->addChild( moon );
    moonAroundEarthRotation->addChild( moonTranslation );
    earthMoonGroup->addChild( moonAroundEarthRotation );

    earthAroundItselfRotation->addChild( earth );
    earthMoonGroup->addChild( earthAroundItselfRotation );

    earthMoonGroupPosition->addChild( earthMoonGroup );

    aroundSunRotationEarthMoonGroup->addChild( earthMoonGroupPosition );

    sunLight->addChild( aroundSunRotationEarthMoonGroup );
/*
*********************************************
**  end earthMoonGroup and Transformations
*********************************************
*/

/*
*********************************************
**  Mercury and Transformations
*********************************************
*/
    osg::Node* mercury = solarSystem.createPlanet( solarSystem._radiusMercury, "Mercury", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ), solarSystem._mapMercury, "" );

    osg::MatrixTransform* aroundSunRotationMercury = solarSystem.createRotation( solarSystem._RorbitMercury, solarSystem._rotateSpeedMercury );
    osg::MatrixTransform* mercuryPosition = solarSystem.createTranslationAndTilt( solarSystem._RorbitMercury, 0.0f );

    mercuryPosition->addChild( mercury );
    aroundSunRotationMercury->addChild( mercuryPosition );

    sunLight->addChild( aroundSunRotationMercury );
/*
*********************************************
**  end Mercury and Transformations
*********************************************
*/

/*
*********************************************
**  Venus and Transformations
*********************************************
*/
    osg::Node* venus = solarSystem.createPlanet( solarSystem._radiusVenus, "Venus", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ), solarSystem._mapVenus, "" );

    osg::MatrixTransform* aroundSunRotationVenus = solarSystem.createRotation( solarSystem._RorbitVenus, solarSystem._rotateSpeedVenus );
    osg::MatrixTransform* venusPosition = solarSystem.createTranslationAndTilt( solarSystem._RorbitVenus, 0.0f );

    venusPosition->addChild( venus );
    aroundSunRotationVenus->addChild( venusPosition );

    sunLight->addChild( aroundSunRotationVenus );
/*
*********************************************
**  end Venus and Transformations
*********************************************
*/

/*
*********************************************
**  Mars and Transformations
*********************************************
*/
    osg::Node* mars = solarSystem.createPlanet( solarSystem._radiusMars, "Mars", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ), solarSystem._mapMars, "" );

    osg::MatrixTransform* aroundSunRotationMars = solarSystem.createRotation( solarSystem._RorbitMars, solarSystem._rotateSpeedMars );
    osg::MatrixTransform* marsPosition = solarSystem.createTranslationAndTilt( solarSystem._RorbitMars, 0.0f );

    marsPosition->addChild( mars );
    aroundSunRotationMars->addChild( marsPosition );

    sunLight->addChild( aroundSunRotationMars );
/*
*********************************************
**  end Mars and Transformations
*********************************************
*/

/*
*********************************************
**  Jupiter and Transformations
*********************************************
*/
    osg::Node* jupiter = solarSystem.createPlanet( solarSystem._radiusJupiter, "Jupiter", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ), solarSystem._mapJupiter, "" );

    osg::MatrixTransform* aroundSunRotationJupiter = solarSystem.createRotation( solarSystem._RorbitJupiter, solarSystem._rotateSpeedJupiter );
    osg::MatrixTransform* jupiterPosition = solarSystem.createTranslationAndTilt( solarSystem._RorbitJupiter, 0.0f );

    jupiterPosition->addChild( jupiter );
    aroundSunRotationJupiter->addChild( jupiterPosition );

    sunLight->addChild( aroundSunRotationJupiter );
/*
*********************************************
**  end Jupiter and Transformations
*********************************************
*/

/*
    // add space, but don't light it, as its not illuminated by our sun
    osg::Node* space = solarSystem.createSpace( "Space", solarSystem._mapSpace );
    space->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
    root->addChild( space );
*/

    if (!writeFileName.empty())
    {
        osgDB::writeNodeFile(*root, writeFileName);
        std::cout<<"Written solar system to \""<<writeFileName<<"\""<<std::endl;
        return 0;
    }


    // run optimization over the scene graph
    osgUtil::Optimizer optimzer;
    optimzer.optimize( root );

    // set the scene to render
    viewer.setSceneData( root );


    // set up tracker manipulators, once for each astral body
    {
        FindNamedNodeVisitor fnnv("Moon");
        root->accept(fnnv);

        if (!fnnv._foundNodes.empty())
        {
            // set up the node tracker.
            osgGA::NodeTrackerManipulator* tm = new osgGA::NodeTrackerManipulator;
            tm->setTrackerMode( trackerMode );
            tm->setRotationMode( rotationMode );
            tm->setTrackNode( fnnv._foundNodes.front().get() );

            unsigned int num = keyswitchManipulator->getNumMatrixManipulators();
            keyswitchManipulator->addMatrixManipulator( 'm', "moon", tm );
            keyswitchManipulator->selectMatrixManipulator( num );
        }
    }

    {
        FindNamedNodeVisitor fnnv("Earth");
        root->accept(fnnv);

        if (!fnnv._foundNodes.empty())
        {
            // set up the node tracker.
            osgGA::NodeTrackerManipulator* tm = new osgGA::NodeTrackerManipulator;
            tm->setTrackerMode( trackerMode );
            tm->setRotationMode( rotationMode );
            tm->setTrackNode( fnnv._foundNodes.front().get() );

            unsigned int num = keyswitchManipulator->getNumMatrixManipulators();
            keyswitchManipulator->addMatrixManipulator( 'e', "earth", tm);
            keyswitchManipulator->selectMatrixManipulator( num );
        }
    }

    {
        FindNamedNodeVisitor fnnv("Sun");
        root->accept(fnnv);

        if (!fnnv._foundNodes.empty())
        {
            // set up the node tracker.
            osgGA::NodeTrackerManipulator* tm = new osgGA::NodeTrackerManipulator;
            tm->setTrackerMode( trackerMode );
            tm->setRotationMode( rotationMode );
            tm->setTrackNode( fnnv._foundNodes.front().get() );

            unsigned int num = keyswitchManipulator->getNumMatrixManipulators();
            keyswitchManipulator->addMatrixManipulator( 's', "sun", tm);
            keyswitchManipulator->selectMatrixManipulator( num );
        }
    }

    return viewer.run();

}// end main
示例#13
0
void reshape(int x, int y)
{
  vgClearPath(p, VG_PATH_CAPABILITY_ALL);
  createSquare(p);
}
示例#14
0
int
main(int argc, char **argv)
{
	/* define the event handlers for the events */
	DACallbacks eventCallbacks = {
		destroy, /* destroy */
		buttonPress, /* buttonPress */
		buttonRelease, /* buttonRelease */
		mouseMove, /* motion (mouse) */
		mouseEnter, /* mouse enters window */
		mouseLeave, /* mouse leaves window */
		NULL    /* timeout */
	};

	/* define regions (x, y, width, height) that need event-handling */
	Region clipRegion = XCreateRegion();

	DARect btn = {0, 0, 16, 16},
	       square = {0, 25, 22, 22},
	       slider = {24, 0, 23, 48};

	/* define what to do if an event occurs in a rectangle */
	DAActionRect *buttonPressRects, *buttonReleaseRects,
	*mouseMoveRects, *mouseEnterRects, *mouseLeaveRects;

	buttonPressRects = malloc(3 * sizeof(DAActionRect));
	buttonPressRects[0] = setRectAction(btn, btnDown);
	buttonPressRects[1] = setRectAction(square, squareDown);
	buttonPressRects[2] = setRectAction(slider, sliderDown);

	buttonReleaseRects = malloc(2 * sizeof(DAActionRect));
	buttonReleaseRects[0] = setRectAction(btn, btnUp);
	buttonReleaseRects[1] = setRectAction(slider, sliderUp);

	mouseMoveRects = malloc(sizeof(DAActionRect));
	mouseMoveRects[0] = setRectAction(slider, sliderMove);

	mouseEnterRects = malloc(sizeof(DAActionRect));
	mouseEnterRects[0] = setRectAction(slider, sliderEnter);

	mouseLeaveRects = malloc(2 * sizeof(DAActionRect));
	mouseLeaveRects[0] = setRectAction(btn, btnLeave);
	mouseLeaveRects[1] = setRectAction(slider, sliderLeave);


	/* XXX: make action rectangles available outside main()
	 * ...libDockapp should be able to do this... (reminder)
	 */
	actionRects = malloc(6 * sizeof(DAActionRect *));
	actionRects[0] = buttonPressRects;
	actionRects[1] = buttonReleaseRects;
	actionRects[2] = mouseMoveRects;
	actionRects[3] = mouseEnterRects;
	actionRects[4] = mouseLeaveRects;
	actionRects[5] = NULL;

	/* provide standard command-line options */
	DAParseArguments(
		argc, argv, /* Where the options come from */
		NULL, 0, /* Our list with options - none as you can see */
		"This is the help text for the rectangle example of how to "
		"use libDockapp.\n",
		"Rectangle example version 1.0");

	/* Tell libdockapp what version we expect it to be, so that you can use
	 * older programs with newer versions of libdockapp with less risc for
	 * compatibility problems.
	 */
	DASetExpectedVersion(20030126);

	/* Initialize a dockapp */
	DAInitialize(
		"",             /* Use default display */
		"daRectangleExample",   /* WM_CLASS hint; don't use chars in [.?*: ] */
		48, 48,         /* geometry of dockapp internals */
		argc, argv      /* (needed internally) */
		);

	/* Create a pixmap to draw on, and to display */
	pixmap = DAMakePixmap(); /* size == dockapp geometry (48,48) */

	colors = setGCs(pixmap);

	XFillRectangle(DADisplay, pixmap, DAClearGC, 0, 0, 48, 48);
	XClearWindow(DADisplay, DAWindow);

	/* Make a "Region" from the shapes we have */
	XUnionRectWithRegion(&btn, clipRegion, clipRegion);
	XUnionRectWithRegion(&square, clipRegion, clipRegion);
	XUnionRectWithRegion(&slider, clipRegion, clipRegion);

	/* Make this region a window shape mask */
	XShapeCombineRegion(DADisplay, DAWindow, ShapeBounding,
			    0, 0, clipRegion, ShapeSet);

	/* We don't need the region anymore (it is copied by XShapeCombineRegion).
	 * XXX: That's not certain, it is not documented. XSetRegion does so,
	 * though, so it is a likely assumption that it does copy.
	 */
	XDestroyRegion(clipRegion);

	/* The cursor we want to use.
	 * Specify 'None' for the default,
	 * or one from X11/cursorfont.h
	 */
	pointer = XCreateFontCursor(DADisplay, XC_based_arrow_up);
	XDefineCursor(DADisplay, DAWindow, pointer);

	/* a square with an image that changes when clicked (A button). */
	createBtn(btn);

	/* a square that shows the number of the mouse-button pressed on click. */
	createSquare(square);

	/* a slider a using two dashed line GC's. */
	createSlider(slider);

	/* Tell libdockapp this is the pixmap that we want to show */
	DASetPixmap(pixmap);

	/* Process events every 100ms */
	DASetTimeout(100);

	/* set event callbacks */
	DASetCallbacks(&eventCallbacks);

	/* Display the pixmap we said it to show */
	DAShow();

	/* Process events and keep the dockapp running */
	DAEventLoop();

	return 0;
}