I fixed most problems. You can refer to my physics-component branch to have a try. There is a test case named Node: PhysicsComponent in cpp-tests.
There is one issue left. Ray cast doesn’t work correctly with some special triangles. I think it is something about the codes i changed in PhysicsShapePolygon::updateScale()
If i don’t change the codes, then i can not query polygons in cpSpace, which means cpSpaceNearestPointQuery() can not find polygon though the query point inside it. You can test it by the step:
revert the codes i changed
run cpp-tests
select Node: PhysicsComponent
enter Pyramid Stack
you will find you can not select grossinis but can select the ball
add doxygen comments for new classes and functions
add some comments of the codes
move codes of PhysicsComponentTest.cpp/.h into PhysicsTest.cpp/.h and deleted PhysicsComponentTest.cpp/.h
delete test case PhysicsComponentTest and reuse PhysicsTest
The only bug left i mentioned above has not been resolved.
In order to be reviewed conveniently, i squashed all commits into one commit. All the modification is in this commit. You can ignore the modification of physics test case.
@zhangxm
well done. the code is much cleaner, much easier to maintain.
I haven’t reviewed it if it works Ok, or if it is performant, but I like the high-level design.
A few things that I would do:
run Instruments and profile the code. Try to find possible bottlenecks, or parts of the code that might run slow. In particular, the getInversed() might slow down things a bit…
also compare its performance with v3.7. Is it slower? How much slower?
Yep, i am thinking about it too. But i can’t, because there is not way to know if the transform is changed or not.
If i can cache the result in physics component, then i think we can cache it in Node too. And it is more reasonable to cache it in Node because even without physics component, we should get the transform every frame.
Did you mean the variable _transformDirty in Node? If so, then the reason is:
Node::getNodeToParentTransform() will change the variable to false, and this function may be invoked in anytime anywhere
If we can cache the result in Node, then the component can use the result, don’t have to cache it in component too. But as i can see, it just use _transformDirty to reduce some computation, but not caching the world transform.
I think guys CCNode has became too heavy, it’s so overloaded! Think about developers who want to make simple 2d games, or games without collision detection, my suggestion is adding a special CCNode beside the original one for such purpose and leave the choice for the developer : use it or not…