示例#1
0
int main( void )
{
  glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE );
  glutInitWindowSize( 800, 600 );
  glutCreateWindow( "PhyEngine" );
  glutDisplayFunc( PhysicsLoop );
  glutKeyboardFunc( Keyboard );
  glutMouseFunc( Mouse );
  glutIdleFunc( PhysicsLoop );

  glMatrixMode( GL_PROJECTION );
  glPushMatrix( );
  glLoadIdentity( );
  gluOrtho2D( 0, 80, 60, 0 );
  glMatrixMode( GL_MODELVIEW );
  glPushMatrix( );
  glLoadIdentity( );

  Circle c( 5.0f );
  Body *b = scene.Add( &c, 40, 40 );
  b->SetStatic( );

  PolygonShape poly;
  poly.SetBox( 30.0f, 1.0f );
  b = scene.Add( &poly, 40, 55 );
  b->SetStatic( );
  b->SetOrient( 0 );

  srand( 1 );

  glutMainLoop( );

  return 0;
}
示例#2
0
void Mouse( int button, int state, int x, int y )
{
  x /= 10.0f;
  y /= 10.0f;

  if(state == GLUT_DOWN)
    switch(button)
    {
    case GLUT_LEFT_BUTTON:
      {
        PolygonShape poly;
        uint32 count = (uint32)Random( 3, MaxPolyVertexCount );
        Vec2 *vertices = new Vec2[count];
        real e = Random( 5, 10 );
        for(uint32 i = 0; i < count; ++i)
          vertices[i].Set( Random( -e, e ), Random( -e, e ) );
        poly.Set( vertices, count );
        Body *b = scene.Add( &poly, x, y );
        b->SetOrient( Random( -PI, PI ) );
        b->restitution = 0.2f;
        b->dynamicFriction = 0.2f;
        b->staticFriction = 0.4f;
        delete [] vertices;
      }
      break;
    case GLUT_RIGHT_BUTTON:
      {
        Circle c( Random( 1.0f, 3.0f ) );
        Body *b = scene.Add( &c, x, y );
      }
      break;
    }
}
示例#3
0
// --------------------------------------------
void main()
{
    Scene scene = Scene();
    // 增加
    scene.Add("a", 1, 5);
    scene.Add("f", 6, 6);
    scene.Add("c", 3, 1);
    scene.Add("b", 2, 2);
    scene.Add("e", 5, 3);
    DoubleNode * node = scene.Add("d", 3, 3);

    scene.PrintLink();
    scene.PrintAOI(node, 2, 2);
    
    // 移动
    cout << endl << "[MOVE]" << endl;
    scene.Move(node, 4, 4);
    scene.PrintLink();
    scene.PrintAOI(node, 2, 2);

    // 删除
    cout << endl << "[LEAVE]" << endl;
    scene.Leave(node);
    scene.PrintLink();
}
示例#4
0
int main()
{
    CheezyWin win;
    win.Init(640, 640);

    Camera cam = Camera();
    Scene *scene = win.CreateScene("FirstScene");

    GameObject *go = new GameObject("go");
    /*GameObject *light = new GameObject("lus");
    light->RemoveComponent("Mesh");
    light->AddComponent(new Light());
    light->GetTransform()->pos = vec3(100.0, 100.0, 100.0);*/

    scene->Add(go);
    //scene->Add(light);

    scene->SetCurrentCamera(cam);

    go->GetTransform()->scale = vec3(0.05);
    vec3 camPos = vec3(5, 5, 10), camUp = vec3(0, 1, 0);
    scene->cam->LookAt(camPos, vec3(0, 0, 0), camUp);

    win.Loop();
    win.Destroy();

    return 0;
}
示例#5
0
文件: main.cpp 项目: dcoded/cg-final
void keyboard( unsigned char key, int x, int y ) {

    switch( key ) {

	// automated animation
        case 'a': animate(); break;

	// incremental rotation along the axes
        case 'x': angles[0] -= angleInc; break;
        case 'y': angles[1] -= angleInc; break;
        case 'z': angles[2] -= angleInc; break;
        case 'X': angles[0] += angleInc; break;
        case 'Y': angles[1] += angleInc; break;
        case 'Z': angles[2] += angleInc; break;

    // add/remove
        case '1': scene.Add(&r1); break;
        case '2': scene.Add(&r2); break;
        case '3': scene.Del(&r1); break;
        case '4': scene.Del(&r2); break;

	// termination
        case 033:  // Escape key
        case 'q': case 'Q':
            exit( 0 );
    }

    glutPostRedisplay();
}
示例#6
0
void GuardianSystemDemo::InitSceneGraph()
{
    for (int32_t i = 0; i < Scene::MAX_MODELS; ++i) {
        TriangleSet mesh;
        mesh.AddSolidColorBox(-0.035f, -0.035f, -0.035f, 0.035f, 0.035f, 0.035f, 0xFFFFFFFF);

        // Objects start 1 meter high
        mObjPosition[i] = XMVectorSet(0.0f, 1.0f, 0.0f, 1.0f);
        // Objects have random velocity
        mObjVelocity[i] = XMVectorSet(randVelocity(), randVelocity() * 0.5f, randVelocity(), 0);
        mObjVelocity[i] = XMVector3Normalize(mObjVelocity[i]) * 0.3f;

        Material* mat = new Material(new Texture(false, 256, 256, Texture::AUTO_FLOOR));
        mDynamicScene.Add(new Model(&mesh, XMFLOAT3(0, 0, 0), XMFLOAT4(0, 0, 0, 1), mat));
    }
}
示例#7
0
int main()
{
	WindowController* windowController = &WindowController::GetInstance();
	if (windowController == nullptr)
		return Terminate("Failed to create window...");
	windowController->setHeight(800);
	windowController->setWidth(1200);

	GlewInit();

	Scene scene;

	Skybox* skybox = new Skybox("skybox", "./Resources/Textures/TropicalSunnyDay", ".png");
	scene.Add(skybox);

	string plane_path = "./Resources/Models/Boeing 747/Boeing747.obj";
	Shader* shader = new Shader("./model.vs", "./model.frag");
	//Model* plane_model = new Model(plane_path);
	//GameObject* plane = new GameObject("Boeing 747", plane_model, shader);
	//plane->Transform(glm::vec3(2.0f, 0.0f, 0.0f));
	//plane->Scale(glm::vec3(2.0f, 2.0f, 2.0f));
	//scene.Add(plane);


	Plane* plane = new Plane("grass.png", "./Resources/Textures", shader, 1000);
	scene.Add(plane);

	windowController->Update(scene);

	//glEnable(GL_DEPTH_TEST);

	//if (GlewInit() != 0)
	//	return Terminate("Failed to init glew");

	//Model nanosuit("./Resources/Models/nanosuit/nanosuit.obj");
	//Shader modelShader("./model.vs", "./model.frag");

	//while (!glfwWindowShouldClose(window))
	//{
	//	// Set frame time
	//	GLfloat currentFrame = glfwGetTime();
	//	deltaTime = currentFrame - lastFrame;
	//	lastFrame = currentFrame;

	//	// Check and call events
	//	glfwPollEvents();
	//	Do_Movement();

	//	// Clear the colorbuffer
	//	glClearColor(0.15f, 0.15f, 0.15f, 1.0f);
	//	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	//	modelShader.Use();   // <-- Don't forget this one!
	//					// Transformation matrices
	//	glm::mat4 projection = glm::perspective(camera.Zoom, (float)WIDTH / (float)HEIGHT, 0.1f, 100.0f);
	//	glm::mat4 view = camera.GetViewMatrix();
	//	glUniformMatrix4fv(glGetUniformLocation(modelShader.Program, "projection"), 1, GL_FALSE, glm::value_ptr(projection));
	//	glUniformMatrix4fv(glGetUniformLocation(modelShader.Program, "view"), 1, GL_FALSE, glm::value_ptr(view));

	//	// Draw the loaded model
	//	glm::mat4 model;
	//	model = glm::translate(model, glm::vec3(0.0f, -1.75f, 0.0f)); // Translate it down a bit so it's at the center of the scene
	//	model = glm::scale(model, glm::vec3(0.2f, 0.2f, 0.2f));	// It's a bit too big for our scene, so scale it down
	//	glUniformMatrix4fv(glGetUniformLocation(modelShader.Program, "model"), 1, GL_FALSE, glm::value_ptr(model));
	//	nanosuit.Draw(modelShader);

	//	// Swap the buffers
	//	glfwSwapBuffers(window);
	//}
	glfwTerminate();
	system("pause");
	return 0;
}
示例#8
0
int main()
{
    const int width = 640;
    const int height = 480;
    
    System::EnableWindowsMemleakDetection();
    Window::Create( width, height, WindowCreateFlags::Empty );
    System::LoadBuiltinAssets();
    System::InitAudio();
    System::InitGamePad();

    GameObject camera;
    camera.AddComponent<CameraComponent>();
    camera.GetComponent<CameraComponent>()->SetProjection( 0, (float)width, (float)height, 0, 0, 1 );
    camera.GetComponent<CameraComponent>()->SetClearColor( Vec3( 0.5f, 0.5f, 0.5f ) );

    Texture2D spriteTex;
    spriteTex.Load( FileSystem::FileContents("glider.png"), TextureWrap::Repeat, TextureFilter::Nearest, Mipmaps::None, 1 );

    Texture2D spriteTex2;
    spriteTex2.Load( FileSystem::FileContents("test_dxt1.dds"), TextureWrap::Repeat, TextureFilter::Nearest, Mipmaps::None, 1 );

    Texture2D spriteTexFromAtlas;
    spriteTexFromAtlas.LoadFromAtlas( FileSystem::FileContents("atlas_cegui.png"), FileSystem::FileContents("atlas_cegui.xml"), "granite", TextureWrap::Repeat, TextureFilter::Nearest, 1 );

    GameObject spriteContainer;
    spriteContainer.AddComponent<SpriteRendererComponent>();
    auto sprite = spriteContainer.GetComponent<SpriteRendererComponent>();
    sprite->SetTexture( &spriteTex, Vec3( 320, 0, -0.6f ), Vec3( (float)spriteTex.GetWidth(), (float)spriteTex.GetHeight(), 1 ), Vec4( 1, 0.5f, 0.5f, 1 ) );
    sprite->SetTexture( &spriteTex, Vec3( 340, 80, -0.5f ), Vec3( (float)spriteTex.GetWidth()/2, (float)spriteTex.GetHeight()/2, 1 ), Vec4( 0.5f, 1, 0.5f, 1 ) );
    sprite->SetTexture( &spriteTex2, Vec3( 280, 60, -0.4f ), Vec3( (float)spriteTex.GetWidth(), (float)spriteTex.GetHeight(), 1 ), Vec4( 1, 1, 1, 0.5f ) );
    sprite->SetTexture( &spriteTexFromAtlas, Vec3( 260, 160, -0.4f ), Vec3( (float)spriteTexFromAtlas.GetWidth(), (float)spriteTexFromAtlas.GetHeight(), 1 ), Vec4( 1, 1, 1, 1 ) );

    spriteContainer.AddComponent<TransformComponent>();
    spriteContainer.GetComponent<TransformComponent>()->SetLocalPosition( Vec3( 20, 0, 0 ) );

    AudioClip audioClip;
    audioClip.Load(FileSystem::FileContents("explosion.wav"));
    
    GameObject audioContainer;
    audioContainer.AddComponent<AudioSourceComponent>();
    audioContainer.GetComponent<AudioSourceComponent>()->SetClipId( audioClip.GetId() );
    audioContainer.GetComponent<AudioSourceComponent>()->Play();
    
    Texture2D fontTex;
    fontTex.Load( FileSystem::FileContents("font.png"), TextureWrap::Clamp, TextureFilter::Linear, Mipmaps::None, 1 );

    Font font;
    font.LoadBMFont(&fontTex, FileSystem::FileContents("font_txt.fnt"));

    //Texture2D fontTexSDF;
    //fontTexSDF.Load( FileSystem::FileContents( "font_sdf.png" ), TextureWrap::Clamp, TextureFilter::Linear, Mipmaps::None );

    //Font sdfFont;
    //sdfFont.LoadBMFont( &fontTexSDF, FileSystem::FileContents( "font_sdf.txt" ) );

    GameObject textContainer;
    textContainer.AddComponent<TextRendererComponent>();
    textContainer.GetComponent<TextRendererComponent>()->SetText( "Aether3D \nGame Engine" );
    textContainer.GetComponent<TextRendererComponent>()->SetFont( &font );
    textContainer.GetComponent<TextRendererComponent>()->SetShader( TextRendererComponent::ShaderType::Sprite );
    textContainer.AddComponent<TransformComponent>();
    textContainer.GetComponent<TransformComponent>()->SetLocalPosition( Vec3( 20, 160, 0 ) );
    //textContainer.GetComponent<TransformComponent>()->SetLocalScale( 2 );
    textContainer.GetComponent<TransformComponent>()->SetLocalRotation( Quaternion::FromEuler( Vec3( 0, 0, 45 ) ) );

    GameObject statsParent;
    statsParent.AddComponent<TransformComponent>();
    statsParent.GetComponent<TransformComponent>()->SetLocalPosition( Vec3( 0, -80, 0 ) );
    
    GameObject statsContainer;
    statsContainer.AddComponent<TextRendererComponent>();
    statsContainer.GetComponent<TextRendererComponent>()->SetText( "Aether3D \nGame Engine" );
    statsContainer.GetComponent<TextRendererComponent>()->SetFont( &font );
    statsContainer.AddComponent<TransformComponent>();
    statsContainer.GetComponent<TransformComponent>()->SetLocalPosition( Vec3( 20, 80, 0 ) );
    statsContainer.GetComponent<TransformComponent>()->SetParent( statsParent.GetComponent<TransformComponent>() );

    RenderTexture2D rtTex;
    rtTex.Create( 512, 512, TextureWrap::Clamp, TextureFilter::Linear );
    
    GameObject renderTextureContainer;
    renderTextureContainer.AddComponent<SpriteRendererComponent>();
    spriteContainer.GetComponent<SpriteRendererComponent>()->SetTexture( &rtTex, Vec3( 150, 250, -0.6f ), Vec3( (float)spriteTex.GetWidth(), (float)spriteTex.GetHeight(), 1 ), Vec4( 1, 1, 1, 1 ) );

    GameObject rtCamera;
    rtCamera.AddComponent<CameraComponent>();
    rtCamera.GetComponent<CameraComponent>()->SetProjection( 0, (float)rtTex.GetWidth(), 0,(float)rtTex.GetHeight(), 0, 1 );
    rtCamera.GetComponent<CameraComponent>()->SetClearColor( Vec3( 0.5f, 0.5f, 0.5f ) );
    rtCamera.GetComponent<CameraComponent>()->SetTargetTexture( &rtTex );
    
    Scene scene;
    scene.Add( &camera );
    scene.Add( &spriteContainer );
    scene.Add( &textContainer );
    scene.Add( &statsContainer );
    scene.Add( &statsParent );
    scene.Add( &renderTextureContainer );
    scene.Add( &rtCamera );
    //System::Print( "%s\n", scene.GetSerialized().c_str() );

    bool quit = false;
    
    while (Window::IsOpen() && !quit)
    {
        Window::PumpEvents();
        WindowEvent event;

        std::string text( "draw calls:" );
        
        while (Window::PollEvent( event ))
        {
            if (event.type == WindowEventType::Close)
            {
                quit = true;
            }
            
            if (event.type == WindowEventType::KeyDown ||
                event.type == WindowEventType::KeyUp)
            {
                KeyCode keyCode = event.keyCode;
                
                if (keyCode == KeyCode::Escape)
                {
                    quit = true;
                }
                else if (keyCode == KeyCode::R)
                {
                    System::ReloadChangedAssets();
                }
                else if (keyCode == KeyCode::B && event.type == WindowEventType::KeyUp)
                {
                    audioContainer.GetComponent<AudioSourceComponent>()->Play();
                }
            }
            if (event.type == WindowEventType::GamePadButtonA)
            {
                text = "button a down";
            }
        }

        const std::string drawCalls = text + std::to_string( System::Statistics::GetDrawCallCount() );
        statsContainer.GetComponent<TextRendererComponent>()->SetText( drawCalls.c_str() );

        scene.Render();

        Window::SwapBuffers();
    }

    System::Deinit();
}