And another thread by me, sorry about that
I played around with physics a bit and I got this weird problem in the following code:
// ====================================================================
// This file was generated by LEBuilder
// http://leadwerks.com/werkspace
// ====================================================================
#include "engine.h"
#include <iostream>
#include <string>
#define LW_SSAO
const int ScreenWidth = 1024;
const int ScreenHeight = 768;
const char* MediaDir = "C:/Program Files/Leadwerks Engine SDK";
const char* AppTitle = "LeadwerksTest";
void createPSphere(float,float,float,TMaterial);
void ErrOut( const std::string& message ) { std::cerr << message << std::endl; }
// -------------------------------
int main( int argn, char* argv[] )
{
// Initialize
if( !Initialize() )
return 1;
SetAppTitle( AppTitle ) ;
RegisterAbstractPath( MediaDir );
// Set graphics mode
if( !Graphics(ScreenWidth,ScreenHeight) )
{
ErrOut( "Failed to set graphics mode." );
return 1;
}
// Create framework object and set it to a global object so other scripts can access it
TFramework fw = CreateFramework();
if( fw == NULL )
{
ErrOut( "Failed to initialize engine." );
return 1;
}
// Set Lua framework object
SetGlobalObject( "fw", fw );
// Set Lua framework variable
BP lua = GetLuaState();
lua_pushobject( lua, fw );
lua_setglobal( lua, "fw" );
lua_pop( lua, 1 );
// Get framework main camera
TCamera camera = GetLayerCamera( GetFrameworkLayer(0) );
PositionEntity( camera, Vec3(2,2,-10) );
// Create cube
TMaterial material = LoadMaterial( "abstract::cobblestones.mat" );
Collisions(1,1,1);
TMesh mesh2 = CreateSphere(4);
PaintEntity( mesh2, material );
TBody body2=CreateBodySphere();
EntityType(body2,1);
EntityParent(mesh2,body2);
SetBodyMass(body2,1);
PositionEntity( body2, Vec3(0.01,10,0) );
SetBodyMassCenter(body2, Vec3(0,0,0));
TMesh mesh = CreateSphere(4);
PaintEntity( mesh, material );
TBody body=CreateBodySphere();
EntityType(body,1);
EntityParent(mesh,body);
SetBodyMass(body,1);
PositionEntity( body, Vec3(0,20,0) );
SetBodyMassCenter(body, Vec3(0,0,0));
// Create ground
TMesh ground = CreateCube();
ScaleEntity( ground, Vec3(20,1,20) );
PositionEntity( ground, Vec3(0,-1.4,0) );
PaintEntity( ground, material );
body=CreateBodyBox();
ScaleEntity( body, Vec3(20,1,20) );
PositionEntity( body, Vec3(0,-1.4,0) );
EntityType(body,1);
SetBodyMass(body,0);
// Add some light
TLight light = CreateDirectionalLight();
RotateEntity( light, Vec3(45,45,45) );
SetShadowSoftness( light, 50);
//
DebugPhysics(1);
while( !KeyHit() && !AppTerminate() )
{
if( !AppSuspended() )
{
UpdateFramework();
RenderFramework();
Flip( 0 );
}
}
return Terminate();
}
It's based on the spinning cube template. The problem is, that "body2" with the small offset of 0.01 in the x-coord just falls through the ground. It seems the spheres can only collide with the ground when they are perfectly placed in the middle of it. It works fine when using box-colliders though. What am I doing wrong?