Skip to main content
deleted 93 characters in body
Source Link
user1430
user1430

I explain my problem, I want to animate Model1 (an aicraft  ) and I want an object, Model2 (a sphere), to follow it in translation anand rotation, as it is a part of this aircraft.

With the following code ( II use one or two tutotutorials to write it) everything seems good when you just movechange just one angleangle at the time = the. The sphere gently followfollows the aircraft, but if you movechange more than one angle at the same time, everything goes wrong !!.

I wonder if it's not a gimbal pblock problem? butBut I use Quaternion !! or may be (it's more probable)quaternions? Or maybe I havn'thaven't understood all thethis stuff !?

See myMy code is below, if you have an idea tell me please

Thanks a lot for help

Jean-gil:

I explain my problem, I want to animate Model1 (an aicraft  ) and I want an object, Model2 (a sphere), to follow it in translation an rotation, as it is a part of this aircraft.

With the following code ( I use one or two tuto to write it) everything seems good when you just move one angle at the time = the sphere gently follow the aircraft, if you move more than one angle at the same time, everything goes wrong !!

I wonder if it's not a gimbal pb? but I use Quaternion !! or may be (it's more probable) I havn't understood all the stuff !

See my code below, if you have an idea tell me please

Thanks a lot for help

Jean-gil

I want to animate Model1 (an aicraft) and I want an object, Model2 (a sphere), to follow it in translation and rotation, as it is a part of this aircraft.

With the following code (I use one or two tutorials to write it) everything seems good when you just change just one angle at the time. The sphere gently follows the aircraft, but if you change more than one angle at the same time, everything goes wrong.

I wonder if it's not a gimbal lock problem? But I use quaternions? Or maybe I haven't understood all this stuff?

My code is below:

Source Link

with XNA 4.0, How can I combine 2 models to make one ?

I explain my problem, I want to animate Model1 (an aicraft ) and I want an object, Model2 (a sphere), to follow it in translation an rotation, as it is a part of this aircraft.

With the following code ( I use one or two tuto to write it) everything seems good when you just move one angle at the time = the sphere gently follow the aircraft, if you move more than one angle at the same time, everything goes wrong !!

I wonder if it's not a gimbal pb? but I use Quaternion !! or may be (it's more probable) I havn't understood all the stuff !

See my code below, if you have an idea tell me please

Thanks a lot for help

Jean-gil

protected override void Update(GameTime gameTime)
    {
        // Allows the game to exit
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            this.Exit();
    
    // Command input to airplane
        float yokeUpDown = 0.0f;
        float yokeRightLeft = 0.0f;
        float RollRotation = 0.01f;

            
      //make quaternion rotation matrix of airplane
        Quaternion additionalAircraftRotation = Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), yokeUpDown) * Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), yokeRightLeft) *Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), RollRotation);

    //increase or decrease aircraft rotation
        spacecraftRotation = spacecraftRotation * additionalAircraftRotation;

    // make vector3 sphere angle rotation
        sphereAngle.X = sphereAngle.X + yokeUpDown;
        sphereAngle.Y = sphereAngle.Y + yokeRightLeft;
        sphereAngle.Z = sphereAngle.Z + RollRotation;
        

    // make rotation quaternion for sphere
        Quaternion additionalSphereRotation = Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), sphereAngle.X) * Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), sphereAngle.Y) * Quaternion.CreateFromAxisAngle(new Vector3(1,0, 0), sphereAngle.Z);

    //relative position of the sphere to the aircraft
        Vector3 translationSphere = new Vector3(-distance_Aircraft_Sphere, 0,0);


        translationSphere = Vector3.Transform(translationSphere, additionalSphereRotation);


        
        sphereposition = aircraftposition + translationSphere;


        // “VectorToAdd” = direction of the airplane
        Vector3 rotatedAircraftVector = Vector3.Transform(vectorToAdd, spacecraftRotation);

        aircraftposition += moveSpeedAircraft * rotatedAircraftVector;

        sphereposition += moveSpeedAircraft * rotatedAircraftVector;


        

}
enter code here