コード例 #1
0
void Main::onInitialize() {
    auto scene = addScene(new dt::Scene("testscene"));

    dt::ResourceManager::get()->addResourceLocation("sinbad.zip","Zip", true);
    dt::ResourceManager::get()->addResourceLocation("particle/","FileSystem", true);
    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

    // make a scene
    auto camnode = scene->addChildNode(new dt::Node("camnode"));
    camnode->setPosition(Ogre::Vector3(0, 2, 10));
    camnode->addComponent(new dt::CameraComponent("cam"))->lookAt(Ogre::Vector3(0, 2, 0));;

    auto p = scene->addChildNode(new dt::Node("p"));

    p->setScale(0.2);
    auto mesh = p->addComponent(new dt::MeshComponent("Sinbad.mesh"));
    mesh->setAnimation("RunBase");
    mesh->setLoopAnimation(true);
    mesh->playAnimation();

    auto path =
        p->addComponent(new dt::FollowPathComponent(dt::FollowPathComponent::LOOP));
    path->addPoint(Ogre::Vector3(-10, 0, 0));
    path->addPoint(Ogre::Vector3(10, 0, 0));
    path->setDuration(2.f);
    path->setFollowRotation(true);

    // create the particle system
    auto p_sys = p->addComponent(new dt::ParticleSystemComponent("p_sys"));
    p_sys->setMaterialName("Test/Particle");
    p_sys->setParticleCountLimit(1000);
    p_sys->getOgreParticleSystem()->setDefaultDimensions(0.03, 0.03);

    Ogre::ParticleEmitter* e = p_sys->addEmitter("emit1", "Point");
    e->setAngle(Ogre::Degree(10));
    e->setColour(Ogre::ColourValue(1.f, 0.6f, 0.f), Ogre::ColourValue(0.2f, 0.8f, 0.2f));
    e->setEmissionRate(100);
    e->setParticleVelocity(3.f, 4.f);
    e->setTimeToLive(1.f, 2.f);

    p_sys->addScalerAffector("scaler", 1.05);
    p_sys->addLinearForceAffector("force", Ogre::Vector3(0, 5, 0));

    Ogre::ParticleAffector* a = p_sys->addAffector("colour_interpolator", "ColourInterpolator");
    a->setParameter("time0", "0");
    a->setParameter("colour0", "1 1 0 1");
    a->setParameter("time1", "0.5");
    a->setParameter("colour1", "1 0.3 0 1");
    a->setParameter("time2", "1");
    a->setParameter("colour2", "1 0 0 0");
}
コード例 #2
0
void OGRERendererRacer::update() {

    mpVehicle = mpApp->mRacer;

    const cml::vector3d& pos = mpVehicle->mPos;

    mVehicleNode->setPosition(pos[0], pos[1], pos[2]);

    Ogre::Quaternion q;

    const quat& orientation = mpVehicle->getOrientation();

    q.w = orientation.as_vector()[0];
    q.x = orientation.as_vector()[1];
    q.y = orientation.as_vector()[2];
    q.z = orientation.as_vector()[3];

    if (q != mOrientation) {

        Ogre::Quaternion transition = q * mOrientation.Inverse();

        Ogre::Radian a;
        Ogre::Vector3 v;

        transition.ToAngleAxis(a, v);

        if (a.valueDegrees() > 0.1) {

            Ogre::Quaternion t2;

            // TODO 3: Make rotation speed configurable
            t2.FromAngleAxis(a * 0.05, v);

            mOrientation = t2 * mOrientation;
        } else {
            mOrientation = q;
        }
    }

    //################# BEGIN Construct Sideward thrust roll quaternion ################

//	cml::vector3f velDirSidewardComponent = cml::dot(mpVehicle->mDirLeft, mpVehicle->mVelocity) * mpVehicle->mDirLeft;

    if (mpVehicle->mAddThrustLeft || mpVehicle->mAddThrustRight) {
        mRollAngle = -mpVehicle->mThrustSideward * 500;
    } else {
        mRollAngle *= 0.98;
    }

    float dot = cml::dot(mpVehicle->mDirLeft, mpVehicle->mVelocity);
    mRollAngle = -dot * 50;

    Ogre::Quaternion qSidewardThrustRoll(Ogre::Degree(mRollAngle), Ogre::Vector3(0, 0, -1));

    cml::vector3f g = mpVehicle->getGravity();

    cml::vector3f velDirGravityComponent = cml::dot(g, mpVehicle->mVelocity) * g;

    dot = cml::dot(velDirGravityComponent, g);

    if (velDirGravityComponent.length() > 0.000001) {
        mPitchAngle = -cml::sign(dot) * velDirGravityComponent.length() * 500000;
    } else {

        if (mpVehicle->mAddThrustForward && mPitchAngle > -7) {
            mPitchAngle -= 0.1;
        } else {
            mPitchAngle *= 0.95;
        }
    }

    Ogre::Quaternion qForwardThrustPitch(Ogre::Degree(mPitchAngle), Ogre::Vector3(1, 0, 0));

    //################# END Construct Sideward thrust roll quaternion ################

    bool mSidewardThrustRollCamera = false;

    if (mSidewardThrustRollCamera) {
        // Roll both vehicle and camera:
        mVehicleNode->setOrientation(q * qSidewardThrustRoll * qForwardThrustPitch);
    } else {
        // Roll only the vehicle, not the camera:
        mVehicleNode->setOrientation(mOrientation);
        mVehicleMeshNode->setOrientation(qSidewardThrustRoll * qForwardThrustPitch);
    }

    //############# BEGIN Update engine particle emitters ####################

    // TODO 1: Reimplement

    bool emit = (mpVehicle->mGameState == 0) && mpVehicle->mThrustForward > 0;

    mEngineFlameParticleSystem->setEmitting(emit);
    mEngineSmokeParticleSystem->setEmitting(emit);

    Ogre::ParticleEmitter* emitter = mEngineFlameParticleSystem->getEmitter(0);
    emitter->setParticleVelocity(mpVehicle->mThrustForward * 6000);
    emitter->setEmissionRate(mpVehicle->mThrustForward * 10000);

    emitter = mEngineSmokeParticleSystem->getEmitter(0);
    emitter->setEmissionRate(mpVehicle->mThrustForward * 7000);

    //############# END Update engine particle emitters ####################
}