You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to achieve perfectly elastic collisions by setting the restitution of the ball and the floor to 1 in the restitution example but the ball does not behave elastically. Each time it bounces less than the previous height. I'm wondering how else can I achieve the effect?
Heres the code, although it's a slight modification of the example:
#include"raylib.h"#definePHYSAC_IMPLEMENTATION#include"physac.h"intmain()
{
// Initialization//--------------------------------------------------------------------------------------intscreenWidth=800;
intscreenHeight=450;
SetConfigFlags(FLAG_MSAA_4X_HINT);
InitWindow(screenWidth, screenHeight, "[physac] - Restitution demo");
// Physac logo drawing positionintlogoX=screenWidth-MeasureText("Physac", 30) -10;
intlogoY=15;
// Initialize physics and default physics bodiesInitPhysics();
// Create floor rectangle physics bodyPhysicsBodyfloor=CreatePhysicsBodyRectangle((Vector2){ screenWidth/2, screenHeight }, screenWidth, 100, 10);
floor->enabled= false; // Disable body state to convert it to static (no dynamics, but collisions)floor->restitution=1;
// Create circles physics bodyPhysicsBodycircleA=CreatePhysicsBodyCircle((Vector2){ screenWidth*0.5f, screenHeight/2 }, 30, 10);
circleA->restitution=1.0f;
SetTargetFPS(60);
//--------------------------------------------------------------------------------------// Main game loopwhile (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update//----------------------------------------------------------------------------------// ...//----------------------------------------------------------------------------------// Draw//----------------------------------------------------------------------------------BeginDrawing();
ClearBackground(BLACK);
DrawFPS(screenWidth-90, screenHeight-30);
// Draw created physics bodiesintbodiesCount=GetPhysicsBodiesCount();
for (inti=0; i<bodiesCount; i++)
{
PhysicsBodybody=GetPhysicsBody(i);
intvertexCount=GetPhysicsShapeVerticesCount(i);
for (intj=0; j<vertexCount; j++)
{
// Get physics bodies shape vertices to draw lines// Note: GetPhysicsShapeVertex() already calculates rotation transformationsVector2vertexA=GetPhysicsShapeVertex(body, j);
intjj= (((j+1) <vertexCount) ? (j+1) : 0); // Get next vertex or first to close the shapeVector2vertexB=GetPhysicsShapeVertex(body, jj);
DrawLineV(vertexA, vertexB, GREEN); // Draw a line between two vertex positions
}
}
DrawText("Restitution amount", (screenWidth-MeasureText("Restitution amount", 30))/2, 75, 30, WHITE);
DrawText("100%", circleA->position.x-MeasureText("100%", 20)/2, circleA->position.y-7, 20, WHITE);
DrawText("Physac", logoX, logoY, 30, WHITE);
DrawText("Powered by", logoX+50, logoY-7, 10, WHITE);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization//-------------------------------------------------------------------------------------- ClosePhysics(); // Unitialize physicsCloseWindow(); // Close window and OpenGL context//--------------------------------------------------------------------------------------return0;
}
The text was updated successfully, but these errors were encountered:
I'm trying to achieve perfectly elastic collisions by setting the restitution of the ball and the floor to 1 in the restitution example but the ball does not behave elastically. Each time it bounces less than the previous height. I'm wondering how else can I achieve the effect?
Heres the code, although it's a slight modification of the example:
The text was updated successfully, but these errors were encountered: