Node::Ptr createTransparentObject(float scale, float rotationY, file::AssetLibrary::Ptr assets) { assert(assets); assert(NUM_OBJECTS > 0); auto randomAxis = Vector3::create((float)rand(), (float)rand(), (float)rand())->normalize(); const float randomAng = 2.0f * (float)PI * rand() / (float)RAND_MAX; return scene::Node::create() ->addComponent(Transform::create( Matrix4x4::create() ->appendRotation(randomAng, randomAxis) ->appendScale(scale) ->appendTranslation(1.0f) ->appendRotationY(rotationY) )) ->addComponent(Surface::create( assets->geometry("cube"), material::BasicMaterial::create() ->diffuseColor(Color::hslaToRgba(0.5f * rotationY / (float)PI, 1.0f, 0.5f, 0.5f)) ->isTransparent(true, true) ->triangleCulling(render::TriangleCulling::BACK), assets->effect("effect/Basic.effect") )); }
Node::Ptr createPhysicsObject(unsigned int id, file::AssetLibrary::Ptr assets, bool isCube) { const float mass = MIN_MASS + (rand() / (float)RAND_MAX) * (MAX_MASS - MIN_MASS); const float size = MIN_SCALE + (rand() / (float)RAND_MAX) * (MAX_SCALE - MIN_SCALE); const float startX = MIN_DROP_POS->x() + (rand() / (float)RAND_MAX) * (MAX_DROP_POS->x() - MIN_DROP_POS->x()); const float startY = MIN_DROP_POS->y() + (rand() / (float)RAND_MAX) * (MAX_DROP_POS->y() - MIN_DROP_POS->y()); const float startZ = MIN_DROP_POS->z() + (rand() / (float)RAND_MAX) * (MAX_DROP_POS->z() - MIN_DROP_POS->z()); const float halfSize = 0.5f * size; const float hue = (id % 10) * 0.1f; auto diffColor = Color::hslaToRgba(hue, 1.0f, 0.5f, 1.0f); auto specColor = Color::hslaToRgba(hue, 1.0f, 0.8f, 1.0f); const float shininess = 2.0f * (rand() / (float)RAND_MAX) * 6.0f; bullet::Collider::Ptr collider = nullptr; if (isCube) { auto boxColliderData = bullet::ColliderData::create( mass, bullet::BoxShape::create(halfSize, halfSize, halfSize) ); collider = bullet::Collider::create(boxColliderData); } else { auto sphColliderData = bullet::ColliderData::create( mass, bullet::SphereShape::create(halfSize) ); collider = bullet::Collider::create(sphColliderData); } return scene::Node::create("node_" + std::to_string(id)) ->addComponent(Transform::create( Matrix4x4::create() ->appendScale(size) ->appendTranslation(startX, startY, startZ) )) ->addComponent(Surface::create( assets->geometry(isCube ? "cube" : "sphere"), material::PhongMaterial::create() ->specularColor(specColor) ->shininess(shininess) ->diffuseColor(diffColor), assets->effect("phong") )) ->addComponent(collider); }
void generateStars(unsigned int numStars, file::AssetLibrary::Ptr assets, std::vector<Node::Ptr>& starNodes) { if (assets == nullptr) throw std::invalid_argument("assets"); starNodes.clear(); starNodes.resize(numStars, nullptr); for (unsigned int i = 0; i < numStars; ++i) { starNodes[i] = Node::create("star_" + std::to_string(i)) ->addComponent(Transform::create()) ->addComponent(Surface::create( assets->geometry("smallStar"), Material::create() ->set("diffuseColor", generateColor()) ->set("colorMask", true) ->set("depthMask", false) ->set("depthFunc", CompareMode::ALWAYS) ->set("stencilFunc", CompareMode::EQUAL) ->set("stencilRef", 1) ->set("stencilMask", (unsigned int)0xff) ->set("stencilFailOp", StencilOperation::KEEP), assets->effect("basic") )); const float minX = -1.0f; const float rangeX = 1.0f - minX; const float minY = -1.0f; const float rangeY = 1.0f - minY; starNodes[i]->component<Transform>()->matrix() ->appendScale(0.25f, 0.25f, 0.25f) ->appendRotationZ(2.0f * (float)PI * (rand() / (float)RAND_MAX)) ->appendTranslation( minX + (rand() / (float)RAND_MAX)*rangeX, minY + (rand() / (float)RAND_MAX)*rangeY, 0.0f ); } }
void printValidation(std::shared_ptr<geometry::Geometry> originalAsset, std::string assetName, file::AssetLibrary::Ptr assets) { std::cout << " Valid : " << originalAsset->equals(assets->geometry(assetName)) << std::endl; }