A Few questions on optimizing the physics space

Hi folks, I’m in the process of trying to squeeze out every last drop of fps (on android).



At this juncture I have my game map when loaded running at ~60fps. (my first attempt with this map was 4fps…heh much improved since then).

When I load it up into the actual game with the physics space the fps drops to < 50fps. (that’s with no moving parts, for some reason this feels odd…I would have expected close to zero impact until there are actually moving objects in the physics space…).



regardless I am now looking towards to optimizing the physics space now…my goal is essentially have it running at 55+ on this device (asus transformer 300).



Game Map Stats:

Textures (M,F,S) all 17

Shaders(M,F,S):4,4,13

Objects:100

Uniforms: 182

Triangles:2990 (this will go up to ~4000 during game play)

Vertices:8450



I believe the physics space currently contains 65 objects:

Kinematic Objects: 13 (will increase to 15 at most during game play…upto 2 balls will be added)

Static Objects: 52 (i.e. kinematic false, mass 0)



Anyways…Seeing as my objects are essentially created in blender, as of right now they are all (of those that play a role in the physics world) being added as RigidBodyControls (presumably using MeshCollisionShape)

I changed th floor to use a PlaneCollision shape without issue.

I am currently trying to see if switching to SimplixCollisionShape for the objects that are quads, but to no avail…when I try

the SimplexCollisionShape, the object no longer appears to be collidable.



I tried adding like this: (this method of course only wraps 1 triangle…but regardless even that triangle doesn’t appear to be collide

Is there something wrong about the approach shown below?



[java][/java]

Node n = (Node)pobj.spatial;

Geometry g = (Geometry)n.getChild(0);

Mesh m = g.getMesh();

FloatBuffer vertexBuffer = m.getFloatBuffer(Type.Position);

Vector3f[] v = BufferUtils.getVector3Array(vertexBuffer);

CollisionShape cs = new SimplexCollisionShape(v[0],v[1],v[2]); // ignore 2nd triangle for now…

pobj.rbc = new RigidBodyControl(cs,0);

pobj.spatial.addControl(pobj.rbc);

bas.getPhysicsSpace().add(pobj.rbc);

[java][/java]



One thing I noticed…The vector positions returned are really small…I suspect.

Fact: The object was created in blender and scaled…

2) When getting the vertex positions they do not reflect the scaling.

3) Confirmed: when get WorldScale on the object, it has scaling factors other then 1.



so…do I simply need to apply the same scaling factors on each vertex? and…if the object itself has scaling

parameters does that mean the object is in fact being scaled for each frame?

Also Is simplexCollisionShapes actually more performant then a meshCollisionShape (even if the underlying object is just a quad?)



Other random Thoughts:

I could potentially define 2 physics spaces, (say left side/rightside), and have the ‘balls’ essentially switch the physics space they belong to based on the x coordinate, this would make each physics space smaller…but…I suspect that really will not improve overall performance…especially once 2 balls are in the game and both physics spaces will need to be active at the same time.



Also I noticed that if I have a ghostControl that overlaps with another static physics object…it gets collision calls, it seems like there should be a way to define multiple objects in the physics space such that collision calculations only consider certain objects…i.e. the engine is obviously doing collision calculations between the ghostControl and the other static objects (which for my purposes is wasted cpu cycles)…even though both do not move…this makes me think I have something configured/setup incorrectly with the physics space in general.



anyhow any feed back/pointers welcome :slight_smile: and encouraged :slight_smile:

use coliision groups/flags to prevent checking between ghost and statics then.

Yeah, I actually tried that briefly, but to no avail…but…based on response…I will give it another shot…

What I did for my ‘group’ I put the ghost in a specific group, but the collisions ‘with’ the floor were still happening…which makes me think…maybe if group is not defined for an object…it will in fact be collidable with all object regardless of their group?..I will try explicitly putting the floor in a different group as well, and see what happens :slight_smile:

Ahh, I got it working:



pobj.gc.removeCollideWithGroup(PhysicsCollisionObject.COLLISION_GROUP_01);

pobj.gc.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02);



now…one more question:

If I have say 20 GhostControls…and they are placed into group 2, (and removed from group 1)…I assume based on this

that JBullet will in fact test all 20 objects for collisions against each other every tick…since these Ghosts are all static…I gather what I really should do is put each GhostControl into its own Group, and then have the moving objects all set to collide with all ‘ghost’ groups, resulting in only the ‘moving’ object collision test occurring with each ghost, rather then the ghosts doing collisions checks on each other.

Those will all be eleminated in the broadspace if their bounding boxes do not intersect. very fastly, its about O(log n) if i remeber right.