Hello Box2D forums,
I've been pulling my hair out trying to figure out why this class variable isn't changing.
Here's the class header. The function in question is startContact(). The cout command is working fine, but Contacting refuses to change to true.
startContact is called through a MyContactListener class. It calls the function fine, but I can't figure out why the cout runs but the Contacting variable doesn't change.
Here's is the function that calls startContact()
Any insight? 😢
I've been pulling my hair out trying to figure out why this class variable isn't changing.
Here's the class header. The function in question is startContact(). The cout command is working fine, but Contacting refuses to change to true.
Code:
#ifndef SHELL_H
#define SHELL_H
#include <Box2D/Box2D.h>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <iostream>
class Shell{
public:
static std::vector<Shell> ShellVect;
static b2World *ShellWorld;
static void Create(double X, double Y, double Angle, b2World &World);
static void Update(sf::RenderWindow &GameWindow);
sf::Shape ShellSh;
b2BodyDef ShellDef; //define static ground body
b2Body* ShellBody;
b2CircleShape ShellHull; //define its polygon
b2FixtureDef ShellfixtureDef; //define it's fixture information (dynamic fixtures)
b2Vec2 position;
double Time;
bool Contacting;
Shell(double X, double Y, double Angle, b2World &World);
~Shell();
void startContact(){
this->Contacting = true;
std::cout << "JJJJJJJJJJJJJJJJJJJJJJJJJ";
}
void endContact() { }
};
#endif // SHELL_H
#define SHELL_H
#include <Box2D/Box2D.h>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <iostream>
class Shell{
public:
static std::vector<Shell> ShellVect;
static b2World *ShellWorld;
static void Create(double X, double Y, double Angle, b2World &World);
static void Update(sf::RenderWindow &GameWindow);
sf::Shape ShellSh;
b2BodyDef ShellDef; //define static ground body
b2Body* ShellBody;
b2CircleShape ShellHull; //define its polygon
b2FixtureDef ShellfixtureDef; //define it's fixture information (dynamic fixtures)
b2Vec2 position;
double Time;
bool Contacting;
Shell(double X, double Y, double Angle, b2World &World);
~Shell();
void startContact(){
this->Contacting = true;
std::cout << "JJJJJJJJJJJJJJJJJJJJJJJJJ";
}
void endContact() { }
};
#endif // SHELL_H
startContact is called through a MyContactListener class. It calls the function fine, but I can't figure out why the cout runs but the Contacting variable doesn't change.
Here's is the function that calls startContact()
Code:
void MyContactListener::BeginContact(b2Contact* contact) {
//check if fixture A was a Shell
void* bodyUserData = contact->GetFixtureA()->GetBody()->GetUserData();
if ( bodyUserData ){
static_cast<Shell*>( bodyUserData )->startContact();
}
//check if fixture B was a Shell
bodyUserData = contact->GetFixtureB()->GetBody()->GetUserData();
if ( bodyUserData ){
static_cast<Shell*>( bodyUserData )->startContact();
}
}
//check if fixture A was a Shell
void* bodyUserData = contact->GetFixtureA()->GetBody()->GetUserData();
if ( bodyUserData ){
static_cast<Shell*>( bodyUserData )->startContact();
}
//check if fixture B was a Shell
bodyUserData = contact->GetFixtureB()->GetBody()->GetUserData();
if ( bodyUserData ){
static_cast<Shell*>( bodyUserData )->startContact();
}
}
Any insight? 😢