physics-engine

Centroid of convex polyhedron

北城余情 提交于 2019-12-22 04:50:12
问题 I have a closed convex polyhedron which is defined by an array of convex polygons (faces) which are defined by arrays of vertices in 3D space. I'm trying to find the centroid of the polyhedron, assuming uniform density. At the moment I calculate it with the algorithm in this pseudo-code. public Vector3 getCentroid() { Vector3 centroid = (0, 0, 0); for (face in faces) { Vector3 point = face.centroid; point.multiply(face.area()); centroid.add(point); } centroid.divide(faces.size()); return

How to stop the forces acting on a body in box2d

此生再无相见时 提交于 2019-12-22 03:16:06
问题 I am using box2d on the iphone to create a game. I have a body that is effected by gravity to move down and not right or left. It will get hit by another body and will then be moving right or left. I then have a reset button which moves the body back to its starting point. The only problem is that it is still moving right or left. How can I counteract the forces that a ball is already traveling? How can I get rid of this right and left movement when I reset my game? 回答1: box2d automatically

How to stop the forces acting on a body in box2d

爱⌒轻易说出口 提交于 2019-12-22 03:16:06
问题 I am using box2d on the iphone to create a game. I have a body that is effected by gravity to move down and not right or left. It will get hit by another body and will then be moving right or left. I then have a reset button which moves the body back to its starting point. The only problem is that it is still moving right or left. How can I counteract the forces that a ball is already traveling? How can I get rid of this right and left movement when I reset my game? 回答1: box2d automatically

Slick2D and JBox2D. How to draw

谁说胖子不能爱 提交于 2019-12-17 10:24:18
问题 Before asking this i did A LOT of searching on the net. I just can't do it. It's a little hard for me to understand. So how do i draw the images at the right screen positions coresponding to bodies in world position? Thanx. If anyone else finds himslef in front of the same obstacle i posted a HOW TO, thanx to normalocity's good explanation. You can find it here: http://romeo.akademx.ro/2012/04/06/slick-and-box2d/ This is the render function: public void render(GameContainer container,

How to apply rotation to a body in Bullet Physics Engine?

烈酒焚心 提交于 2019-12-14 01:21:22
问题 I have rotation values (roll, pitch, yaw). I would like to apply that rotation to a body, but I have no idea how to do that. 回答1: The most straightforward way would be to directly set the world transform for a rigid body, either through a motion state or by direct setting. To get a transform from roll, pitch, and yaw, you could use: btRigidBody * rigidBody = //... btTransform tr; tr.setIdentity(); btQuaternion quat; quat.setEuler(yaw,pitch,roll); //or quat.setEulerZYX depending on the

Few rigidbody cause Bullet Physics slowly

时光怂恿深爱的人放手 提交于 2019-12-13 16:17:17
问题 I'm currently doing the job for intergrating physics engine, Bullet Physics, into my graphics engine, Before that, I implemented the easy collision system with SAP and Narrowphase algorithm, the cost of time was 3ms for SAP and Narrowphase with about 300 objects. Because of some bugs of my algorithm, I decided to change to the real physics engine, Bullet Physics. So I followed the tutorial by official articles. When I thought I know how to implement in my graphics engine, and the output

(Physics engine for games like Sugar, Sugar) SpriteKit performance optimization for many physics sprites

懵懂的女人 提交于 2019-12-13 03:36:17
问题 I'm a iOS game developer and I saw an interesting physics & draw game "Sugar, Sugar" recently. In the game, there are lots of pixel particles (thousands of them) generated from the screen and free falling to the ground. Player can draw any shape of lines, which can guide those particles to certain cups. A image from google: I'm trying to achieve similar effect using SpriteKit with Swift. Here's what I got: Then I encounter a performance problem. Once the number of particles > 100. The CPU and

famo.us access to collisionData upon collision event

北慕城南 提交于 2019-12-12 03:58:23
问题 In the famo.us source I see that two things are emitted upon collision: the 'collision' string, and a variable called collisionData, like this: (physics/constraints/Collision.js, lines 112-122): if (this._eventOutput) { var collisionData = { target : target, source : source, overlap : overlap, normal : n }; this._eventOutput.emit('preCollision', collisionData); this._eventOutput.emit('collision', collisionData); } I know how to use the 'collision' string like so: collision.on('collision',

What causes the joints of a physics engine to tear?

ぐ巨炮叔叔 提交于 2019-12-12 01:54:04
问题 I will keep this brief, know that what I am talking about happened on Box2d for AS3 in 2009, and it also happens today with a totally separate library p2 physics in JavaScript. Please go to the following 2d ragdoll demo page and spin the ragdoll around by the head quite vigorously. https://schteppe.github.io/p2.js/demos/ragdoll.html You will see the result that the joints separate and turn elastic. This problem prevents me making anything fun with physics. Ball and chains, catapults,

Unity Physics: How To Limit Rotation of Object Moved by Gravity

橙三吉。 提交于 2019-12-11 05:38:45
问题 I have a Child object, an Iron Bar (with Rigidbody and Gravity), connected to a Long Arm (w/ Rigidbody and isKinematic). I need to restrict the rotation of the Iron Bar from 1 to 40 degree angles only so it won't go overboard and hit the Long Arm . Please refer to attached image for more info. I tried several approaches from using a Hinge Joint and its Limit options and also through code. But I cannot seem to solve this problem. Right now I have this script attached to the Iron Bar but it