/** * Creates a new firework of this type and writes it into the given * instance. The optional parent firework is used to base position * and velocity on. */ void create(Firework *firework, const Firework *parent = NULL) const { firework->type = type; firework->age = crandom.randomReal(minAge, maxAge); cyclone::Vector3 vel; if (parent) { // The position and velocity are based on the parent. firework->setPosition(parent->getPosition()); vel += parent->getVelocity(); } else { cyclone::Vector3 start; int x = (int)crandom.randomInt(3) - 1; start.x = 5.0f * cyclone::real(x); firework->setPosition(start); } vel += crandom.randomVector(minVelocity, maxVelocity); firework->setVelocity(vel); // We use a mass of one in all cases (no point having fireworks // with different masses, since they are only under the influence // of gravity). firework->setMass(1); firework->setDamping(damping); firework->setAcceleration(cyclone::Vector3::GRAVITY); firework->clearAccumulator(); }
void RagdollDemo::reset() { bones[0].setState( cyclone::Vector3(0, 0.993, -0.5), cyclone::Vector3(0.301, 1.0, 0.234)); bones[1].setState( cyclone::Vector3(0, 3.159, -0.56), cyclone::Vector3(0.301, 1.0, 0.234)); bones[2].setState( cyclone::Vector3(0, 0.993, 0.5), cyclone::Vector3(0.301, 1.0, 0.234)); bones[3].setState( cyclone::Vector3(0, 3.15, 0.56), cyclone::Vector3(0.301, 1.0, 0.234)); bones[4].setState( cyclone::Vector3(-0.054, 4.683, 0.013), cyclone::Vector3(0.415, 0.392, 0.690)); bones[5].setState( cyclone::Vector3(0.043, 5.603, 0.013), cyclone::Vector3(0.301, 0.367, 0.693)); bones[6].setState( cyclone::Vector3(0, 6.485, 0.013), cyclone::Vector3(0.435, 0.367, 0.786)); bones[7].setState( cyclone::Vector3(0, 7.759, 0.013), cyclone::Vector3(0.45, 0.598, 0.421)); bones[8].setState( cyclone::Vector3(0, 5.946, -1.066), cyclone::Vector3(0.267, 0.888, 0.207)); bones[9].setState( cyclone::Vector3(0, 4.024, -1.066), cyclone::Vector3(0.267, 0.888, 0.207)); bones[10].setState( cyclone::Vector3(0, 5.946, 1.066), cyclone::Vector3(0.267, 0.888, 0.207)); bones[11].setState( cyclone::Vector3(0, 4.024, 1.066), cyclone::Vector3(0.267, 0.888, 0.207)); cyclone::real strength = -random.randomReal(500.0f, 1000.0f); for (unsigned i = 0; i < NUM_BONES; i++) { bones[i].body->addForceAtBodyPoint( cyclone::Vector3(strength, 0, 0), cyclone::Vector3() ); } bones[6].body->addForceAtBodyPoint( cyclone::Vector3(strength, 0, random.randomBinomial(1000.0f)), cyclone::Vector3(random.randomBinomial(4.0f), random.randomBinomial(3.0f), 0) ); // Reset the contacts cData.contactCount = 0; }