Jump to content
  • Advertisement
Sign in to follow this  
AoS

Expected Declaration

This topic is 2491 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have the below code. Microsoft Visual C++ Express 2010 keeps telling me It expects a declaration at all the if(!sceneDesc.cpuDispatcher) statements. I can't understand what is wrong. Could it be that the variable is not declared? That was all google turned up.


#include "PxPhysicsAPI.h"
#include "PxDefaultAllocator.h"
#include "PxDefaultErrorCallback.h"
#include "PxTolerancesScale.h"
#include "PxDefaultSimulationFilterShader.h"

using namespace physx;

bool recordMemoryAllocations = true;

static PxDefaultErrorCallback gDefaultErrorCallback;
static PxDefaultAllocator gDefaultAllocatorCallback;
static PxSimulationFilterShader gDefaultFilterShader=PxDefaultSimulationFilterShader;

PxPhysics *mPhysicsSDK = PxCreatePhysics(PX_PHYSICS_VERSION, gDefaultAllocatorCallback, gDefaultErrorCallback, PxTolerancesScale(), recordMemoryAllocations );

PxCooking *mCooking = PxCreateCooking(PX_PHYSICS_VERSION, &mPhysicsSDK->getFoundation(), PxCookingParams());

PxSceneDesc sceneDesc(mPhysicsSDK->getTolerancesScale());

PxScene *mScene = mPhysicsSDK->createScene(sceneDesc);

if(!sceneDesc.cpuDispatcher) {
mCpuDispatcher = PxDefaultCpuDispatcherCreate(mNbThreads);
if(!mCpuDispatcher)
fatalError("PxDefaultCpuDispatcherCreate failed!");
sceneDesc.cpuDispatcher = mCpuDispatcher;
}
if(!sceneDesc.filterShader)
sceneDesc.filterShader = &gDefaultFilterShader;

#ifdef PX_WINDOWS
if(!sceneDesc.gpuDispatcher && mCudaContextManager)
{
sceneDesc.gpuDispatcher = mCudaContextManager->getGpuDispatcher();
}
#endif

if (!mScene)
fatalError("createScene failed!");
PxMaterial* mMaterial;

mMaterial = mPhysicsSDK->createMaterial(0.5f, 0.5f, 0.1f); //static friction, dynamic friction, restitution
if(!mMaterial)
PxReal d = 0.0f;
PxU32 axis = 1;
PxTransform pose;

if(axis == 0)
pose = PxTransform(PxVec3(d, 0.0f, 0.0f));
else if(axis == 1)
pose = PxTransform(PxVec3(0.0f, d, 0.0f),PxQuat(PxHalfPi, PxVec3(0.0f, 0.0f, 1.0f)));
else if(axis == 2)
pose = PxTransform(PxVec3(0.0f, 0.0f, d), PxQuat(-PxHalfPi, PxVec3(0.0f, 1.0f, 0.0f)));

PxRigidStatic* plane = mPhysicsSDK->createRigidStatic(pose);
if (!plane)
fatalError("create plane failed!");
PxShape* shape = plane->createShape(PxPlaneGeometry(), *mMaterial);
if (!shape)
fatalError("create shape failed!");
mScene->addActor(*plane);
PxReal density = 1.0f;
PxTransform(PxVec3(0.0f, 5.0f, 0.0f), PxQuat::createIdentity());
PxVec3 dimensions(1.0f, 1.0f, 1.0f);
PxBoxGeometry geometry(dimensions);

PxRigidDynamic *actor = PxCreateDynamic(*mPhysicsSDK, transform, geometry, *mMaterial, density);
if (!actor)
fatalError("create actor failed!");
mScene->addActor(*actor);
mAccumulator = 0.0f;
mStepSize = 1.0f / 60.0f;

virtual bool advance(PxReal dt)
{
mAccumulator += dt;
if(mAccumulator < mStepSize)
return false;

mAccumulator -= mStepSize;

mScene->simulate(mStepSize);
return true;
}
PxTransform newPose = PxShapeExt::getGlobalPose(*mPhysicsShape);
mScene->fetchResults(true);
mPhysicsSDK->release();

Share this post


Link to post
Share on other sites
Advertisement
You can't have free-floating if statements like that. They need to be in a function, along with most of the rest of that code. You also have a free function marked 'virtual'. It needs to be in a class. Whatever you're trying to do, you need to slow down and learn to use C++ first.

Share this post


Link to post
Share on other sites
That was how the code was written. I didn't write it. But that does explain some stuff.

Share this post


Link to post
Share on other sites
Okay so I cleared out a bunch of errors. Basically my only problem now is that I get several undeclared identifier errors and I don't know what headers I need to include to fix it.
1>c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(227): error C2065: 'mNbThreads' : undeclared identifier
1>c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(229): error C3861: 'fatalError': identifier not found
1>c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(236): error C2065: 'mCudaContextManager' : undeclared identifier
1>c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(238): error C2065: 'mCudaContextManager' : undeclared identifier
1>c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(238): error C2227: left of '->getGpuDispatcher' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(243): error C3861: 'fatalError': identifier not found
1>c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(253): error C2065: 'd' : undeclared identifier
1>c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(255): error C2065: 'd' : undeclared identifier
1>c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(257): error C2065: 'd' : undeclared identifier
1>c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(261): error C3861: 'fatalError': identifier not found
1>c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(264): error C3861: 'fatalError': identifier not found
1>c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(271): error C2065: 'transform' : undeclared identifier
1>c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(273): error C3861: 'fatalError': identifier not found
1>c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(275): error C2065: 'mAccumulator' : undeclared identifier
1>c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(276): error C2065: 'mStepSize' : undeclared identifier
1>c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(279): error C2575: 'advance' : only member functions and bases can be virtual
1>c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(279): error C2601: 'advance' : local function definitions are illegal
1> c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(214): this line contains a '{' which has not yet been matched
1>c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(289): error C2065: 'mPhysicsShape' : undeclared identifier
1>c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(280): error C2065: 'mAccumulator' : undeclared identifier
1>c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(281): error C2065: 'mAccumulator' : undeclared identifier
1>c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(281): error C2065: 'mStepSize' : undeclared identifier
1>c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(284): error C2065: 'mAccumulator' : undeclared identifier
1>c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(284): error C2065: 'mStepSize' : undeclared identifier
1>c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(286): error C2065: 'mScene' : undeclared identifier
1>c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(286): error C2227: left of '->simulate' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\users\matt\documents\visual studio 2010\projects\nvphysx\nvphysx\nvphysx.cpp(286): error C2065: 'mStepSize' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Share this post


Link to post
Share on other sites
Can you post the updated code? Everything starting with 'm' looks like a member variable, so I don't think this is just a case of including a header. Where did you find the code in the first place?

Share this post


Link to post
Share on other sites
Its basically the sample code to make a bouncing box in PhysX.
Here is the updated version:

#include "stdafx.h"
#include "NVPhysx.h"
#include "glut.h"
#include "PxPhysicsAPI.h"
#include "PxDefaultAllocator.h"
#include "PxDefaultErrorCallback.h"
#include "PxTolerancesScale.h"
#include "PxDefaultSimulationFilterShader.h"
#include "PxExtensionsAPI.h"
#include "PxDefaultCpuDispatcher.h"
#include "PxShapeExt.h"
#include "PxTask.h"


using namespace physx;

bool recordMemoryAllocations = true;

static PxDefaultErrorCallback gDefaultErrorCallback;
static PxDefaultAllocator gDefaultAllocatorCallback;
static PxSimulationFilterShader gDefaultFilterShader=PxDefaultSimulationFilterShader;

int main(){

PxPhysics *mPhysicsSDK = PxCreatePhysics(PX_PHYSICS_VERSION, gDefaultAllocatorCallback, gDefaultErrorCallback, PxTolerancesScale(), recordMemoryAllocations );

PxCooking *mCooking = PxCreateCooking(PX_PHYSICS_VERSION, &mPhysicsSDK->getFoundation(), PxCookingParams());

PxSceneDesc sceneDesc(mPhysicsSDK->getTolerancesScale());
sceneDesc.gravity=PxVec3(0.0f, -9.8f, 0.0f);
PxScene *mScene = mPhysicsSDK->createScene(sceneDesc);

PxInitExtensions(*mPhysicsSDK);

if(!sceneDesc.cpuDispatcher) {
PxDefaultCpuDispatcher* mCpuDispatcher = PxDefaultCpuDispatcherCreate(mNbThreads);
if(!mCpuDispatcher)
fatalError("PxDefaultCpuDispatcherCreate failed!");
sceneDesc.cpuDispatcher = mCpuDispatcher;
}
if(!sceneDesc.filterShader)
sceneDesc.filterShader = *gDefaultFilterShader;

#ifdef PX_WINDOWS
if(!sceneDesc.gpuDispatcher && mCudaContextManager)
{
sceneDesc.gpuDispatcher = mCudaContextManager->getGpuDispatcher();
}
#endif

if (!mScene)
fatalError("createScene failed!");
PxMaterial* mMaterial;

mMaterial = mPhysicsSDK->createMaterial(0.5f, 0.5f, 0.1f); //static friction, dynamic friction, restitution
if(!mMaterial)
PxReal d = 0.0f;
PxU32 axis = 1;
PxTransform pose;

if(axis == 0)
pose = PxTransform(PxVec3(d, 0.0f, 0.0f));
else if(axis == 1)
pose = PxTransform(PxVec3(0.0f, d, 0.0f), PxQuat(PxHalfPi, PxVec3(0.0f, 0.0f, 1.0f)));
else if(axis == 2)
pose = PxTransform(PxVec3(0.0f, 0.0f, d), PxQuat(-PxHalfPi, PxVec3(0.0f, 1.0f, 0.0f)));

PxRigidStatic* plane = mPhysicsSDK->createRigidStatic(pose);
if (!plane)
fatalError("create plane failed!");
PxShape* shape = plane->createShape(PxPlaneGeometry(), *mMaterial);
if (!shape)
fatalError("create shape failed!");
mScene->addActor(*plane);
PxReal density = 1.0f;
PxTransform(PxVec3(0.0f, 5.0f, 0.0f), PxQuat::createIdentity());
PxVec3 dimensions(1.0f, 1.0f, 1.0f);
PxBoxGeometry geometry(dimensions);

PxRigidDynamic *actor = PxCreateDynamic(*mPhysicsSDK, transform, geometry, *mMaterial, density);
if (!actor)
fatalError("create actor failed!");
mScene->addActor(*actor);
mAccumulator = 0.0f;
mStepSize = 1.0f / 60.0f;

virtual bool advance(PxReal dt)
{
mAccumulator += dt;
if(mAccumulator < mStepSize)
return false;

mAccumulator -= mStepSize;

mScene->simulate(mStepSize);
return true;
}
PxTransform newPose = PxShapeExt::getGlobalPose(*mPhysicsShape);
mScene->fetchResults(true);
mPhysicsSDK->release();
}

Share this post


Link to post
Share on other sites

Basically my only problem now is that I get several undeclared identifier errors and I don't know what headers I need to include to fix it.
[/quote]
We don't know. You could try searching for all files that contain the given identifier, looking for declarations, but I suspect you won't find them.

Where did you get this code?

Share this post


Link to post
Share on other sites
I bet he's trying to piece together some snippets of code someone put up, assuming whoever was using it knew the basics of C++. it's obvious the OP needs to go read up on C++ more and understand the proper structure of code.

I mean, I see a virtual function defined inside main(). What the hell is that?

OP, go learn how C/C++ is structured, then come back to this.

Share this post


Link to post
Share on other sites

I bet he's trying to piece together some snippets of code someone put up, assuming whoever was using it knew the basics of C++. it's obvious the OP needs to go read up on C++ more and understand the proper structure of code.

I mean, I see a virtual function defined inside main(). What the hell is that?

OP, go learn how C/C++ is structured, then come back to this.


New set of errors. I fixed the code AFAIK. Got rid of all your complaints and added the opengl stuff. Don't hate.

Okay so it looks like I may have picked windows application instead of win32 console for my project type and thats why I am getting some of these errors. Will test and get back. But if there is anything else please note it.

1>------ Build started: Project: NVPhysx, Configuration: Debug Win32 ------
1> NVPhysx.cpp
1>NVPhysx.obj : error LNK2001: unresolved external symbol "class physx::pubfnd3::PxFlags<enum physx::PxFilterFlag::Enum,unsigned short> __cdecl physx::PxDefaultSimulationFilterShader(unsigned int,struct physx::PxFilterData,unsigned int,struct physx::PxFilterData,class physx::pubfnd3::PxFlags<enum physx::PxPairFlag::Enum,unsigned short> &,void const *,unsigned int)" (?PxDefaultSimulationFilterShader@physx@@YA?AV?$PxFlags@W4Enum@PxFilterFlag@physx@@G@pubfnd3@1@IUPxFilterData@1@I0AAV?$PxFlags@W4Enum@PxPairFlag@physx@@G@31@PBXI@Z)
1>NVPhysx.obj : error LNK2019: unresolved external symbol _PxCreateDynamic referenced in function "void __cdecl InitializePhysX(void)" (?InitializePhysX@@YAXXZ)
1>NVPhysx.obj : error LNK2019: unresolved external symbol "class physx::PxDefaultCpuDispatcher * __cdecl physx::PxDefaultCpuDispatcherCreate(unsigned int,unsigned int *)" (?PxDefaultCpuDispatcherCreate@physx@@YAPAVPxDefaultCpuDispatcher@1@IPAI@Z) referenced in function "void __cdecl InitializePhysX(void)" (?InitializePhysX@@YAXXZ)
1>NVPhysx.obj : error LNK2019: unresolved external symbol __imp__PxCreateCooking referenced in function "void __cdecl InitializePhysX(void)" (?InitializePhysX@@YAXXZ)
1>NVPhysx.obj : error LNK2019: unresolved external symbol __imp__PxCreatePhysics referenced in function "void __cdecl InitializePhysX(void)" (?InitializePhysX@@YAXXZ)
1>NVPhysx.obj : error LNK2019: unresolved external symbol "public: __thiscall physx::PxDefaultErrorCallback::PxDefaultErrorCallback(void)" (??0PxDefaultErrorCallback@physx@@QAE@XZ) referenced in function "void __cdecl `dynamic initializer for 'gDefaultErrorCallback''(void)" (??__EgDefaultErrorCallback@@YAXXZ)
1>NVPhysx.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall physx::PxDefaultErrorCallback::~PxDefaultErrorCallback(void)" (??1PxDefaultErrorCallback@physx@@UAE@XZ) referenced in function "void __cdecl `dynamic atexit destructor for 'gDefaultErrorCallback''(void)" (??__FgDefaultErrorCallback@@YAXXZ)
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
1>c:\users\matt\documents\visual studio 2010\Projects\NVPhysx\Debug\NVPhysx.exe : fatal error LNK1120: 8 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


#include "stdafx.h"
#include "NVPhysx.h"
#include "glut.h"
#include "PxPhysicsAPI.h"
#include "PxDefaultAllocator.h"
#include "PxDefaultErrorCallback.h"
#include "PxTolerancesScale.h"
#include "PxDefaultSimulationFilterShader.h"
#include "PxExtensionsAPI.h"
#include "PxDefaultCpuDispatcher.h"
#include "PxShapeExt.h"
#include "PxTask.h"
#include <PxMat33.h>
#include <PxMat33Legacy.h>
#include <PxSimpleFactory.h>

using namespace physx;

const int WINDOW_WIDTH=1024, WINDOW_HEIGHT=768;

bool recordMemoryAllocations = true;
static PxPhysics *mPhysicsSDK = NULL;
static PxDefaultErrorCallback gDefaultErrorCallback;
static PxDefaultAllocator gDefaultAllocatorCallback;
static PxSimulationFilterShader gDefaultFilterShader=PxDefaultSimulationFilterShader;
PxReal mAccumulator = 0.0f;
PxReal mStepSize = 1.0f / 60.0f;
PxScene *mScene = NULL;
PxRigidActor *box;

int oldX=0, oldY=0;
float rX=15, rY=0;
float fps=0;
int startTime=0;
int totalFrames=0;
int state =1 ;
float dist=-5;

void SetOrthoForFont()
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0, WINDOW_WIDTH, 0, WINDOW_HEIGHT);
glScalef(1, -1, 1);
glTranslatef(0, -WINDOW_HEIGHT, 0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void ResetPerspectiveProjection()
{
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}

void RenderSpacedBitmapString(
int x,
int y,
int spacing,
void *font,
char *string)
{
char *c;
int x1=x;
for (c=string; *c != '\0'; c++) {
glRasterPos2i(x1,y);
glutBitmapCharacter(font, *c);
x1 = x1 + glutBitmapWidth(font,*c) + spacing;
}
}


void DrawAxes()
{

glPushMatrix();
glColor3f(0,0,1);
glPushMatrix();
glTranslatef(0,0, 0.8f);
glutSolidCone(0.0325,0.2, 4,1);
glTranslatef(0,0.0625,0.225f);
RenderSpacedBitmapString(0,0,0,GLUT_BITMAP_HELVETICA_10, "Z");
glPopMatrix();
glutSolidCone(0.0225,1, 4,1);

glColor3f(1,0,0);
glRotatef(90,0,1,0);
glPushMatrix();
glTranslatef(0,0,0.8f);
glutSolidCone(0.0325,0.2, 4,1);
glTranslatef(0,0.0625,0.225f);
RenderSpacedBitmapString(0,0,0,GLUT_BITMAP_HELVETICA_10, "X");
glPopMatrix();
glutSolidCone(0.0225,1, 4,1);

glColor3f(0,1,0);
glRotatef(90,-1,0,0);
glPushMatrix();
glTranslatef(0,0, 0.8f);
glutSolidCone(0.0325,0.2, 4,1);
glTranslatef(0,0.0625,0.225f);
RenderSpacedBitmapString(0,0,0,GLUT_BITMAP_HELVETICA_10, "Y");
glPopMatrix();
glutSolidCone(0.0225,1, 4,1);
glPopMatrix();
}
void DrawGrid(int GRID_SIZE)
{
glBegin(GL_LINES);
glColor3f(0.75f, 0.75f, 0.75f);
for(int i=-GRID_SIZE;i<=GRID_SIZE;i++)
{
glVertex3f((float)i,0,(float)-GRID_SIZE);
glVertex3f((float)i,0,(float)GRID_SIZE);

glVertex3f((float)-GRID_SIZE,0,(float)i);
glVertex3f((float)GRID_SIZE,0,(float)i);
}
glEnd();
}

void StepPhysX() {
mScene->simulate(mStepSize);
}

void InitializePhysX() {
PxPhysics *mPhysicsSDK = PxCreatePhysics(PX_PHYSICS_VERSION, gDefaultAllocatorCallback, gDefaultErrorCallback, PxTolerancesScale(), recordMemoryAllocations );
PxCooking *mCooking = PxCreateCooking(PX_PHYSICS_VERSION, &mPhysicsSDK->getFoundation(), PxCookingParams());
PxSceneDesc sceneDesc(mPhysicsSDK->getTolerancesScale());
sceneDesc.gravity=PxVec3(0.0f, -9.8f, 0.0f);
mScene = mPhysicsSDK->createScene(sceneDesc);
static int mNbThreads = 1;
if(!sceneDesc.cpuDispatcher) {
PxDefaultCpuDispatcher* mCpuDispatcher = PxDefaultCpuDispatcherCreate(mNbThreads);
sceneDesc.cpuDispatcher = mCpuDispatcher;
}
if(!sceneDesc.filterShader)
sceneDesc.filterShader = *gDefaultFilterShader;
PxMaterial *mMaterial;
mMaterial = mPhysicsSDK->createMaterial(0.5f, 0.5f, 0.1f); //static friction, dynamic friction, restitution
PxReal d = 0.0f;
PxU32 axis = 1;
PxTransform pose;
if(!mMaterial)
if(axis == 0)
pose = PxTransform(PxVec3(d, 0.0f, 0.0f));
else if(axis == 1)
pose = PxTransform(PxVec3(0.0f, d, 0.0f), PxQuat(PxHalfPi, PxVec3(0.0f, 0.0f, 1.0f)));
else if(axis == 2)
pose = PxTransform(PxVec3(0.0f, 0.0f, d), PxQuat(-PxHalfPi, PxVec3(0.0f, 1.0f, 0.0f)));
PxRigidStatic *plane = mPhysicsSDK->createRigidStatic(pose);
PxShape *mPhysicsShape = plane->createShape(PxPlaneGeometry(), *mMaterial);
mScene->addActor(*plane);
PxReal density = 1.0f;
PxTransform(PxVec3(0.0f, 5.0f, 0.0f), PxQuat::createIdentity());
PxVec3 dimensions(1.0f, 1.0f, 1.0f);
PxBoxGeometry geometry(dimensions);
PxRigidDynamic *actor = PxCreateDynamic(*mPhysicsSDK, PxTransform(PxVec3(0.0f, 0.0f, 0.0f)), geometry, *mMaterial, density);
mScene->addActor(*actor);
box=actor;
}

void getColumnMajor(PxMat33 m, PxVec3 t, float* mat) {
mat[0] = m.column0[0];
mat[1] = m.column0[1];
mat[2] = m.column0[2];
mat[3] = 0;

mat[4] = m.column1[0];
mat[5] = m.column1[1];
mat[6] = m.column1[2];
mat[7] = 0;

mat[8] = m.column2[0];
mat[9] = m.column2[1];
mat[10] = m.column2[2];
mat[11] = 0;

mat[12] = t[0];
mat[13] = t[1];
mat[14] = t[2];
mat[15] = 1;
}

void DrawBox(PxShape *mPhysicsShape) {
PxTransform newPose = PxShapeExt::getGlobalPose(*mPhysicsShape);
PxBoxGeometry bg;
mPhysicsShape->getBoxGeometry(bg);
PxMat33 m = PxMat33(newPose.q);
float mat[16];
getColumnMajor(m, newPose.p, mat);
glPushMatrix();
glMultMatrixf(mat);
glutSolidCube(bg.halfExtents.x*2);
glPopMatrix();
}

void DrawShape(PxShape *mPhysicsShape)
{
PxGeometryType::Enum type = mPhysicsShape->getGeometryType();
switch(type)
{
case PxGeometryType::eBOX:
DrawBox(mPhysicsShape);
break;
}
}

void DrawActor(PxRigidActor* actor)
{
PxU32 nShapes = actor->getNbShapes();
PxShape** shapes=new PxShape*[nShapes];

actor->getShapes(shapes, nShapes);
while (nShapes--)
{
DrawShape(shapes[nShapes]);
}
delete [] shapes;
}

void RenderActors()
{
DrawActor(box);
}

void ShutdownPhysX() {
mScene->removeActor(*box);
mScene->release();
box->release();
mPhysicsSDK->release();
}

void InitGL() {
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

GLfloat ambient[4]={0.25f,0.25f,0.25f,0.25f};
GLfloat diffuse[4]={1,1,1,1};
GLfloat mat_diffuse[4]={0.85f,0,0,0};

glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_diffuse);

glDisable(GL_LIGHTING);
}

void OnReshape(int nw, int nh) {
glViewport(0,0,nw, nh);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (GLfloat)nw / (GLfloat)nh, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
}

char buffer[MAX_PATH];
void OnRender() {
//Calculate fps
totalFrames++;
int current = glutGet(GLUT_ELAPSED_TIME);
if((current-startTime)>1000)
{
float elapsedTime = float(current-startTime);
fps = ((totalFrames * 1000.0f)/ elapsedTime) ;
startTime = current;
totalFrames=0;
}

sprintf_s(buffer, "FPS: %3.2f",fps);
if (mScene)
{
StepPhysX();
}


glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0,0,dist);
glRotatef(rX,1,0,0);
glRotatef(rY,0,1,0);

DrawAxes();
DrawGrid(10);

glEnable(GL_LIGHTING);
RenderActors();
glDisable(GL_LIGHTING);

SetOrthoForFont();
glColor3f(1,1,1);
RenderSpacedBitmapString(20,20,0,GLUT_BITMAP_HELVETICA_12,buffer);

ResetPerspectiveProjection();

glutSwapBuffers();
}

void OnShutdown() {
ShutdownPhysX();
}


void Mouse(int button, int s, int x, int y)
{
if (s == GLUT_DOWN)
{
oldX = x;
oldY = y;
}

if(button == GLUT_MIDDLE_BUTTON)
state = 0;
else
state = 1;
}

void Motion(int x, int y)
{
if (state == 0)
dist *= (1 + (y - oldY)/60.0f);
else
{
rY += (x - oldX)/5.0f;
rX += (y - oldY)/5.0f;
}
oldX = x;
oldY = y;

glutPostRedisplay();
}

void OnIdle() {
glutPostRedisplay();
}

void main(int argc, char** argv) {
atexit(OnShutdown);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
glutCreateWindow("GLUT PhysX3 Demo - Simple Box");

glutDisplayFunc(OnRender);
glutIdleFunc(OnIdle);
glutReshapeFunc(OnReshape);

glutMouseFunc(Mouse);
glutMotionFunc(Motion);
InitGL();
InitializePhysX();

glutMainLoop();
}

Share this post


Link to post
Share on other sites
All apart from the last error are because you're not linking to various PhysX libraries. I don't know what ones exactly, but the tutorial you're using or the documentation will tell you which library to link to.

The last error is because you've created a Win32 project but you don't have a WinMain function. Either create a console application and use main(), or use WinMain() (Whichever the tutorial / sample code you're following does).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!