ive been trying to get mousejoint going for the last month 😮
anyway i basically tried incorporating the testbed example into my project but im now getting a segmentation signal
the errors dont make sense, theyre looking for files, on the desktop that ive never linked too, (my thought are theyre just temp), i got around that problem by copying and pasting the box2d folder to the desktop, but that still left the other errors
debugger
Call Stack
main.c
objects.h
thanks
anyway i basically tried incorporating the testbed example into my project but im now getting a segmentation signal
the errors dont make sense, theyre looking for files, on the desktop that ive never linked too, (my thought are theyre just temp), i got around that problem by copying and pasting the box2d folder to the desktop, but that still left the other errors
debugger
Quote:
Building to ensure sources are up-to-date
Build succeeded
Selecting target:
default
Adding source dir: C:\Documents and Settings\Emmet\My Documents\Life Of Slime\
Adding source dir: C:\Documents and Settings\Emmet\My Documents\Life Of Slime\
Adding file: SDL_GFX.exe
Starting debugger:
done
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
Debugger name and version: GNU gdb 6.7.50.20071127
Child process PID: 720
Program received signal SIGSEGV, Segmentation fault.
At C:/Documents and Settings/Emmet/Desktop/Box2D_v2.0.1/Box2D/Source/Collision/../Common/b2Math.h:108
Debugger finished with status 0
Build succeeded
Selecting target:
default
Adding source dir: C:\Documents and Settings\Emmet\My Documents\Life Of Slime\
Adding source dir: C:\Documents and Settings\Emmet\My Documents\Life Of Slime\
Adding file: SDL_GFX.exe
Starting debugger:
done
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
Debugger name and version: GNU gdb 6.7.50.20071127
Child process PID: 720
Program received signal SIGSEGV, Segmentation fault.
At C:/Documents and Settings/Emmet/Desktop/Box2D_v2.0.1/Box2D/Source/Collision/../Common/b2Math.h:108
Debugger finished with status 0
Call Stack
Quote:
Nr Address Function
#0 00421CB1 b2Vec2::Set(this=0x4, x_=50, y_=50) (C:/Documents and Settings/Emmet/Desktop/Box2D_v2.0.1/Box2D/Source/Collision/../Common/b2Math.h:108)
#1 00401462 SDL_main(argc=1, argv=0xa626c8) (C:/Documents and Settings/Emmet/My Documents/Life Of Slime/main.cpp:138)
#2 004025E7 console_main(argc=1, argv=0xa626c8) (./src/main/win32/SDL_win32_main.c:217)
#3 004027C5 WinMain(hInst=0x400000, hPrev=0x0, szCmdLine=0x241f29 "", sw=10) (./src/main/win32 /SDL_win32_main.c:353)
#4 00402044 main() (??:??)
#0 00421CB1 b2Vec2::Set(this=0x4, x_=50, y_=50) (C:/Documents and Settings/Emmet/Desktop/Box2D_v2.0.1/Box2D/Source/Collision/../Common/b2Math.h:108)
#1 00401462 SDL_main(argc=1, argv=0xa626c8) (C:/Documents and Settings/Emmet/My Documents/Life Of Slime/main.cpp:138)
#2 004025E7 console_main(argc=1, argv=0xa626c8) (./src/main/win32/SDL_win32_main.c:217)
#3 004027C5 WinMain(hInst=0x400000, hPrev=0x0, szCmdLine=0x241f29 "", sw=10) (./src/main/win32 /SDL_win32_main.c:353)
#4 00402044 main() (??:??)
main.c
Code:
/// Includes //////
#include <stdio.h>
#include <stdlib.h>
//#include <cmath> // currently not used
#include "Box2D.h"
#include "SDL/SDL.h"
#include "SDL/SDL_gfxPrimitives.h"
#include "Include/objects.h"
//////////////////////////////////
/// Window Parameters //////
const int WINDOW_WIDTH = 800;
const int WINDOW_HEIGHT = 480;
const char* WINDOW_TITLE = "Life Of Slime";
///////////////////////////////////////////
/// Rename for Simipiler Reference ///
SDL_Event event;
////////////////
/// Scale Meters to Pixels, for Drawing ///
float scale = 10;
////////////////
/// Set-up Object Properties ///
float Ball[3]={40,1, 1};// x-y-r
float Ground[4]={40,47, 40,1};// x-y-(1/2)w-(1/2)h
float Platform[4]={38,35, 1.5,0.5};// x-y-(1/2)w-(1/2)h
///////////////////////////////////////////////////////
/// Simulation Parameters //////
float32 timeStep = 1.0f / 60.0f;
int32 iterations = 10;
bool pause=true;
////////////////
namespace
{
Test* test;
b2World* m_world;
}
b2Vec2 ConvertScreenToWorld(int32 x, int32 y)
{
b2Vec2 p;
p.x = x/scale;
p.y = y/scale;
return p;
}
void Mouse(int32 button, int32 state, int32 x, int32 y)
{
if (button == 1)//LEFT
{
if (state == 1)//DOWN
{
b2Vec2 p = ConvertScreenToWorld(x, y);
test->MouseDown(p);
}
if (state == 0)//UP
{
test->MouseUp();
}
}
}
void MouseMotion(int32 x, int32 y)
{
b2Vec2 p = ConvertScreenToWorld(x, y);
test->MouseMove(p);
}
/*
//b2World* world;
//b2Body* ballBody;
//b2MouseJoint* mouseJoint;
void On_Mouse_Down(const b2World* world, const b2MouseJointDef* mouse_joint, const b2Body* ballBody)
{
if (ballBody) {
b2MouseJointDef* mouse_joint;
mouse_joint->body1 = world->GetGroundBody();
mouse_joint->body2 = ballBody;
mouse_joint->target.Set(event.motion.x/scale, event.motion.x/scale);
mouse_joint->maxForce = 10000;
mouse_joint->timeStep = timeStep;
b2MouseJoint* mouseJoint = (b2MouseJoint*)world->CreateJoint(mouse_joint);
}
}
void Mouse_Update(const b2MouseJoint* mouseJoint, const b2Vec2* p)
{
if (mouseJoint) {
// mouseJoint->SetTarget(p);
}
}
void On_Mouse_Up(const b2World* world, const b2MouseJoint* mouseJoint)
{
if (mouseJoint) {
world->DestroyJoint(mouseJoint);
mouseJoint = NULL;
}
}
bool L_Mouse_Down=false;
*/
int main(int argc, char **argv)
{
/// Initiate Window ///////
SDL_Init( SDL_INIT_VIDEO );
SDL_Surface* screen = SDL_SetVideoMode( WINDOW_WIDTH, WINDOW_HEIGHT, 0, SDL_HWSURFACE | SDL_DOUBLEBUF /* | SDL_FULLSCREEN */ );
SDL_WM_SetCaption( WINDOW_TITLE, 0 );
/////////////////////////////////////
/// Initiate World ///
//b2AABB worldAABB
test->m_worldAABB.lowerBound.Set(50.0f, 50.0f);
test->m_worldAABB.upperBound.Set(100.0f, 100.0f);
b2Vec2 gravity(0.0f, 9.8f);
bool doSleep = true;
test->m_world = new b2World(test->m_worldAABB, gravity, doSleep);
///////////////////////////////////////////
/// Create Ground Body [Static] ///
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(Ground[0], Ground[1]);
b2Body* groundBody = test->m_world->CreateBody(&groundBodyDef);
b2PolygonDef groundShapeDef;
groundShapeDef.SetAsBox(Ground[2], Ground[3]);
groundBody->CreateShape(&groundShapeDef);
/////////////////////////////////////////
/// Create Platform Body [Static] ///
b2BodyDef platformBodyDef;
platformBodyDef.position.Set(Platform[0], Platform[1]);
b2Body* platformBody = test->m_world->CreateBody(&platformBodyDef);
b2PolygonDef platformShapeDef;
platformShapeDef.SetAsBox(Platform[2], Platform[3]);
platformBody->CreateShape(&platformShapeDef);
/////////////////////////////////////////////
/// Create Ball Body [Dynamic] ///
b2BodyDef ballBodyDef;
ballBodyDef.position.Set(Ball[0], Ball[1]);
b2Body* ballBody = test->m_world->CreateBody(&ballBodyDef);
b2CircleDef ballShapeDef;
ballShapeDef.radius = Ball[2];
ballShapeDef.density = 1.0f;
ballShapeDef.friction = 1.0f;
ballBodyDef.linearDamping = 10000;
ballBodyDef.angularDamping = 10000;
ballShapeDef.restitution = 0.2;
ballBody->CreateShape(&ballShapeDef);
ballBody->SetMassFromShapes();
//////////////////////////////
bool gameRunning = true;
while (gameRunning)
{
/// Control Events ////////////////////////////////////////////////////////
if (SDL_PollEvent(&event)){
if (event.type == SDL_QUIT) {gameRunning = false;} // Quit Application
if ( event.type == SDL_KEYDOWN ){
if ( event.key.keysym.sym == SDLK_SPACE ) pause=!pause;
}
if(event.type == SDL_MOUSEBUTTONDOWN && SDL_BUTTON(SDL_GetMouseState(NULL,NULL)) == SDL_BUTTON_LEFT); Mouse( 1, 1, event.motion.x, event.motion.y);
if(event.type == SDL_MOUSEBUTTONUP && SDL_BUTTON(SDL_GetMouseState(NULL,NULL)) == SDL_BUTTON_LEFT); Mouse( 1, 0, event.motion.x, event.motion.y);
//if(event.type == SDL_MOUSEMOTION) test->Mouse_Update(new b2Vec2 (event.motion.x/scale, event.motion.x/scale));
}
///////////////////////////////////////////////////////////////////////////
/// Pause Simulation /////////////////////////////////////////////
if (pause==false){
test->m_world->Step(timeStep, iterations);
}
////////////////////////////////////////////////////////////////////
/// Return Ball Position and Angle, To Draw ///
b2Vec2 position = ballBody->GetPosition();
float32 angle = ballBody->GetAngle();
/////////////////////////////////////
/// Clear Screen ///
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
////
/// Draw Ground ///
boxRGBA(screen, (Ground[0]-Ground[2])*scale, (Ground[1]-Ground[3])*scale, (Ground[0]+Ground[2])*scale, (Ground[1]+Ground[3])*scale, 0, 255, 0, 255);
////
/// Draw Platform ///
boxRGBA(screen, (Platform[0]-Platform[2])*scale, (Platform[1]-Platform[3])*scale, (Platform[0]+Platform[2])*scale, (Platform[1]+Platform[3])*scale, 0, 255, 0, 255);
////
/// Draw Ball ///
filledEllipseRGBA(screen, position.x*scale, position.y*scale, Ball[2]*scale, Ball[2]*scale, 255, 255, 255, 255);
/////
SDL_Flip(screen);
}
SDL_Quit();
return 0;
}
void Test::MouseDown(const b2Vec2& p)
{
if (m_mouseJoint != NULL)
{
return;
}
// Make a small box.
b2AABB aabb;
b2Vec2 d;
d.Set(0.001f, 0.001f);
aabb.lowerBound = p - d;
aabb.upperBound = p + d;
// Query the world for overlapping shapes.
const int32 k_maxCount = 10;
b2Shape* shapes[k_maxCount];
int32 count = m_world->Query(aabb, shapes, k_maxCount);
b2Body* body = NULL;
for (int32 i = 0; i < count; ++i)
{
b2Body* shapeBody = shapes[i]->GetBody();
if (shapeBody->IsStatic() == false && shapeBody->GetMass() > 0.0f)
{
bool inside = shapes[i]->TestPoint(shapeBody->GetXForm(), p);
if (inside)
{
body = shapes[i]->GetBody();
break;
}
}
}
}
void Test::MouseUp()
{
if (m_mouseJoint)
{
m_world->DestroyJoint(m_mouseJoint);
m_mouseJoint = NULL;
}
}
void Test::MouseMove(const b2Vec2& p)
{
if (m_mouseJoint)
{
m_mouseJoint->SetTarget(p);
}
}
#include <stdio.h>
#include <stdlib.h>
//#include <cmath> // currently not used
#include "Box2D.h"
#include "SDL/SDL.h"
#include "SDL/SDL_gfxPrimitives.h"
#include "Include/objects.h"
//////////////////////////////////
/// Window Parameters //////
const int WINDOW_WIDTH = 800;
const int WINDOW_HEIGHT = 480;
const char* WINDOW_TITLE = "Life Of Slime";
///////////////////////////////////////////
/// Rename for Simipiler Reference ///
SDL_Event event;
////////////////
/// Scale Meters to Pixels, for Drawing ///
float scale = 10;
////////////////
/// Set-up Object Properties ///
float Ball[3]={40,1, 1};// x-y-r
float Ground[4]={40,47, 40,1};// x-y-(1/2)w-(1/2)h
float Platform[4]={38,35, 1.5,0.5};// x-y-(1/2)w-(1/2)h
///////////////////////////////////////////////////////
/// Simulation Parameters //////
float32 timeStep = 1.0f / 60.0f;
int32 iterations = 10;
bool pause=true;
////////////////
namespace
{
Test* test;
b2World* m_world;
}
b2Vec2 ConvertScreenToWorld(int32 x, int32 y)
{
b2Vec2 p;
p.x = x/scale;
p.y = y/scale;
return p;
}
void Mouse(int32 button, int32 state, int32 x, int32 y)
{
if (button == 1)//LEFT
{
if (state == 1)//DOWN
{
b2Vec2 p = ConvertScreenToWorld(x, y);
test->MouseDown(p);
}
if (state == 0)//UP
{
test->MouseUp();
}
}
}
void MouseMotion(int32 x, int32 y)
{
b2Vec2 p = ConvertScreenToWorld(x, y);
test->MouseMove(p);
}
/*
//b2World* world;
//b2Body* ballBody;
//b2MouseJoint* mouseJoint;
void On_Mouse_Down(const b2World* world, const b2MouseJointDef* mouse_joint, const b2Body* ballBody)
{
if (ballBody) {
b2MouseJointDef* mouse_joint;
mouse_joint->body1 = world->GetGroundBody();
mouse_joint->body2 = ballBody;
mouse_joint->target.Set(event.motion.x/scale, event.motion.x/scale);
mouse_joint->maxForce = 10000;
mouse_joint->timeStep = timeStep;
b2MouseJoint* mouseJoint = (b2MouseJoint*)world->CreateJoint(mouse_joint);
}
}
void Mouse_Update(const b2MouseJoint* mouseJoint, const b2Vec2* p)
{
if (mouseJoint) {
// mouseJoint->SetTarget(p);
}
}
void On_Mouse_Up(const b2World* world, const b2MouseJoint* mouseJoint)
{
if (mouseJoint) {
world->DestroyJoint(mouseJoint);
mouseJoint = NULL;
}
}
bool L_Mouse_Down=false;
*/
int main(int argc, char **argv)
{
/// Initiate Window ///////
SDL_Init( SDL_INIT_VIDEO );
SDL_Surface* screen = SDL_SetVideoMode( WINDOW_WIDTH, WINDOW_HEIGHT, 0, SDL_HWSURFACE | SDL_DOUBLEBUF /* | SDL_FULLSCREEN */ );
SDL_WM_SetCaption( WINDOW_TITLE, 0 );
/////////////////////////////////////
/// Initiate World ///
//b2AABB worldAABB
test->m_worldAABB.lowerBound.Set(50.0f, 50.0f);
test->m_worldAABB.upperBound.Set(100.0f, 100.0f);
b2Vec2 gravity(0.0f, 9.8f);
bool doSleep = true;
test->m_world = new b2World(test->m_worldAABB, gravity, doSleep);
///////////////////////////////////////////
/// Create Ground Body [Static] ///
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(Ground[0], Ground[1]);
b2Body* groundBody = test->m_world->CreateBody(&groundBodyDef);
b2PolygonDef groundShapeDef;
groundShapeDef.SetAsBox(Ground[2], Ground[3]);
groundBody->CreateShape(&groundShapeDef);
/////////////////////////////////////////
/// Create Platform Body [Static] ///
b2BodyDef platformBodyDef;
platformBodyDef.position.Set(Platform[0], Platform[1]);
b2Body* platformBody = test->m_world->CreateBody(&platformBodyDef);
b2PolygonDef platformShapeDef;
platformShapeDef.SetAsBox(Platform[2], Platform[3]);
platformBody->CreateShape(&platformShapeDef);
/////////////////////////////////////////////
/// Create Ball Body [Dynamic] ///
b2BodyDef ballBodyDef;
ballBodyDef.position.Set(Ball[0], Ball[1]);
b2Body* ballBody = test->m_world->CreateBody(&ballBodyDef);
b2CircleDef ballShapeDef;
ballShapeDef.radius = Ball[2];
ballShapeDef.density = 1.0f;
ballShapeDef.friction = 1.0f;
ballBodyDef.linearDamping = 10000;
ballBodyDef.angularDamping = 10000;
ballShapeDef.restitution = 0.2;
ballBody->CreateShape(&ballShapeDef);
ballBody->SetMassFromShapes();
//////////////////////////////
bool gameRunning = true;
while (gameRunning)
{
/// Control Events ////////////////////////////////////////////////////////
if (SDL_PollEvent(&event)){
if (event.type == SDL_QUIT) {gameRunning = false;} // Quit Application
if ( event.type == SDL_KEYDOWN ){
if ( event.key.keysym.sym == SDLK_SPACE ) pause=!pause;
}
if(event.type == SDL_MOUSEBUTTONDOWN && SDL_BUTTON(SDL_GetMouseState(NULL,NULL)) == SDL_BUTTON_LEFT); Mouse( 1, 1, event.motion.x, event.motion.y);
if(event.type == SDL_MOUSEBUTTONUP && SDL_BUTTON(SDL_GetMouseState(NULL,NULL)) == SDL_BUTTON_LEFT); Mouse( 1, 0, event.motion.x, event.motion.y);
//if(event.type == SDL_MOUSEMOTION) test->Mouse_Update(new b2Vec2 (event.motion.x/scale, event.motion.x/scale));
}
///////////////////////////////////////////////////////////////////////////
/// Pause Simulation /////////////////////////////////////////////
if (pause==false){
test->m_world->Step(timeStep, iterations);
}
////////////////////////////////////////////////////////////////////
/// Return Ball Position and Angle, To Draw ///
b2Vec2 position = ballBody->GetPosition();
float32 angle = ballBody->GetAngle();
/////////////////////////////////////
/// Clear Screen ///
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
////
/// Draw Ground ///
boxRGBA(screen, (Ground[0]-Ground[2])*scale, (Ground[1]-Ground[3])*scale, (Ground[0]+Ground[2])*scale, (Ground[1]+Ground[3])*scale, 0, 255, 0, 255);
////
/// Draw Platform ///
boxRGBA(screen, (Platform[0]-Platform[2])*scale, (Platform[1]-Platform[3])*scale, (Platform[0]+Platform[2])*scale, (Platform[1]+Platform[3])*scale, 0, 255, 0, 255);
////
/// Draw Ball ///
filledEllipseRGBA(screen, position.x*scale, position.y*scale, Ball[2]*scale, Ball[2]*scale, 255, 255, 255, 255);
/////
SDL_Flip(screen);
}
SDL_Quit();
return 0;
}
void Test::MouseDown(const b2Vec2& p)
{
if (m_mouseJoint != NULL)
{
return;
}
// Make a small box.
b2AABB aabb;
b2Vec2 d;
d.Set(0.001f, 0.001f);
aabb.lowerBound = p - d;
aabb.upperBound = p + d;
// Query the world for overlapping shapes.
const int32 k_maxCount = 10;
b2Shape* shapes[k_maxCount];
int32 count = m_world->Query(aabb, shapes, k_maxCount);
b2Body* body = NULL;
for (int32 i = 0; i < count; ++i)
{
b2Body* shapeBody = shapes[i]->GetBody();
if (shapeBody->IsStatic() == false && shapeBody->GetMass() > 0.0f)
{
bool inside = shapes[i]->TestPoint(shapeBody->GetXForm(), p);
if (inside)
{
body = shapes[i]->GetBody();
break;
}
}
}
}
void Test::MouseUp()
{
if (m_mouseJoint)
{
m_world->DestroyJoint(m_mouseJoint);
m_mouseJoint = NULL;
}
}
void Test::MouseMove(const b2Vec2& p)
{
if (m_mouseJoint)
{
m_mouseJoint->SetTarget(p);
}
}
objects.h
Code:
#ifndef OBJECTS_H
#define OBJECTS_H
class Test;
class Test
{
public:
Test();
virtual ~Test();
void MouseDown(const b2Vec2& p);
void MouseUp();
void MouseMove(const b2Vec2& p);
b2AABB m_worldAABB;
b2World* m_world;
b2MouseJoint* m_mouseJoint;
};
#endif
#define OBJECTS_H
class Test;
class Test
{
public:
Test();
virtual ~Test();
void MouseDown(const b2Vec2& p);
void MouseUp();
void MouseMove(const b2Vec2& p);
b2AABB m_worldAABB;
b2World* m_world;
b2MouseJoint* m_mouseJoint;
};
#endif
thanks