Rotating model

Hi, I made a gun model in blender 2.49 and exported it using ogre. I loaded the model in jme3 and it loads perfectly. The only thing that I am facing a problem now is the rotation of the gun model. I tried to make the gun face the camera direction but couldn’t. I sent the camera Quaternion to the guns Quaternion but the angle of the gun is wrong. It is like the sideways of the gun is the forward point which it shouldn’t be. I tried to fix it by messing around with the quaternion but no success.



If any one could help me with this I would really appreciate.



Here is an example of what i am doing:



weapon class

[java]

public class Weapon

{

public Spatial model;

public Vector3f position;

public float size;

public Bullet bullet [];

public int max = 5;

public Weapon(Spatial model, Vector3f position, float size, Spatial bulletModel, float bulletSize)

{

this.model = model;

this.position = position;

this.size = size;

setupLocals();

setupBullet(bulletModel, bulletSize);

}

private void setupLocals()

{

model.setLocalTranslation(position);

model.setLocalScale(size);

}



//This is the method for rotating the model

public void Update(float tpf, Vector3f position, Quaternion rot)

{

UpdateRotation(rot);

//Position specifies the position of the gun

}

}

private void UpdateRotation(Quaternion rotation)

{

model.setLocalRotation(rotation);

}

[/java]





main class:

[java]

public class main extends SimpleApplication

{

Weapon weapon;

public static void main(String [] args)

{

main app = new main();

app.start();

}

public void simpleInitApp()

{

Spatial weaponModel = assetManager.loadModel(“Models/Weapon…”); //Weapon Model

weapon = new Weapon(weaponModel, Vector3f.ZERO, 1, bulletModel, 0.5f);

rootNode.attachChild(weapon.model);

//then the rest for other stuff

}



@Override

public void simpleUpdate(float tpf)

{

//Codes here for moving the model and later doing the update.

weapons.Update(tpf, //some position goes here, cam.getRotation());

}

}

[/java]



Thanks

K Out!

.lookAt(cam.getLocation().add(cam.getDirection));

on a side note, you should be consistent with the case you use within your code. All Classes are usually upper camel case, while methods and instances of classes are usually lower camel case, although its neither here, nor there about what you choose in your code (there are standards) but, at least just please be consistent :stuck_out_tongue:

Thanks for the help kidneytrader it helped.



I will try to be more consistent about the code in future, wezrule, thanks.



K Out!