Beispiel #1
0
    private void Start()
    {
        tail = new PhysicsEngineForFun.AeroForceOnRigidBody(
            new PhysicsEngineForFun.Matrix3(0, 0, 0, -1, -0.5f, 0, 0, 0, -0.1f),
            new PhysicsEngineForFun.Vector3(2.0f, 0, 0),
            PhysicsEngineWindSpeed);

        left_wing = new PhysicsEngineForFun.AeroForceControlOnRigidBody(
            new PhysicsEngineForFun.Matrix3(0, 0, 0, -1, -0.5f, 0, 0, 0, 0),
            new PhysicsEngineForFun.Matrix3(0, 0, 0, -1.005f, -0.5f, 0, 0, 0, 0),
            new PhysicsEngineForFun.Matrix3(0, 0, 0, -0.995f, -0.5f, 0, 0, 0, 0),
            new PhysicsEngineForFun.Vector3(-1, 0, -2),
            PhysicsEngineWindSpeed);
        left_wing.controlSetting = 0;

        right_wing = new PhysicsEngineForFun.AeroForceControlOnRigidBody(
            new PhysicsEngineForFun.Matrix3(0, 0, 0, -1, -0.5f, 0, 0, 0, 0),
            new PhysicsEngineForFun.Matrix3(0, 0, 0, -1.005f, -0.5f, 0, 0, 0, 0),
            new PhysicsEngineForFun.Matrix3(0, 0, 0, -0.995f, -0.5f, 0, 0, 0, 0),
            new PhysicsEngineForFun.Vector3(-1, 0, 2),
            PhysicsEngineWindSpeed);
        right_wing.controlSetting = 0;

        rudder = new PhysicsEngineForFun.AeroForceControlOnRigidBody(
            new PhysicsEngineForFun.Matrix3(0, 0, 0, 0, 0, 0, 0, 0, 0),
            new PhysicsEngineForFun.Matrix3(0, 0, 0, 0, 0, 0, -0.01f, 0, 0),
            new PhysicsEngineForFun.Matrix3(0, 0, 0, 0, 0, 0, 0.01f, 0, 0),
            new PhysicsEngineForFun.Vector3(2.0f, 0.5f, 0),
            PhysicsEngineWindSpeed);
        rudder.controlSetting = 0f;
        ResetAircraft();

        PhysicsEngineForFun.Matrix3 i = new PhysicsEngineForFun.Matrix3();
        i.SetBlockInertiaTensor(new PhysicsEngineForFun.Vector3(2, 1, 1), 1);

        aircraft.SetMass(2.5f);
        aircraft.SetInertiaTensor(i);
        aircraft.linearDamping = aircraft.angularDamping = 0.8f;
        aircraft.acceleration  = new PhysicsEngineForFun.Vector3(0, -9.8f, 0);
        aircraft.CalculateDerivedData();

        registry.Add(aircraft, left_wing);
        registry.Add(aircraft, right_wing);
        registry.Add(aircraft, rudder);
        registry.Add(aircraft, tail);
    }
Beispiel #2
0
    private void Start()
    {
        sail = new PhysicsEngineForFun.AeroForceOnRigidBody(
            new PhysicsEngineForFun.Matrix3(0, 0, 0, 0, 0, 0, 0, 0, -1.0f),
            new PhysicsEngineForFun.Vector3(2.0f, 0, 0),
            PhysicsEngineWindSpeed);

        buoyancy = new PhysicsEngineForFun.BuoyancyOnRigidBody(
            new PhysicsEngineForFun.Vector3(0.0f, 0.5f, 0.0f),
            1.0f, 3.0f, 1.6f);

        sailboat.position    = new PhysicsEngineForFun.Vector3(0, 1.6f, 0);
        sailboat.orientation = new PhysicsEngineForFun.Quaternion(1, 0, 0, 0);
        sailboat.velocity    = new PhysicsEngineForFun.Vector3(0, 0, 0);
        sailboat.rotation    = new PhysicsEngineForFun.Vector3(0, 0, 0);
        sailboat.SetMass(200f);

        PhysicsEngineForFun.Matrix3 i = new PhysicsEngineForFun.Matrix3();
        i.SetBlockInertiaTensor(new PhysicsEngineForFun.Vector3(2, 2, 2), 100f);
        sailboat.SetInertiaTensor(i);

        sailboat.linearDamping = sailboat.angularDamping = 0.8f;
        sailboat.acceleration  = new PhysicsEngineForFun.Vector3(0, -9.8f, 0);
        sailboat.CalculateDerivedData();

        registry.Add(sailboat, sail);
        registry.Add(sailboat, buoyancy);

        Vector3 pos = transform.position = sailboat.position.GetUnityEngineVector3();

        transform.localEulerAngles = sailboat.rotation.GetUnityEngineVector3();

        Vector3 forward = pos - Camera.main.transform.position;

        forward.Normalize();
        if (forward == Vector3.zero)
        {
            return;
        }
        Camera.main.transform.rotation = Quaternion.LookRotation(forward);
    }