Jump to content
  • Advertisement
Sign in to follow this  
HellCreator

NPC integrating jbullet into my engine

This topic is 3725 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

the actual problem is in my engine java+gl4java i have objects derived from W3DObject that have properties such that
vector3f pos;
vector3f dir;
vector3f scale;
float mass;
//etc and also bounding box 
float min[3],max[3];
//and also the ref to rigid body
RigidBody rbodyref;




then i doing integration of jbullet into engine and init objects in my scene like this somethere
public boolean Add(W3DObj obj) 
	{
		//check if limit reached
		if(objs.size()>=Constants.g_max_objects_in_world)return false;
		objs.add(obj);
		if(obj.object_colide_type==ColideAble.Light_World_Object)
		light_objs.add(obj);
                //HERE ADD OBJECT TO BULET AND ASIGN REF TO RIGIDBODY
                phengine.addObjectRef(obj);
		return true;
	}




then
public boolean addObjectRef(W3DObj obj) {
// create a few dynamic rigidbodies
// Re-using the same collision is better for memory usage and performance

float mass = Float.parseFloat(obj.getAP("mass=","1.0"));
// rigidbody is dynamic if and only if mass is non zero, otherwise static
	boolean isDynamic = (mass != 0f);
	CollisionShape colShape = null;
        if (isDynamic) {
		colShape=new BoxShape(new Vector3f(1, 1, 1));
	}else{
               colShape=new StaticPlaneShape(new Vector3f(0, 1, 0), 100);
              }
              collisionShapes.add(colShape);

	// Create Dynamic Objects
        Transform startTransform = new Transform();
	startTransform.setIdentity();

	Vector3f localInertia = new Vector3f(0, 0, 0);
	if (isDynamic) {
			colShape.calculateLocalInertia(mass, localInertia);
			}
                        Vector3D centerom=obj.cd.getCenter();
			startTransform.origin.set(centerom.x,centerom.y,centerom.z);
                        obj.setPhisicsRef((Object)localCreateRigidBody(mass,startTransform,colShape));	
		return true;
    }




then in render or update function
public void updatePhysics() {
        // simple dynamics world doesn't handle fixed-time-stepping
		float ms = clock.getTimeMicroseconds();
		clock.reset();
		// step the simulation
		if (dynamicsWorld != null) 
                {
			dynamicsWorld.stepSimulation(ms / 1000000f);
                        //shootBox(getRayTo(0,0));
			//dynamicsWorld.debugDrawWorld();
		}
    }




but how now can i set the new right pos and direction from rigid bodie object? i am trying this but we dealing with center of mass that actualy is center of BB
public void applyPhisicsV1()
	{
		W3DObj obj;
                phengine.updatePhysics();
		for(int i = 0; i < objs.size();i++)
		{
		 obj=(W3DObj)objs.get(i);
                 if(obj!=null)
                 {
		 //if obj is static then skip
		 //obj1 dinamic can colide on static and dinamic
		 RigidBody rbody=(RigidBody)obj.getPhisicsRef();
                 if(rbody!=null)
                 {
                  //update obj pos and orientation from  rbody. properties
                     Vector3f cm=rbody.getCenterOfMassPosition();
                     Quat4f mo=rbody.getOrientation();
                     //here set it to obj
                     obj.pos.set(cm.x,cm.y,cm.z);
                     obj.dir.set(mo.x,mo.y,mo.z);
                 }
                 }
                }
	}




how can i set it correctly according to the BB or how i do it right way& [Edited by - HellCreator on March 19, 2008 6:13:16 AM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!