I'm trying to write a wrapper for Bullet physics for implementing into my game framework.
I have 3 classes, mDebugDraw is an implementation of the bullet debug drawing.
mRigidBody is a container for bullet's rigid body stuff.
World is a container for bullet's world stuff.
I have ~100 errors in visual studio, and almost all of them are coming from where I'm trying to create mRigidBodies, the errors are "cannot convert from initializer list to mRigidBody", "no appropriate constructor available", as well as weird ones like "mRigidBody::mRigidBody(std::string) member function is already defined or declared", which isn't a function I have implemented.
world.h contains the definitions for those three classes:
#pragma once
#include <btBulletDynamicsCommon.h>
#include <BulletCollision\CollisionShapes\btBoxShape.h>
#include <GL/glew.h>
#include "LinearMath\btIDebugDraw.h"
#include <vector>
#include <glm\vec3.hpp>
#include <iostream>
#include <map>
class mDebugDraw : public btIDebugDraw
{
private:
int debugMode;
public:
mDebugDraw();
virtual ~mDebugDraw();
struct mLine
{
glm::vec3 from;
glm::vec3 to;
glm::vec3 color;
mLine(const glm::vec3 ifrom, const glm::vec3 ito, glm::vec3 _color)
{
from = ifrom;
to = ito;
color = _color;
}
};
std::vector<mLine> lines;
struct mColor
{
glm::vec3 col;
mColor(const glm::vec3 c)
{
col = c;
}
};
std::vector<mColor> colors;
GLuint vao;
GLuint vbo[2];
virtual void drawLine(const btVector3& from, const btVector3& to, const btVector3& color);
virtual void drawContactPoint(const btVector3& PointOnB, const btVector3& normalOnB, btScalar distance, int lifeTime, const btVector3& color);
virtual void draw3dText(const btVector3& location, const char* textString);
virtual void setDebugMode(int m_debugMode);
virtual int getDebugMode() const;
virtual void drawTriangle(const btVector3 & a, const btVector3 & b, const btVector3 & c, const btVector3 & color, btScalar alpha) {}
void reportErrorWarning(const char * warningString) { std::cout << "Physics debugger warning: " << warningString << std::endl; }
std::vector<mLine> & GetLines() { return lines; }
void draw();
void clean();
};
class mRigidBody
{
public:
mRigidBody(std::string name, World::shapeTypes type, glm::vec3 extent, glm::vec3 startposition);
mRigidBody(std::string name, World::shapeTypes type, glm::vec3 extent, glm::vec3 startPosition, float mass, float friction, float restitution);
void setPosition(glm::vec3 _position);
void setMass(float _mass);
void setRestitution(float _restitution);
void setFriction(float _friction);
std::string getName() const { return name; }
btCollisionShape* getShape() { return mShape; }
btRigidBody* getBody() { return rigidBody; }
int getIndex() const { return index; }
private:
btCollisionShape* mShape;
btRigidBody* rigidBody;
std::string name;
int index;
//btDefaultMotionState * mMotionState;
};
class World
{
protected:
World();
public:
enum shapeTypes
{
sphere,
cube,
capsule
};
static World * gameWorld();
void init();
btDiscreteDynamicsWorld* physicsWorld;
std::vector<btBoxShape> hitboxes;
mDebugDraw debugDrawer;
void drawWireframe();
mRigidBody* getRigidBody(std::string name) const;
void addRigidBody(mRigidBody* _body, std::string _name);
std::map<std::string, mRigidBody *> getMap() { return mRigidBodies; }
private:
static World *mInstance;
std::map<std::string, mRigidBody *> mRigidBodies;
};
the majority of the errors come from these two lines in world.h, where I'm defining the two constructors.
mRigidBody(std::string name, World::shapeTypes type, glm::vec3 extent, glm::vec3 startposition);
mRigidBody(std::string name, World::shapeTypes type, glm::vec3 extent, glm::vec3 startPosition, float mass, float friction, float restitution);
Here's the full list of errors.
1> main.cpp
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody'
1> World.cpp
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody'
1>c:\repo\bustle\src\world.cpp(52): error C2511: 'mRigidBody::mRigidBody(std::string,World::shapeTypes,glm::vec3,glm::vec3)': overloaded member function not found in 'mRigidBody'
1> c:\repo\bustle\include\world.h(73): note: see declaration of 'mRigidBody'
1>c:\repo\bustle\src\world.cpp(62): error C2597: illegal reference to non-static member 'mRigidBody::mShape'
1>c:\repo\bustle\src\world.cpp(65): warning C4244: 'argument': conversion from 'glm::tvec3<float,0>::length_type' to 'btScalar', possible loss of data
1>c:\repo\bustle\src\world.cpp(65): error C2597: illegal reference to non-static member 'mRigidBody::mShape'
1>c:\repo\bustle\src\world.cpp(68): error C2597: illegal reference to non-static member 'mRigidBody::mShape'
1>c:\repo\bustle\src\world.cpp(74): error C2597: illegal reference to non-static member 'mRigidBody::mShape'
1>c:\repo\bustle\src\world.cpp(74): error C2512: 'btRigidBody': no appropriate default constructor available
1> c:\repo\bustle\bullet\src\bulletdynamics\vehicle\btwheelinfo.h(17): note: see declaration of 'btRigidBody'
1>c:\repo\bustle\src\world.cpp(76): error C2671: 'mRigidBody::{ctor}': static member functions do not have 'this' pointers
1>c:\repo\bustle\src\world.cpp(79): error C2511: 'mRigidBody::mRigidBody(std::string,World::shapeTypes,glm::vec3,glm::vec3,float,float,float)': overloaded member function not found in 'mRigidBody'
1> c:\repo\bustle\include\world.h(73): note: see declaration of 'mRigidBody'
1>c:\repo\bustle\src\world.cpp(80): error C2597: illegal reference to non-static member 'mRigidBody::name'
1>c:\repo\bustle\src\world.cpp(91): error C2597: illegal reference to non-static member 'mRigidBody::mShape'
1>c:\repo\bustle\src\world.cpp(94): warning C4244: 'argument': conversion from 'glm::tvec3<float,0>::length_type' to 'btScalar', possible loss of data
1>c:\repo\bustle\src\world.cpp(94): error C2597: illegal reference to non-static member 'mRigidBody::mShape'
1>c:\repo\bustle\src\world.cpp(97): error C2597: illegal reference to non-static member 'mRigidBody::mShape'
1>c:\repo\bustle\src\world.cpp(104): error C2227: left of '->calculateLocalInertia' must point to class/struct/union/generic type
1>c:\repo\bustle\src\world.cpp(106): error C2597: illegal reference to non-static member 'mRigidBody::mShape'
1>c:\repo\bustle\src\world.cpp(107): error C2671: 'mRigidBody::{ctor}': static member functions do not have 'this' pointers
1>c:\repo\bustle\src\world.cpp(107): error C2227: left of '->rigidBody' must point to class/struct/union/generic type
1>c:\repo\bustle\src\world.cpp(108): error C2671: 'mRigidBody::{ctor}': static member functions do not have 'this' pointers
1>c:\repo\bustle\src\world.cpp(108): error C2597: illegal reference to non-static member 'mRigidBody::name'
1> State_Tutorial.cpp
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody'
1> State_MainMenu.cpp
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody'
1> State_Loading.cpp
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody'
1> State_Gameplay.cpp
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody'
1> State_EndRound.cpp
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody'
1>c:\repo\bustle\src\state_endround.cpp(530): warning C4018: '<': signed/unsigned mismatch
1> State_BulletTest.cpp
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody'
1>c:\repo\bustle\src\state_bullettest.cpp(18): error C2440: '<function-style-cast>': cannot convert from 'initializer list' to 'mRigidBody'
1> c:\repo\bustle\src\state_bullettest.cpp(18): note: No constructor could take the source type, or constructor overload resolution was ambiguous
1>c:\repo\bustle\src\state_bullettest.cpp(18): error C2512: 'mRigidBody': no appropriate default constructor available
1> c:\repo\bustle\include\world.h(73): note: see declaration of 'mRigidBody'
1>c:\repo\bustle\src\state_bullettest.cpp(19): error C2440: '<function-style-cast>': cannot convert from 'initializer list' to 'mRigidBody'
1> c:\repo\bustle\src\state_bullettest.cpp(19): note: No constructor could take the source type, or constructor overload resolution was ambiguous
1>c:\repo\bustle\src\state_bullettest.cpp(19): error C2512: 'mRigidBody': no appropriate default constructor available
1> c:\repo\bustle\include\world.h(73): note: see declaration of 'mRigidBody'
1> Sprite.cpp
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody'
1>c:\repo\bustle\src\sprite.cpp(167): warning C4018: '>': signed/unsigned mismatch
1> Player.cpp
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody'
1> Passenger.cpp
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody'
1> Kinematic.cpp
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody'
1> GameObject.cpp
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody'
1> GameManager.cpp
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody'
1>c:\repo\bustle\src\gamemanager.cpp(49): warning C4316: 'State_BulletTest': object allocated on the heap may not be aligned 16
1> DisplayHandler.cpp
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody'
1> DebugManager.cpp
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody'
1> CollisionBoxes.cpp
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody'
1> Collision.cpp
1>c:\repo\bustle\include\world.h(75): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(75): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2653: 'World': is not a class or namespace name
1>c:\repo\bustle\include\world.h(76): error C2061: syntax error: identifier 'shapeTypes'
1>c:\repo\bustle\include\world.h(76): error C2535: 'mRigidBody::mRigidBody(std::string)': member function already defined or declared
1> c:\repo\bustle\include\world.h(75): note: see declaration of 'mRigidBody::mRigidBody'
1>c:\repo\bustle\src\collision.cpp(158): warning C4018: '<': signed/unsigned mismatch
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Thanks in advance for any help, I've been struggling with this for a day now.
World
is used before it's declared. In the definition of mRigidBody
's constructors you refer to World::shapeTypes
but World
is only defined later in the file. Try placing the definition of World
before mRigidBody
. You may need to forward declare mRigidBody
before defining World
.