I have a space simulation, so obviously I don't want gravity or air resistance. Gravity was straight forward to turn off, but I can't find the equivalent for air resistance. I presume it's going to be on a body-by-body basis rather than a world wide setting like gravity.
Indeed I see on btSoftBody that there are values for medium density like air_density but I am using btRigidBody.
There is no air resistance in bullet physics but there is damping
For every body you create you should set damping calling
body->setDamping(linear, angular);
set linear to be 0
Related
I have some questions for correctly implementing a system that add gravity to my player while still detecting and correcting collision with the floor. I understand the basic math for the AABB and adding gravity vector to the players velocity vector then adding it to the position. For some reason when I try the player stops for the first few frames then eventually the velocity builds up to be more than the tile width and it goes through. I guess my real question is how to properly implement the gravity with the collision. Do I make gravity vector 0, 0 when it hits the floor or when I am just standing on the floor my collision detection will constantly move me out of the floor? I really don't know the flow of the logic with this situation.
Edit 1:
I am trying to make the simple engine myself to gain experience with programming. I kind of solved the one problem, I now can stop on the floor. My current logic is:
add gravity to velocity, check for collision, adjust the velocity by the offset of the collision, if any, add velocity to the position then set velocity to 0.
m_velocity += m_gravity;
glm::vec2 mtd = collideWithObject(objectVector);
m_velocity -= mtd;
m_position += m_velocity;
m_velocity.x = 0.0f;
m_velocity.y = 0.0f;
It works but I am not sure if that is the flow, I guess I just want to know what is the most common way to implement this.
For some reason when I try the player stops for the first few frames then eventually the velocity builds up to be more than the tile width and it goes through.
If you are applying physics in increments - such as once every frame - you must account for the infinite increments that exist between each of those points.
For a simple "plane collision", like your floor, don't test if your current AABB collides with the floor. Create the smallest AABB that includes your current AABB and the last AABB. If that box collides, you've collided with the plane.
as #MorphingDragon mentioned, you should consider Box2D, many games use Box2D.
For your question "Do I make gravity vector 0, 0 when it hits the floor or when I am just standing on the floor my collision detection will constantly move me out of the floor? I really don't know the flow of the logic with this situation.". I just assume you know Verlet integration, for calculate your new position, you don't need to change your gravity, [as you know, gravity is everywhere on earth, or you want to do a game in space, ;)] you just need to handle the collision detection logic as "when collision happens, just make the collision point satisfy my constraints", and your constraint should be "all point should not be placed under the floor, otherwise just move it and make it sit on the floor".
The collection detection and constraint solver theory should be very common in modern physical engine and easy to understand and implement.
Hope this help.
Thanks
An
I'm currently making a 2D pool game where i have to use real physics simulation. I have done the circle collision and elastic collision so far, But I want a formula which can find the collision response velocity, which differs when a ball collides with other at different points thanks in advance.
There are many approaches, but if you can afford to make the balls overlap a bit (that is, to make part of the ball "enter" the other) you can turn it into a spring-damper system and solve with Hooke's law.
Since Hooke's law give you the force, you need to integrate it to find the momentum. Momentum divided by mass is the velocity you're looking for.
Take a look at this excellent intro of spring physics for game development (that also has a link for his intro on numerical integration).
edit: if you're looking for a practical solution I suggest the Box2D physics engine.
Pool collision can be considered as elastic collision throughout the board, with friction slowing down its movement.
Don;t think the collision response in terms of angles to the circle. Using vectors will ease the problem.
The circle-circle collision velocity response is easy:
1. When collision is detected
2. FInd the normal velocity of the balls acting toward the other ball.
3. Interchange the Normal velocity between the two balls
4. Resolve the velocity in x and y direction
A very helpful webiste to find the velocity response in terms of vectors: http://archive.ncsa.illinois.edu/Classes/MATH198/townsend/math.html
I am developing third-person shooting game using Bullet and Ogre. When the character model collides with an object in the world, such as a power-up, the collision applies a force to the character and causes them to spin. How can I prevent the collision applying a force to the character?
I have set a method for btDynamicsWorld::setInternalTickCallback and so I know which bodies are colliding and the btManifoldPoint.
Note that I applyTorque to the body in order to rotate them smoothly so I cannot simply prevent rotation.
Thanks for your help.
I am unfamiliar with the physics engines you mentioned, but I know a thing or two about real physics...
Basically if you draw a free body diagram and arrows that represent the forces, you can determine the net effect. Or if you know the desired net effect, you can figure out where you need to add forces or remove forces.
You could add an equal and opposite force/torque at the time of impact. This would make the net forces on your object zero.
Or you could take the elements that are causing the forces and make them massless. Force = mass * acceleration. If the mass is zero and your physics engine is based on real world physics, then it shouldn't cause any net forces on collision.
Hope that helps.
I d like to make my Camera shake in opengl
my old algorithm is:
setCamPosXYZ(x+randx,y+randy,z+randz);
but it is not the best. What is a better solution, a real world camera shake?
I have found a sin function with a high frequency and a gradually decreasing amplitude looks very convincing. If you want it to appear more random you can have different frequencies for each direction and it will bounce around more randomly. A sin function is also makes sense physically because if you think of the camera being mounted on a very stiff spring with some damping, then it's going to oscillate like a damped sin curve.
Generate x+randx,y+randy,z+randz
and then animate smoothly (liner interpolation) between existing camera pos
and x+randx,y+randy,z+randz
for a smooth shake.
To animate smoothly set your new
x at each time step to xinitial + k(randx)
Once you reach the random shake point generate a new random point and again animate
using linear interpolation
A real world camera shake is a reaction to some force, like a bumb or a shockwave, so it's a movement in one direct, then a countermovement in the other direction, moving back and forth until it stabilises.
So start with a sinus wave that dissipates, and then you might add some random to this to make it a bit more jerky.
Also, you should add a slight rotation of the camera along with the movement.
Does anyone have any guidance for coding an approximation for the particle stream coming out of a jet engine (with afterburner) in opengl using particles drawing using vertex buffers / 4f color buffers?
I believe there are two aspects to this problem:
The colour of the light as particles exit the jet engine as a function of temperature and some constants relating to the type of gas being burnt. This article leads me to believe I will need some sort of array for the temperature / color conversion curve. Apprently hydrogen burns at 2,660C in oxygen and 2,045C in air whereas jet fuel burns at 287.5C in air. (but the temperature of jet fighter afterburner can reach 1700C somehow)
The vapour trail behind the rocket / jet which will be either white with alpha for the water base vapour trail if the rocket is in atmosphere. Also I believe my assumption is correct that this would not be necessary for a rocket burning fuel in space. The vapour trail will simulated as tiny water droplets which are much larger than the wavelength of visible light, so they would scatter light achromatically. As water itself is colorless the resulting color would be white?
Also I am looking to model this from a birds eye perspective so it does not need to be a full 3D model. So the positions of the 10 or so pilot lights around the afterburner cone for example could just be approximated as maybe 5 linear points.
Depending on the level of detail you require, you may want to simple use a textured cone coming out of the yet engine. If you want to go for a full-blown particle system (which for a jet engine does not appear necessary to me) then you might want to give each particle on the stack a bunch of properties like speed (vec3), size, gas type and age.
Make a loop to process each particle each time your game loop goes around. For each tick, your simulation would then change the speed and size as the particle gets older. You should make a functions that determines the look of the particle according to its age and gas type.
At its simplest, this could make colored particles fade, enlarge and speed down as it gets older. Is this what you are looking for?