void PlatformDemoState::addItems() { std::function<void(const sf::Vector2f&)> createBox = [this](const sf::Vector2f& position) { auto body = xy::Component::create<xy::Physics::RigidBody>(m_messageBus, xy::Physics::BodyType::Dynamic); xy::Physics::CollisionRectangleShape cs({ 100.f, 100.f }, { -50.f, -50.f }); cs.setDensity(11.f); cs.setFriction(0.7f); body->addCollisionShape(cs); auto model = m_meshRenderer.createModel(MeshID::Cube, m_messageBus); model->setBaseMaterial(m_meshRenderer.getMaterial(MatId::Demo)); auto ent = xy::Entity::create(m_messageBus); ent->setPosition(position); ent->addComponent(body); ent->addComponent(model); m_scene.addEntity(ent, xy::Scene::BackFront); }; std::function<void(const sf::Vector2f&)> createBall = [this](const sf::Vector2f& position) { auto body = xy::Component::create<xy::Physics::RigidBody>(m_messageBus, xy::Physics::BodyType::Dynamic); xy::Physics::CollisionCircleShape cs(34.f); cs.setDensity(4.f); cs.setFriction(0.2f); cs.setRestitution(0.8f); body->addCollisionShape(cs); auto model = m_meshRenderer.createModel(MeshID::Sphere, m_messageBus); model->setBaseMaterial(m_meshRenderer.getMaterial(MatId::SphereTest)); auto ent = xy::Entity::create(m_messageBus); ent->setPosition(position); ent->addComponent(body); ent->addComponent(model); m_scene.addEntity(ent, xy::Scene::BackFront); }; for (auto i = 0u; i < 5u; ++i) { createBox({ xy::Util::Random::value(20.f, 2500.f), 20.f }); createBall({ xy::Util::Random::value(20.f, 2500.f), 20.f }); } }
Material::Material(optix::Context context, Ogre::MaterialPtr baseMaterial) { setBaseMaterial(baseMaterial); this->context = context; createMaterial(); this->reflexive=0.0f; this->opacity=1.0f; this->refractiveIndex=1.0f; update(); }
/*Draw projectiles.*/ void drawProjectiles() { for(int i = 0; i < globalProjectile.pIndex; i++) { glPushMatrix(); if(globalProjectile.projectiles[i].color == RED_BASE) setBaseMaterial(red); else if(globalProjectile.projectiles[i].color == BLUE_BASE) setBaseMaterial(blue); glTranslatef(globalProjectile.projectiles[i].position.x, globalProjectile.projectiles[i].position.y, globalProjectile.projectiles[i].position.z); drawSphereFilled(); glPopMatrix(); } }
void PlatformDemoState::addPlayer() { auto body = xy::Component::create<xy::Physics::RigidBody>(m_messageBus, xy::Physics::BodyType::Dynamic); xy::Physics::CollisionRectangleShape cs({ 120.f, 240.f }); cs.setFriction(0.6f); cs.setDensity(0.9f); body->fixedRotation(true); body->addCollisionShape(cs); auto controller = xy::Component::create<Plat::PlayerController>(m_messageBus); auto camera = xy::Component::create<xy::Camera>(m_messageBus, getContext().defaultView); camera->lockTransform(xy::Camera::TransformLock::AxisY); camera->lockBounds({ 0.f,0.f, 2816.f, 1080.f }); auto model = m_meshRenderer.createModel(MeshID::Batcat, m_messageBus); model->setBaseMaterial(m_meshRenderer.getMaterial(MatId::BatcatMat)); model->rotate(xy::Model::Axis::X, 90.f); model->rotate(xy::Model::Axis::Z, -90.f); model->setPosition({ 60.f, 240.f, 0.f }); model->playAnimation(1, 0.2f); auto entity = xy::Entity::create(m_messageBus); entity->setPosition(960.f, 540.f); entity->addComponent(body); entity->addComponent(model); playerController = entity->addComponent(controller); playerCamera = entity->addComponent(camera); m_scene.setActiveCamera(playerCamera); m_scene.addEntity(entity, xy::Scene::Layer::FrontMiddle); body = xy::Component::create<xy::Physics::RigidBody>(m_messageBus, xy::Physics::BodyType::Dynamic); body->fixedRotation(true); cs.setRect({ 200.f, 300.f }); body->addCollisionShape(cs); cs.setRect({ 80.f, 80.f }, { 60.f, -80.f }); body->addCollisionShape(cs); model = m_meshRenderer.createModel(MeshID::Fixit, m_messageBus); model->setSubMaterial(m_meshRenderer.getMaterial(MatId::MrFixitBody), 0); model->setSubMaterial(m_meshRenderer.getMaterial(MatId::MrFixitHead), 1); model->rotate(xy::Model::Axis::X, 90.f); model->rotate(xy::Model::Axis::Z, 90.f); model->setScale({ 50.f, 50.f, 50.f }); model->setPosition({ 100.f, 300.f, 0.f }); entity = xy::Entity::create(m_messageBus); entity->setPosition(1320.f, 40.f); entity->addComponent(model); entity->addComponent(body); m_scene.addEntity(entity, xy::Scene::Layer::FrontMiddle); }
void PlatformDemoState::buildTerrain() { m_shaderResource.preload(PlatformShaderId::SpecularSmooth2D, xy::Shader::NormalMapped::vertex, NORMAL_FRAGMENT_TEXTURED); m_textureResource.setFallbackColour({ 127, 127, 255 }); const auto& normalTexture = m_textureResource.get("normalFallback"); auto background = xy::Component::create<Plat::Background>(m_messageBus, m_textureResource); background->setAmbientColour(m_scene.getAmbientColour()); auto entity = xy::Entity::create(m_messageBus); entity->addComponent(background); m_scene.addEntity(entity, xy::Scene::Layer::BackRear); auto drawable = xy::Component::create<xy::AnimatedDrawable>(m_messageBus); drawable->setTexture(m_textureResource.get("assets/images/platform/left_edge.png")); drawable->setNormalMap(normalTexture); drawable->setShader(m_shaderResource.get(PlatformShaderId::SpecularSmooth2D)); entity = xy::Entity::create(m_messageBus); entity->addComponent(drawable); m_scene.addEntity(entity, xy::Scene::Layer::BackFront); //------------------------- drawable = xy::Component::create<xy::AnimatedDrawable>(m_messageBus); drawable->setTexture(m_textureResource.get("assets/images/platform/ground_section.png")); drawable->setNormalMap(normalTexture); drawable->setShader(m_shaderResource.get(PlatformShaderId::SpecularSmooth2D)); entity = xy::Entity::create(m_messageBus); entity->setPosition(256.f, 1080.f - 128.f); entity->addComponent(drawable); m_scene.addEntity(entity, xy::Scene::Layer::BackFront); //------------------------- drawable = xy::Component::create<xy::AnimatedDrawable>(m_messageBus); drawable->setTexture(m_textureResource.get("assets/images/platform/ground_section.png")); drawable->setNormalMap(normalTexture); drawable->setShader(m_shaderResource.get(PlatformShaderId::SpecularSmooth2D)); entity = xy::Entity::create(m_messageBus); entity->setPosition(1024.f, 1080.f - 128.f); entity->addComponent(drawable); m_scene.addEntity(entity, xy::Scene::Layer::BackFront); //------------------------- drawable = xy::Component::create<xy::AnimatedDrawable>(m_messageBus); drawable->setTexture(m_textureResource.get("assets/images/platform/ground_section.png")); drawable->setNormalMap(normalTexture); drawable->setShader(m_shaderResource.get(PlatformShaderId::SpecularSmooth2D)); entity = xy::Entity::create(m_messageBus); entity->setPosition(1792.f, 1080.f - 128.f); entity->addComponent(drawable); m_scene.addEntity(entity, xy::Scene::Layer::BackFront); //------------------------- drawable = xy::Component::create<xy::AnimatedDrawable>(m_messageBus); drawable->setTexture(m_textureResource.get("assets/images/platform/right_edge.png")); drawable->setNormalMap(normalTexture); drawable->setShader(m_shaderResource.get(PlatformShaderId::SpecularSmooth2D)); entity = xy::Entity::create(m_messageBus); entity->setPosition(2560.f, 0.f); entity->addComponent(drawable); m_scene.addEntity(entity, xy::Scene::Layer::BackFront); //------------------------- auto model = m_meshRenderer.createModel(MeshID::Platform, m_messageBus); model->rotate(xy::Model::Axis::X, 90.f); model->rotate(xy::Model::Axis::Z, 180.f); model->setPosition({ 384.f, 158.f, 0.f }); model->setBaseMaterial(m_meshRenderer.getMaterial(MatId::Platform01)); entity = xy::Entity::create(m_messageBus); entity->setPosition(400.f, 700.f); entity->addComponent(model); m_scene.addEntity(entity, xy::Scene::Layer::BackFront); //------------------------- drawable = xy::Component::create<xy::AnimatedDrawable>(m_messageBus); drawable->setTexture(m_textureResource.get("assets/images/platform/plat_03.png")); drawable->setNormalMap(normalTexture); drawable->setShader(m_shaderResource.get(PlatformShaderId::SpecularSmooth2D)); entity = xy::Entity::create(m_messageBus); entity->setPosition(2000.f, 550.f); entity->addComponent(drawable); m_scene.addEntity(entity, xy::Scene::Layer::BackFront); //------------------------- drawable = xy::Component::create<xy::AnimatedDrawable>(m_messageBus); drawable->setTexture(m_textureResource.get("assets/images/platform/plat_02.png")); drawable->setNormalMap(normalTexture); drawable->setShader(m_shaderResource.get(PlatformShaderId::SpecularSmooth2D)); entity = xy::Entity::create(m_messageBus); entity->setPosition(1670.f, 450.f); entity->addComponent(drawable); m_scene.addEntity(entity, xy::Scene::Layer::BackFront); //------------------------- model = m_meshRenderer.createModel(MeshID::Platform, m_messageBus); model->rotate(xy::Model::Axis::X, 90.f); model->rotate(xy::Model::Axis::Z, 180.f); model->setPosition({ 384.f, 158.f, 0.f }); model->setBaseMaterial(m_meshRenderer.getMaterial(MatId::Platform04)); entity = xy::Entity::create(m_messageBus); entity->setPosition(1210.f, 600.f); entity->addComponent(model); m_scene.addEntity(entity, xy::Scene::Layer::BackFront); //------some shadow receivers-------// model = m_meshRenderer.createModel(MeshID::Quad, m_messageBus); model->setPosition({ 0.f, 0.f, -250.f }); entity = xy::Entity::create(m_messageBus); entity->setPosition(1000.f, 702.f); entity->addComponent(model); m_scene.addEntity(entity, xy::Scene::Layer::BackFront); model = m_meshRenderer.createModel(MeshID::Quad, m_messageBus); model->rotate(xy::Model::Axis::X, 90.f); entity = xy::Entity::create(m_messageBus); entity->setPosition(1000.f, 952.f); entity->addComponent(model); m_scene.addEntity(entity, xy::Scene::Layer::BackFront); }