コード例 #1
0
ファイル: World.cpp プロジェクト: Prnbs/ShadowVolOGL
void World::CreateBodies()
{ 
	Grid* grid = new Grid();
	Cube* cube = new Cube();

	cube->Create();
	grid->Create();
	
	world.push_back(cube);
	world.push_back(grid);
	
}
コード例 #2
0
ファイル: world.cpp プロジェクト: roughl/gl_terrain
void World::Update (SDL_KeyboardEvent *keyevent)
{
    switch(keyevent->keysym.sym)
    {
    case SDLK_KP_PLUS:
	case SDLK_PLUS:
        if(keyevent->type==SDL_KEYUP)
        {
            float x, y, z, size;
            x=( (float)rand()/RAND_MAX )* terrain[0]->GetWidth();
            z=( (float)rand()/RAND_MAX )* terrain[0]->GetHeight();
            size=(float)rand()/(RAND_MAX/1.0)+1.0; // between 1.0 and 2.0
            y=terrain[0]->GetMapY(x, z)+size*1.8f;

            cout << "creating cube at " << x << " / " << y << " / ";
            cout << z << " with size " << size << endl;

			Cube *cub = new Cube();
			cub->Create(x,y,z,size);
            
            objects.push_back( cub );
            /*
            objects.push_back( new Sphere(this) );
            spheres.back()->Create(x,y,z,size);*/
        }
        break;
    case SDLK_KP_MINUS: 
	case SDLK_MINUS:
        if(keyevent->type==SDL_KEYUP)
        {
            if(objects.size())
            {
                delete objects.back();
                objects.pop_back();
            }
        }
        break;
    case 'p':
        if(keyevent->type==SDL_KEYDOWN)
            {
                printf("current State:\n");
                printf("pos.x= %f\tpos.y= %f\tpos.z= %f\n", pos.x, pos.y, pos.z);     
                cout << "angle.y: " << angle.y << " -> ";
                if(drawtop) cout << "drawtop ";
                if(drawbuttom) cout << "drawbuttom ";
                if(drawright) cout << "drawright ";
                if(drawleft) cout << "drawleft ";
                cout << endl;
            }
        break;
        
    case SDLK_SPACE:
        if(keyevent->type==SDL_KEYDOWN)
        {
        //    if(yspeed==0)
             //   yspeed+=jumpvelocity;
        }
        else
        {
        }
        break;
	default:
		break;
    }
}
コード例 #3
0
ファイル: world.cpp プロジェクト: roughl/gl_terrain
void World::Draw(void)
{
    //std::cout << "Drawing Terrain at " << posx << " / " << posy << " / " << posz << " / ";

	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		// Clear Screen And Depth Buffer
	glLoadIdentity ();											// Reset The Modelview Matrix
	
	// --- Go to Cam Pos ---
	glRotatef (angle.x, 1.0f, 0.0f, 0.0f);						// Rotate On The X-Axis By angle
	glRotatef (angle.y, 0.0f, 1.0f, 0.0f);						// Rotate On The Y-Axis By angle
	glRotatef (angle.z, 0.0f, 0.0f, 1.0f);						// Rotate On The Z-Axis By angle
	glTranslatef (-this->pos.x, -this->pos.y, -this->pos.z);	// Translate to Cam Pos
	
	static const float max = 100.0f;
	static const float min = 100.0f;
    static Cube mycube;
	static float speed =  0.10f;
    static float pos[4] = {(float)terrain[0]->GetWidth()*2, max, (float)terrain[0]->GetHeight()*2, 1.0f};
	static float amb[4] = {0.01f, 0.01f, 0.01f, 1.0f};
	static float dif[4] = {0.5f, 0.5f, 0.5f, 1.0f};
	static float spec[4]= {1.0f, 1.0f, 1.0f, 1.0f};
    GL_SetLight(pos, amb, dif, spec);
    mycube.Create(pos[0],pos[1],pos[2],1.0f);
	pos[1]+=speed;
	if(pos[1] >= max){
		speed = -speed;
		pos[1]=max;
	}
	else if(pos[1] <= min){
		speed = -speed;
		pos[1]=min;
	}
	mycube.Draw();


    DrawChildren();
    
    if(drawright)
    {
        glPushMatrix();
        glTranslatef(terrain[0]->GetWidth(), 0.0f, 0.0f);
        DrawChildren();
        glPopMatrix();
    }
    if(drawleft)
    {
        glPushMatrix();
        glTranslatef(-(terrain[0]->GetWidth()), 0.0f, 0.0f);
        DrawChildren();
        glPopMatrix();
    }
    
    if(drawtop)
    {
        glPushMatrix();
        glTranslatef(0.0f, 0.0f, -terrain[0]->GetHeight());
        DrawChildren();
        if(drawright)
        {
            glTranslatef(terrain[0]->GetWidth(), 0.0f, 0.0f);
            DrawChildren();
            glTranslatef(-terrain[0]->GetWidth(), 0.0f, 0.0f);
        }
        if(drawleft)
        {
            glTranslatef(-(terrain[0]->GetWidth()), 0.0f, 0.0f);
            DrawChildren();
        }
        glPopMatrix();
    }
    if(drawbuttom)
    {
        glPushMatrix();
        glTranslatef(0.0f, 0.0f, terrain[0]->GetHeight());
        DrawChildren();
        if(drawright)
        {
            glTranslatef(terrain[0]->GetWidth(), 0.0f, 0.0f);
            DrawChildren();
            glTranslatef(-terrain[0]->GetWidth(), 0.0f, 0.0f);
        }
        if(drawleft)
        {
            glTranslatef(-(terrain[0]->GetWidth()), 0.0f, 0.0f);
            DrawChildren();
        }
        glPopMatrix();
    }/**/


	glFlush ();													// Flush The GL Rendering Pipeline
}