Example #1
0
	void TankWarWorld::SetupDefaultGame()
	{

		createPlanes();
		createLights();
		createTanks();
	}
Example #2
0
vector<Item*> ItemFactory::createItems(const int itemLevel, const int dungeonSize)
{
	vector<Item*> _items;

	// Create all seperate item types
	vector<Item*> _lights		= createLights(Random::getRandomNumber(static_cast<int>(ceil(dungeonSize / MIN_LIGHT_ROLL_MODIFIER)), 
																	   static_cast<int>(ceil(dungeonSize / MAX_LIGHT_ROLL_MODIFIER))));
	vector<Item*> _potions		= createPotions(Random::getRandomNumber(static_cast<int>(ceil(dungeonSize / MIN_POTION_ROLL_MODIFIER)), 
																		static_cast<int>(ceil(dungeonSize / MAX_POTION_ROLL_MODIFIER))));
	vector<Item*> _specialItems = createSpecialItems();
	vector<Item*> _armours		= createArmours(itemLevel, Random::getRandomNumber(static_cast<int>(ceil(dungeonSize / MIN_ARMOUR_ROLL_MODIFIER)), 
																				   static_cast<int>(ceil(dungeonSize / MAX_ARMOUR_ROLL_MODIFIER))));
	vector<Item*> _weapons		= createWeapons(itemLevel, Random::getRandomNumber(static_cast<int>(ceil(dungeonSize / MIN_WEAPON_ROLL_MODIFIER)), 
																				   static_cast<int>(ceil(dungeonSize / MAX_WEAPON_ROLL_MODIFIER))));

	// Reserve enough space for the parent container and move all item container elements to parent container
	_items.reserve(_items.size() + _lights.size() + _potions.size() + _specialItems.size() + _armours.size() +_weapons.size());
	move(_lights.begin(),		_lights.end(),			back_inserter(_items));
	move(_potions.begin(),		_potions.end(),			back_inserter(_items));
	move(_specialItems.begin(), _specialItems.end(),	back_inserter(_items));
	move(_armours.begin(),		_armours.end(),			back_inserter(_items));
	move(_weapons.begin(),		_weapons.end(),			back_inserter(_items));

	// Shuffle the parent container so the container is truly random
	shuffle(_items.begin(), _items.end(), Random::getRandomEngine());

	return _items;
}
void init(void)
{
	printf("Enter the ip address of other machine:  ");
	scanf("%s",DEST_IP);
	glClearColor (0.0, 0.0, 0.0, 0.0);
	glClearDepth(1.0);
	glDisable(GL_CULL_FACE);
	glShadeModel (GL_SMOOTH);
	glMatrixMode (GL_PROJECTION);
	glLoadIdentity ();
	glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 1000.0);
	glMatrixMode (GL_MODELVIEW);
	init_net();
	init_car_model();
	init_key_press();
	createLights();
}
int main(int argc, char **argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
	glutInitWindowSize(640, 480);
	glutCreateWindow("Graphics Assignment 2");
	glutDisplayFunc(display);
	glutSpecialFunc(buttonPressed);
	glutKeyboardFunc(keyPress);

	createLights();


	
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_LIGHTING);

	toggleLightOne();

	glutMainLoop();
	return 0;
}
Example #5
0
void Scene::createScene()
{
    rootNode = moduleRegistry->getRootNode();

    moduleRegistry->registerDynamicsWorld(dynamicsWorld);

    lastCheckpoint = new btVector3();
    moduleRegistry->registerLastCheckpoint(lastCheckpoint);
    
    moduleRegistry->registerAllowMovement(&allowMovement);
    moduleRegistry->registerCameraAngle(&cameraAngle);
    
    createLights();
    // SKYBOX !
    Skybox* skybox = new Skybox(rootNode,"skybox1");

    // 2D TEXT FOR DEBUGGING PURPOSE !
    text2d = new Text2D(rootNode);
    moduleRegistry->registerText2D(text2d);

    // 3D TEXT FOR FUN PURPOSE !
    text3d = new Text3D(rootNode);
    moduleRegistry->registerText3D(text3d);

    // THE MIGHTY BALL
    ball = new Ball(osg::Vec3f(0, 0, 50), 7., moduleRegistry);
    moduleRegistry->getInputManager()->setBall(ball);
    moduleRegistry->registerBall(ball);
    ball->setModuleRegistry(moduleRegistry);
    ballBody = ball->getBody();

    createLevel(currentLevel);

#ifndef VRJUGGLER
    moduleRegistry->getSceneView()->setSceneData(rootNode);
#endif
}
Example #6
0
osg::Node* createRoom(osg::Node* loadedModel)
{
    // default scale for this model.
    osg::BoundingSphere bs(osg::Vec3(0.0f,0.0f,0.0f),1.0f);

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

    if (loadedModel)
    {
        const osg::BoundingSphere& loaded_bs = loadedModel->getBound();

        osg::PositionAttitudeTransform* pat = new osg::PositionAttitudeTransform();
        pat->setPivotPoint(loaded_bs.center());

        pat->setUpdateCallback(new ModelTransformCallback(loaded_bs));
        pat->addChild(loadedModel);

        bs = pat->getBound();

        root->addChild(pat);

    }

    bs.radius()*=1.5f;

    // create a bounding box, which we'll use to size the room.
    osg::BoundingBox bb;
    bb.expandBy(bs);


    // create statesets.
    osg::StateSet* rootStateSet = new osg::StateSet;
    root->setStateSet(rootStateSet);

    osg::StateSet* wall = new osg::StateSet;
    wall->setMode(GL_CULL_FACE,osg::StateAttribute::ON);

    osg::StateSet* floor = new osg::StateSet;
    floor->setMode(GL_CULL_FACE,osg::StateAttribute::ON);

    osg::StateSet* roof = new osg::StateSet;
    roof->setMode(GL_CULL_FACE,osg::StateAttribute::ON);

    osg::Geode* geode = new osg::Geode;

    // create front side.
    geode->addDrawable(createWall(bb.corner(0),
                                  bb.corner(4),
                                  bb.corner(1),
                                  wall));

    // right side
    geode->addDrawable(createWall(bb.corner(1),
                                  bb.corner(5),
                                  bb.corner(3),
                                  wall));

    // left side
    geode->addDrawable(createWall(bb.corner(2),
                                  bb.corner(6),
                                  bb.corner(0),
                                  wall));
    // back side
    geode->addDrawable(createWall(bb.corner(3),
                                  bb.corner(7),
                                  bb.corner(2),
                                  wall));

    // floor
    geode->addDrawable(createWall(bb.corner(0),
                                  bb.corner(1),
                                  bb.corner(2),
                                  floor));

    // roof
    geode->addDrawable(createWall(bb.corner(6),
                                  bb.corner(7),
                                  bb.corner(4),
                                  roof));

    root->addChild(geode);

    root->addChild(createLights(bb,rootStateSet));

    return root;

}
Example #7
0
File: IHM.cpp Project: GP-S/HOTS
IHM::PolycodeGUI::IHM::IHM ( PolycodeView* view, string serverAddress, int serverPort ) {

    core = new POLYCODE_CORE ( view, 1280,720,false,true,0,0,60, 0, true );
    
    CoreServices::getInstance()->getRenderer()->enableScissor(true);
    CoreServices::getInstance()->getRenderer()->setScissorBox(Polycode::Rectangle(0, 0, 1280, 720));

    CoreServices::getInstance()->getResourceManager()->addArchive ( "Resources/default.pak" );
    CoreServices::getInstance()->getResourceManager()->addDirResource ( "default", false );
    CoreServices::getInstance()->getResourceManager()->addDirResource ( "Resources", false );
    
    CoreServices::getInstance()->getResourceManager()->addArchive ( "UIThemes.pak" );
    CoreServices::getInstance()->getConfig()->loadConfig("Polycode", "UIThemes/dark_retina/theme.xml");
    CoreServices::getInstance()->getResourceManager()->addDirResource("UIThemes/dark_retina/");
    
    scene = new CollisionScene();
    scene->doVisibilityChecking ( true );
    
    Scene *screen = new Scene(Scene::SCENE_2D_TOPLEFT);
       
    button = new UIButton("End of Turn",100,26);
    button->setScale(2,2);
    screen->addChild(button);
    button->setPosition(core->getXRes()-2*button->getWidth()-20,core->getYRes()/2-2*button->getHeight()/2);
    screen->rootEntity.processInputEvents = true;
    
    p1Shards = new SceneLabel("0/0", 17,"Script",Label::ANTIALIAS_FULL,16);
    p1Shards->setColorInt(255,255,255,255);
    p1Shards->setPosition(10,10);
    screen->addChild(p1Shards);
    
    p0Shards = new SceneLabel("0/0", 17,"Script",Label::ANTIALIAS_FULL,16);
    p0Shards->setColorInt(255,255,255,255);
    p0Shards->setPosition(core->getXRes()-2*p0Shards->getWidth()-10,core->getYRes()-2*p0Shards->getHeight()-10);
    screen->addChild(p0Shards);

    ground = new ScenePrimitive ( ScenePrimitive::TYPE_PLANE, 192,108 );
    ground->setMaterialByName ( "GroundMaterial" );
    scene->addEntity ( ground );

    initBoard();

    /*
    for ( int i =0; i<10; i++ ) {
        Card *card = new Card();
        scene->addCollisionChild ( card );
        p0Stock->addCard ( card,Vector3 ( 0,0,0 ) );
        card->setTitle ( "Card "+std::to_string ( i ) );
    }

    for ( int i =10; i<15; i++ ) {
        Card *card = new Card();
        scene->addCollisionChild ( card );
        p0Hand->addCard ( card,Vector3 ( 0,0,0 ) );
        card->setTitle ( "Card "+std::to_string ( i ) );
    }
    */



    createLights();


    scene->getDefaultCamera()->setPosition ( 0,130,1 );
    scene->getDefaultCamera()->lookAt ( Vector3 ( 0,0,0 ) );

    button->addEventListener(this, UIEvent::CLICK_EVENT);
    core->getInput()->addEventListener ( this, InputEvent::EVENT_MOUSEMOVE );
    core->getInput()->addEventListener ( this, InputEvent::EVENT_MOUSEDOWN );
    
    client = new Network::GameClient(serverAddress,serverPort,this);

}
Example #8
0
void OgreSample14App::createScene()
{
	Entity* head = mSceneMgr->createEntity("Head", "ogrehead.mesh");
	mSceneMgr->getRootSceneNode()->attachObject(head);
	createLights();
}
Example #9
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()->setApplicationName(arguments.getApplicationName());
    arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" example demonstrates the use of ImageStream for rendering movies as textures.");
    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
    arguments.getApplicationUsage()->addCommandLineOption("--texture2D","Use Texture2D rather than TextureRectangle.");
    arguments.getApplicationUsage()->addCommandLineOption("--shader","Use shaders to post process the video.");
    arguments.getApplicationUsage()->addCommandLineOption("--interactive","Use camera manipulator to allow movement around movie.");
    arguments.getApplicationUsage()->addCommandLineOption("--flip","Flip the movie so top becomes bottom.");


    // construct the viewer.
    osgViewer::Viewer viewer(arguments);

    if (arguments.argc()<1)
    {
        arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
        return 1;
    }

    osg::ref_ptr<osg::Group> root = new osg::Group;



    /*    osg::Light* light = new osg::Light();
    light->setPosition(osg::Vec4d(-500.0, 1000.0, 500.0, 1.0));
    light->setDirection(osg::Vec3d(5.0, -10.0, -5.0));
    light->setSpotCutoff(70);
    light->setAmbient(osg::Vec4d(0.05, 0.05, 0.05, 1.0));
    light->setDiffuse(osg::Vec4d(0.5, 0.5, 0.5, 1.0));
    //light->setQuadraticAttenuation(0.001);

    osg::LightSource* lightSource = new osg::LightSource();
    lightSource->setLight(light);

    //osg::Light * attachedlight = lightSource->getLight();

    //attache light to root group
    root->addChild(lightSource);

	//activate light
	osg::StateSet* stateSet = root->getOrCreateStateSet();
    lightSource->setStateSetModes(*stateSet, osg::StateAttribute::ON);

    osg::StateSet* stateset = root->getOrCreateStateSet();
    stateset->setMode(GL_LIGHTING,osg::StateAttribute::ON);
*/
    osg::ref_ptr<osg::Geode> geode = new osg::Geode;



    //OpenCV-AR
    CvCapture* cameraCapture;
    CvCapture* fileCapture;
    //cameraCapture = cvCreateCameraCapture(0);

    fileCapture = cvCreateFileCapture("video/whal.avi");
    cameraCapture = fileCapture;

    if(!cameraCapture) {
		fprintf(stderr,"OpenCV: Create camera capture failed\n");
		return 1;
	}

    //printf("%f\n", cvGetCaptureProperty(cameraCapture, CV_CAP_PROP_FPS));

    //cvSetCaptureProperty(cameraCapture, CV_CAP_PROP_FRAME_WIDTH, 1280);
    //cvSetCaptureProperty(cameraCapture, CV_CAP_PROP_FRAME_HEIGHT, 960);
    //cvSetCaptureProperty(cameraCapture, CV_CAP_PROP_FPS, 15);

	IplImage* frame = cvQueryFrame(cameraCapture);
	IplImage* flipFrame = cvCreateImage(cvGetSize(frame), frame->depth, frame->nChannels);



    //osg::Image* image = osgDB::readImageFile("aclib-large.png");
    osg::Image* image = new osg::Image();
    //image->setPixelBufferObject( new osg::PixelBufferObject(image));

    image->setDataVariance( osg::Object::DYNAMIC );
    iplImageToOsgImage(flipFrame, image);

    //load model
    osg::ref_ptr<osg::PositionAttitudeTransform> modelPat = new osg::PositionAttitudeTransform();

    //osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile("models/Cars/AstonMartin-DB9.3ds");
    osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile("models/ferrari_car_2.osg");
    modelPat->addChild(loadedModel);
    modelPat->setScale(osg::Vec3(0.5, 0.5, 0.5));
    modelPat->setAttitude(osg::Quat(3.14 / 2, osg::Vec3d(-1.0, 0.0, 0.0)));

    if (!loadedModel) {
    	std::cout << "No model data loaded" << std::endl;
    	return 1;
    }



    //C_BODY

    std::vector<osg::MatrixTransform*> topMtList = getMatrixTransformListByName("C_TOP", loadedModel);
    std::vector<osg::MatrixTransform*> leftDoorMtList = getMatrixTransformListByName("C_LDOOR", loadedModel);
    std::vector<osg::MatrixTransform*> rightDoorMtList = getMatrixTransformListByName("C_RDOOR", loadedModel);
    std::vector<osg::MatrixTransform*> leftWheelsMtList = getMatrixTransformListByName("C_LWS", loadedModel);
    std::vector<osg::MatrixTransform*> rightWheelsMtList = getMatrixTransformListByName("C_RWS", loadedModel);
    std::vector<osg::MatrixTransform*> forwardBumperMtList = getMatrixTransformListByName("C_BUMP_F", loadedModel);
    std::vector<osg::MatrixTransform*> backBumperMtList = getMatrixTransformListByName("C_BUMP_B", loadedModel);
    std::vector<osg::MatrixTransform*> engineMtList = getMatrixTransformListByName("C_ENGINE", loadedModel);
    std::vector<osg::MatrixTransform*> bodyMtList = getMatrixTransformListByName("C_BODY", loadedModel);
    std::vector<osg::MatrixTransform*> salonMtList = getMatrixTransformListByName("C_SALON", loadedModel);

    /*    //findNodeVisitor findNode("C_BODY");
    FindNamedNode findNode("C_BODY");
    loadedModel->accept(findNode);

    std::vector<osg::Node*> foundNodeList = findNode.getNodeList();
    int listCount = foundNodeList.size();
    printf("%d\n", listCount);
    std::vector<osg::MatrixTransform*> bodyMtList;

    //vector<int>::const_iterator i;
    for(int i = 0; i < listCount; i++) {
        bodyMtList.push_back(new osg::MatrixTransform());
        //obj4Mt->setName("obj4Mt");

        osg::Group* foundNodeParent = foundNodeList[i]->getParent(0);

        bodyMtList[i]->addChild(foundNodeList[i]);

        foundNodeParent->addChild(bodyMtList[i]);

        foundNodeParent->removeChild(foundNodeList[i]);
    }
*/
    osg::Matrix translateMatrix;


    //osg::Node* foundNode = NULL;
    //foundNode = findNamedNode("obj5", loadedModel);

    //osg::ref_ptr<osg::MatrixTransform> obj5Mt = new osg::MatrixTransform();
    //obj4Mt->setName("obj5Mt");

    //osg::Group* foundNodeParent = foundNode->getParent(0);

    //obj5Mt->addChild(foundNode);

    //foundNodeParent->addChild(obj5Mt);

    //foundNodeParent->removeChild(foundNode);


    osg::Matrix rotateMatrix;
    float theta(M_PI * 0.1f);
    osg::Vec3f axis (1.0, 1.0, 0.1);
    osg::Quat wheelAxis( theta, axis);



    osg::BoundingSphere modelBoundingSphere = modelPat->getBound();
    printf("%f\n", modelBoundingSphere.radius());
    modelBoundingSphere.radius() *= 1.5f;

    osg::BoundingBox modelBoundingBox;
    modelBoundingBox.expandBy(modelBoundingSphere);



    //Light group

    //create light
    root->addChild(createLights(modelBoundingBox, root->getOrCreateStateSet()));


    //collect scene

    // only clear the depth buffer
    viewer.getCamera()->setClearMask(GL_DEPTH_BUFFER_BIT);

    // create a HUD as slave camera attached to the master view.

    viewer.setUpViewAcrossAllScreens();

    osgViewer::Viewer::Windows windows;
    viewer.getWindows(windows);

    if (windows.empty()) return 1;

    osg::Camera* screenCamera = createScreen(image);

    // set up cameras to rendering on the first window available.
    screenCamera->setGraphicsContext(windows[0]);
    screenCamera->setViewport(0,0,windows[0]->getTraits()->width, windows[0]->getTraits()->height);
    //screenCamera->setViewport(0, 0, 6.4, 4.8);


    viewer.addSlave(screenCamera, false);


    //root->addChild( geode.get());
    //root->addChild( createPyramid());
    //root->addChild( createScreen());//100.0, 100.0, image));
    root->addChild(modelPat);
    //root->addChild(objectPat);

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



        viewer.realize();
        
        viewer.getCamera()->setClearColor(osg::Vec4(0.0f,0.0f,0.0f,1.0f));
/*
        //viewer.getCamera()->setProjameraCaptureectionMatrixAsOrtho(topleft.x(),bottomright.x(),topleft.y(),bottomright.y(), -10, 10);
        //viewer.getCamera()->setProjectionMatrixAsPerspective(60.0, screenAspectRatio, 100.0, -1.0);
*/
        viewer.getCamera()->setViewMatrixAsLookAt(osg::Vec3d(100.0, 100.0, 100.0), osg::Vec3d(0.0, 0.0, 0.0), osg::Vec3d(0.0, 1.0, 0.0));






        //Define vector of OpenCV-AR template
        vector<CvarTemplate> openCvArTemplateList;


        //load template
        CvarTemplate openCvArTemplate1;
        cvarLoadTemplateTag(&openCvArTemplate1,"aclib.png");
        //cvarLoadTemplateTag(&openCvArTemplate1,"markers/431.jpg");
        openCvArTemplateList.push_back(openCvArTemplate1);

        CvarTemplate openCvArTemplate2;
        cvarLoadTemplate(&openCvArTemplate2,"aclib.png",1);
        //cvarLoadTemplate(&openCvArTemplate2,"markers/431.jpg", 1);
        openCvArTemplateList.push_back(openCvArTemplate2);

        //Define OpenCV-AR marker;
        vector<CvarMarker> openCvArMarker;

        //Create OpenCV-AR camera
        CvarCamera openCvArCamera;
        //IplImage* frame = osgImage2IplImage(image);

        //cvarReadCamera("camera.yml", &openCvArCamera);
        cvarReadCamera(NULL, &openCvArCamera);
        cvarCameraScale(&openCvArCamera,frame->width,frame->height);
        viewer.getCamera()->setProjectionMatrix(osg::Matrixd(openCvArCamera.projection));


        //CvarOpticalFlow *flow;

       // srand(time(NULL));

        //int thresh = 60;
        double matchThresh = 0.7;
        //int state = 0;


        int counter = 0;
        while(!viewer.done())
        {
        	counter++;

        	char c = 0;//cvWaitKey(33);
        	//printf("%d\n", c);
        	if (c == 27) { // нажата ESC
        		printf("esc\n");
        		break;
        	}
        	if (c == 107) { // matchThresh up
        	  	matchThresh = matchThresh + 0.01;
        	}
        	if (c == 106) { // matchThresh down
        		matchThresh = matchThresh - 0.01;
        	}


        	if ((counter >= 300) and (counter < 310)) { // matchThresh down
        		//Top
        		translateMatrixTransformList(topMtList, 0.0, -1.2, 0.0);

        		//Engine
        		translateMatrixTransformList(engineMtList, 0.0, -1.0, 0.0);

        		//Body
        		translateMatrixTransformList(bodyMtList, 0.0, -0.8, 0.0);

        		//Salon
        		translateMatrixTransformList(salonMtList, 0.0, -0.4, 0.0);


        		//leftWeels
        		translateMatrixTransformList(leftWheelsMtList, -0.5, 0.0, 0.0);

        		//rightWeels
        		translateMatrixTransformList(rightWheelsMtList, 0.5, 0.0, 0.0);

        		//Left doors
        		translateMatrixTransformList(leftDoorMtList, -0.5, 0.0, 0.0);

        		//Right doors
           		translateMatrixTransformList(rightDoorMtList, 0.5, 0.0, 0.0);


           		//Forward bumper
        		translateMatrixTransformList(forwardBumperMtList, 0.0, 0.0, 0.5);

        		//back bumper
        		translateMatrixTransformList(backBumperMtList, 0.0, 0.0, -0.5);


        	}


        	//rotateMatrix.makeRotate(rotateMatrix.getRotate() * wheelAxis);
        	//obj5Mt->setMatrix(rotateMatrix);

        	//thresh = rand() % 256;
        	//printf("Match thresh value: %f\n", matchThresh);
        	frame = cvQueryFrame(cameraCapture);

        	cvCopy(frame, flipFrame);

        	cvFlip(flipFrame, flipFrame);
        	//cvNamedWindow("Original", 1);
        	//cvShowImage("Original", frame);
        	iplImageToOsgImage(frame, image);

        	image->dirty();

        	//osg::Image* = osg::Image(*image);


        	//frame = osgImage2IplImage(image);
        	//AR detection
        	//GLdouble modelview[16] = {0};

        	//Detect marker
        	int arDetect = cvarArMultRegistration(flipFrame,&openCvArMarker,openCvArTemplateList,&openCvArCamera, 60, 0.91);
			//printf("Marker found: %d\n",  arDetect);

			viewer.getCamera()->setViewMatrixAsLookAt(osg::Vec3d(0.0, 0.0, 100.0), osg::Vec3d(0.0, 0.0, 1000.0), osg::Vec3d(0.0, 1.0, 0.0));

			for(int i=0;i<arDetect;i++) {
				//if(openCvArMarker[i].tpl == 0);
				osg::Matrixf osgModelViewMatrix;
				for (int column = 0; column < 4; column++)	{
					for (int row = 0; row < 4; row++)	{
						osgModelViewMatrix(column, row) = openCvArMarker[i].modelview[column * 4 + row];
					}
				}

				viewer.getCamera()->setViewMatrix(osgModelViewMatrix);
			}

			viewer.frame();
        }
        return 0;

}