示例#1
0
void RigidBody::initValues(float mass, Matrix3 Ibody ,

		Vector3 position, Vector3 velocity,
		Quaternion rotation , Vector3 angularMomentum ){
		setPosition(position);
		setRotation(rotation);

		setMass(mass);
		setIbody(Ibody);
		setVelocity(velocity);

		setAngularMomentum(angularMomentum);
}
示例#2
0
RigidBlock::RigidBlock(float a, float b, float c, float mass,
	Vector3 position, Vector3 velocity,
	Quaternion rotation, Vector3 angularMomentum){
	//Status setzen
	setMass(mass);
	setPosition(position);
	setRotation(rotation);

	//Trägheitstensor berechnen
	setDimensions(a,b,c);

	setVelocity(velocity);
	setAngularMomentum(angularMomentum);

	//printState();
}
void ClientUnit::simulateUnit()
{
    // Apply latest frame inputs just before simulation
    Real time = TIME_PER_FRAME;
    
    mScale = mSpeed*time;
    mAgressorTime += time;
    mTargetTime += time;
    mFireTime += time;
    mMoveTime += time;

    if (mAgressorTime >= TIME_TO_PEACE) {
        mAgressor = 0;
    }
    if (mTargetTime >= TIME_TO_PEACE) {
        mTarget = 0;
    }

    // Motion control
    mInput->vMove.x         = ((int)mInput->aKey[KEY_LEFT   ] - (int)mInput->aKey[KEY_RIGHT   ]);
    mInput->vMove.y         = ((int)mInput->aKey[KEY_UP     ] - (int)mInput->aKey[KEY_DOWN    ]);
    mInput->vMove.z         = ((int)mInput->aKey[KEY_FORWARD] - (int)mInput->aKey[KEY_BACKWARD]);
    mInput->vRotate.x       = -(int)mInput->aAxe[0];
    mInput->vRotate.y       =  (int)mInput->aAxe[1];

    // Apply motion control
    if (mCtrl != MODE_GHOST) {
        if (!maState[0] && mInput->aKey[KEY_FORWARD] || !maState[1] && mInput->aKey[KEY_BACKWARD]) {
            this->setLinearVelocity(Vec3(0.0f, 0.0f, 0.0f));
            this->setAngularVelocity(Vec3(0.0f, 0.0f, 0.0f));
            this->setLinearMomentum(Vec3(0.0f, 0.0f, 0.0f));
            this->setAngularMomentum(Vec3(0.0f, 0.0f, 0.0f));
        }
        if (mInput->aKey[KEY_BREAK]) {
            this->setLinearVelocity(Vec3(0.0f, 0.0f, 0.0f));
            this->setAngularVelocity(Vec3(0.0f, 0.0f, 0.0f));
            this->setLinearMomentum(Vec3(0.0f, 0.0f, 0.0f));
            this->setAngularMomentum(Vec3(0.0f, 0.0f, 0.0f));
        }
        if (!maState[3] && mInput->aKey[KEY_LEFT] || !maState[4] && mInput->aKey[KEY_RIGHT]) {
            if (mSaladin->maReferentiel[0]->speed > 10.0f) {
                setAngularVelocity(Vec3(0.0f, 0.0f, 0.0f));
                setAngularMomentum(Vec3(0.0f, 0.0f, 0.0f));
            }
        }
        if (!maState[2]) {
            mMoveTime = 0;
        }
        mSaladin->simulateRotation(
            mInput->vRotate.x*mScale.y,
            mInput->vRotate.y*mScale.y
        );
        mSaladin->simulateTorque(
            mInput->aKey[KEY_BREAK],                                                                                // DIRBRAKE
            mInput->vMove.z,                                                                                        // DIRTORQUE
            mInput->vMove.x,                                                                                        // DIRSTEER
            mSpeed,                                                                                                 // speed
            mScale,                                                                                                 // scaled speed
            mDiff                                                                                                   // TORQUE DIFFERENTIAL
        );
        simulateFire(
            mInput->aButton[0]
        );
        if (mInput->aKey[KEY_FORWARD]) {
            maState[0] = true;
            maState[1] = false;
            maState[2] = false;
        }
        if (mInput->aKey[KEY_BACKWARD]) {
            maState[0] = false;
            maState[1] = true;
            maState[2] = false;
        }
        if (mInput->aKey[KEY_LEFT] || mInput->aKey[KEY_RIGHT]) {
            maState[2] = false;
        }
        maState[3] = mInput->aKey[KEY_LEFT];
        maState[4] = mInput->aKey[KEY_RIGHT];

        if (mInput->aKey[KEY_BREAK]) {
            maState[0] = true;
            maState[1] = false;
            maState[2] = true;
            maState[3] = false;
            maState[4] = false;
        }
    }
}