/*===========================================================================*/ void StochasticUniformGridRenderer::Engine::draw( kvs::ObjectBase* object, kvs::Camera* camera, kvs::Light* light ) { kvs::Texture::Binder unit0( m_volume_texture, 0 ); kvs::Texture::Binder unit1( m_exit_texture, 1 ); kvs::Texture::Binder unit2( m_entry_texture, 2 ); kvs::Texture::Binder unit3( m_transfer_function_texture, 3 ); kvs::Texture::Binder unit4( randomTexture(), 4 ); kvs::ProgramObject::Binder unit( m_ray_casting_shader ); if ( isEnabledShading() ) kvs::OpenGL::Enable( GL_LIGHTING ); else kvs::OpenGL::Disable( GL_LIGHTING ); const float f = camera->back(); const float n = camera->front(); const float to_zw1 = ( f * n ) / ( f - n ); const float to_zw2 = 0.5f * ( ( f + n ) / ( f - n ) ) + 0.5f; const float to_ze1 = 0.5f + 0.5f * ( ( f + n ) / ( f - n ) ); const float to_ze2 = ( f - n ) / ( f * n ); const kvs::Vector3f light_position = kvs::WorldCoordinate( light->position() ).toObjectCoordinate( object ).position(); const kvs::Vector3f camera_position = kvs::WorldCoordinate( camera->position() ).toObjectCoordinate( object ).position(); m_ray_casting_shader.setUniform( "to_zw1", to_zw1 ); m_ray_casting_shader.setUniform( "to_zw2", to_zw2 ); m_ray_casting_shader.setUniform( "to_ze1", to_ze1 ); m_ray_casting_shader.setUniform( "to_ze2", to_ze2 ); m_ray_casting_shader.setUniform( "light_position", light_position ); m_ray_casting_shader.setUniform( "camera_position", camera_position ); const size_t size = randomTextureSize(); const int count = repetitionCount() * ::RandomNumber(); const float offset_x = static_cast<float>( ( count ) % size ); const float offset_y = static_cast<float>( ( count / size ) % size ); const kvs::Vec2 random_offset( offset_x, offset_y ); m_ray_casting_shader.setUniform( "random_offset", random_offset ); this->draw_quad(); }
/* * multiply the top of the matrix stack by a view-pointing transformation * with the eyepoint at e, looking at point l, with u at the top of the screen. * The coordinate system is deemed to be right-handed. * The generated transformation transforms this view into a view from * the origin, looking in the positive y direction, with the z axis pointing up, * and x to the right. */ void look(Space *t, Point3 e, Point3 l, Point3 u){ Matrix m, inv; Point3 r; l=unit3(sub3(l, e)); u=unit3(vrem3(sub3(u, e), l)); r=cross3(l, u); /* make the matrix to transform from (rlu) space to (xyz) space */ ident(m); m[0][0]=r.x; m[0][1]=r.y; m[0][2]=r.z; m[1][0]=l.x; m[1][1]=l.y; m[1][2]=l.z; m[2][0]=u.x; m[2][1]=u.y; m[2][2]=u.z; ident(inv); inv[0][0]=r.x; inv[0][1]=l.x; inv[0][2]=u.x; inv[1][0]=r.y; inv[1][1]=l.y; inv[1][2]=u.y; inv[2][0]=r.z; inv[2][1]=l.z; inv[2][2]=u.z; ixform(t, m, inv); move(t, -e.x, -e.y, -e.z); }
void SceneHandler::addUnit(Behaviours* behaviour, GameState::Enum state) { if (state != GameState::SCENARIO) { std::shared_ptr<Unit> unit(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), state)); m_unitObjects.push_back(unit); } else { m_leader = new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), state); std::shared_ptr<Unit> unit1(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::TEAM)); unit1->m_fixRotation = 30; m_team.push_back(unit1); std::shared_ptr<Unit> unit2(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::TEAM)); unit2->m_fixRotation = 60; m_team.push_back(unit2); std::shared_ptr<Unit> unit3(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::TEAM)); unit3->m_fixRotation = 90; m_team.push_back(unit3); std::shared_ptr<Unit> unit4(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::TEAM)); unit4->m_fixRotation = 120; m_team.push_back(unit4); std::shared_ptr<Unit> unit5(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::TEAM)); unit5->m_fixRotation = 150; m_team.push_back(unit5); std::shared_ptr<Unit> unit6(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::TEAM)); unit6->m_fixRotation = 180; m_team.push_back(unit6); std::shared_ptr<Unit> unit7(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::TEAM)); unit7->m_fixRotation = 210; m_team.push_back(unit7); std::shared_ptr<Unit> enemie1(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::ENEMIE1)); m_unitObjects.push_back(enemie1); std::shared_ptr<Unit> enemie2(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::ENEMIE2)); m_unitObjects.push_back(enemie2); std::shared_ptr<Unit> enemie3(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::ENEMIE3)); m_unitObjects.push_back(enemie3); std::shared_ptr<Unit> enemie4(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::ENEMIE4)); m_unitObjects.push_back(enemie4); std::shared_ptr<Unit> enemie5(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::ENEMIE5)); m_unitObjects.push_back(enemie5); std::shared_ptr<Unit> enemie6(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::ENEMIE6)); m_unitObjects.push_back(enemie6); std::shared_ptr<Unit> enemie7(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::ENEMIE7)); m_unitObjects.push_back(enemie7); std::shared_ptr<Unit> enemie8(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::ENEMIE8)); m_unitObjects.push_back(enemie8); } }
void Test::setupScenario(RVO::RVOSimulator* sim) { /* Specify the default parameters for agents that are subsequently added. */ float radius = 2.0f; sim->setAgentDefaults(15.0f, 10, 5.0f, 5.0f, radius, 150.0f); /* * Add agents, specifying their start position, and store their goals on the * opposite side of the environment. */ for (int i = 0; i < 100; ++i) { for (int j = 0; j < 15; ++j) { GameUnitT unit(radius); unit.agentNo = sim->addAgent(RVO::Vector2(55.0f + i * 10.0f, 55.0f + j * 10.0f)); goals.push_back(RVO::Vector2(-1075.0f, -1075.0f)); unit.updatePosition(RVO::Vector2(-1075.0f, -1075.0f)); mUnits.push_back(unit); GameUnitT unit2(radius); unit2.agentNo = sim->addAgent(RVO::Vector2(-55.0f - i * 10.0f, 55.0f + j * 10.0f)); goals.push_back(RVO::Vector2(1075.0f, -1075.0f)); unit2.updatePosition(RVO::Vector2(1075.0f, -1075.0f)); mUnits.push_back(unit2); GameUnitT unit3(radius); unit3.agentNo = sim->addAgent(RVO::Vector2(55.0f + i * 10.0f, -55.0f - j * 10.0f)); goals.push_back(RVO::Vector2(-1075.0f, 1075.0f)); unit3.updatePosition(RVO::Vector2(-1075.0f, 1075.0f)); mUnits.push_back(unit3); GameUnitT unit4(radius); unit4.agentNo = sim->addAgent(RVO::Vector2(-55.0f - i * 10.0f, -55.0f - j * 10.0f)); goals.push_back(RVO::Vector2(1075.0f, 1075.0f)); unit4.updatePosition(RVO::Vector2(1075.0f, 1075.0f)); mUnits.push_back(unit4); } } /* * Add (polygonal) obstacles, specifying their vertices in counterclockwise * order. */ std::vector<RVO::Vector2> obstacle1, obstacle2, obstacle3, obstacle4; obstacle1.push_back(RVO::Vector2(-1010.0f, 1040.0f)); obstacle1.push_back(RVO::Vector2(-1040.0f, 1040.0f)); obstacle1.push_back(RVO::Vector2(-1040.0f, 1010.0f)); obstacle1.push_back(RVO::Vector2(-1010.0f, 1010.0f)); obstacle2.push_back(RVO::Vector2(1010.0f, 1040.0f)); obstacle2.push_back(RVO::Vector2(1010.0f, 1010.0f)); obstacle2.push_back(RVO::Vector2(1040.0f, 1010.0f)); obstacle2.push_back(RVO::Vector2(1040.0f, 1040.0f)); obstacle3.push_back(RVO::Vector2(1010.0f, -1040.0f)); obstacle3.push_back(RVO::Vector2(1040.0f, -1040.0f)); obstacle3.push_back(RVO::Vector2(1040.0f, -1010.0f)); obstacle3.push_back(RVO::Vector2(1010.0f, -1010.0f)); obstacle4.push_back(RVO::Vector2(-1010.0f, -1040.0f)); obstacle4.push_back(RVO::Vector2(-1010.0f, -1010.0f)); obstacle4.push_back(RVO::Vector2(-1040.0f, -1010.0f)); obstacle4.push_back(RVO::Vector2(-1040.0f, -1040.0f)); sim->addObstacle(obstacle1); sim->addObstacle(obstacle2); sim->addObstacle(obstacle3); sim->addObstacle(obstacle4); drawObstacle(obstacle1); drawObstacle(obstacle2); drawObstacle(obstacle3); drawObstacle(obstacle4); /* Process the obstacles so that they are accounted for in the simulation. */ sim->processObstacles(); }