Raycasting with Irrbullet

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
eejin
Posts: 97
Joined: Sun Jul 24, 2011 11:50 am

Re: Raycasting with Irrbullet

Post by eejin »

zerochen wrote:hi,

bullet obj deactivate after a few seconds so you must active them explicit or disable the deactivation

eg

Code: Select all

 
body->setActivationState(EAS_DISABLE_DEACTIVATION)
 
Thanks it works :D. Now how would I get a cilinder as a collisionshape ?
zerochen
Posts: 273
Joined: Wed Jan 07, 2009 1:17 am
Location: Germany

Re: Raycasting with Irrbullet

Post by zerochen »

it is not so hard to implement one yourself

here is a example of my createShape function (note: functionnames dont match to irrBullet)

Code: Select all

void CCylinderShape::createShape()
{
    node->updateAbsolutePosition();
 
    const core::vector3df& extent = node->getBoundingBox().getExtent();
 
    shape = new btCylinderShape(irrlichtToBulletVector(extent * 0.5));
 
    shape->setLocalScaling(irrlichtToBulletVector(node->getScale()));
    calculateLocalInertia(mass, core::vector3df(0.0f,0.0f,0.0f));
}
eejin
Posts: 97
Joined: Sun Jul 24, 2011 11:50 am

Re: Raycasting with Irrbullet

Post by eejin »

Im not quite sure how to implement this. Could you maybe point me in the right direction :D?
Also is there a function in irrbullet to lock rotations on certain axis?
zerochen
Posts: 273
Joined: Wed Jan 07, 2009 1:17 am
Location: Germany

Re: Raycasting with Irrbullet

Post by zerochen »

have a look at boxshape.h/.cpp
you have to to copy these files, rename it and replace the createShape function.

allow Y rotation:

Code: Select all

   
rigidBody->setAngularFactor(vector3df(0,1,0));
 
eejin
Posts: 97
Joined: Sun Jul 24, 2011 11:50 am

Re: Raycasting with Irrbullet

Post by eejin »

Mhmm I get these errors:

Code: Select all

C:\Users\Person\Documents\Irrlicht\irrlicht-1.7.2\examples\01.HelloWorld\main.cpp||In function 'int main()':|
C:\Users\Person\Documents\Irrlicht\irrlicht-1.7.2\examples\01.HelloWorld\main.cpp|54|error: expected type-specifier before 'CCylinderShape'|
C:\Users\Person\Documents\Irrlicht\irrlicht-1.7.2\examples\01.HelloWorld\main.cpp|54|error: cannot convert 'int*' to 'ICollisionShape*' in initialization|
C:\Users\Person\Documents\Irrlicht\irrlicht-1.7.2\examples\01.HelloWorld\main.cpp|54|error: expected ',' or ';' before 'CCylinderShape'|
||=== Build finished: 3 errors, 3 warnings ===|
With
cylindershape.cpp

Code: Select all

#include <ISceneNode.h>
#include "Bullet/btBulletDynamicsCommon.h"
#include "Bullet/btBulletCollisionCommon.h"
#include "cylindershape.h"
 
using namespace irr;
using namespace core;
using namespace scene;
 
CCylinderShape::CCylinderShape(ISceneNode* const n, f32 m, bool overrideMargin)
{
    node = n;
    mass = m;
 
    type = ECST_BOX;
 
    createShape(overrideMargin);
}
 
 
void CCylinderShape::createShape()
{
    node->updateAbsolutePosition();
 
    const vector3df& extent = node->getBoundingBox().getExtent();
 
    shape = new btCylinderShape(irrlichtToBulletVector(extent * 0.5));
 
    setLocalScaling(node->getScale(), ESP_COLLISIONSHAPE);
    calculateLocalInertia(mass, vector3df(0.0f,0.0f,0.0f));
}
 
CCylinderShape::~CCylinderShape()
{
}
 
and cylindershape.h

Code: Select all

// Copyright (C) 2009-2011 Josiah Hartzell (Skyreign Software)
// This file is part of the "irrBullet" Bullet physics extension library and wrapper.
// For conditions of distribution and use, see license in irrbullet.h
// The above copyright notice and its accompanying information must remain here.
 
#ifndef __CYLINDER_SHAPE_H_INCLUDED__
#define __CYLINDER_SHAPE_H_INCLUDED__
 
#include "collisionshape.h"
 
 
class CCylinderShape : public ICollisionShape
{
public:
    CCylinderShape(irr::scene::ISceneNode* const n, irr::f32 m, bool overrideMargin = false);
 
    virtual ~CCylinderShape();
 
protected:
    void createShape(bool overrideMargin);
};
 
 
#endif // __CYLINDER_SHAPE_H_INCLUDED__
 
 
And I call it like this:

Code: Select all

       ICollisionShape *playershape = new CCylinderShape(player, 1, false);
When I replace CCylinderShape with IBoxShape it compiles and works but as a box shape ofcourse.

And it now only rotates around the y axis but how can I set the pivot point?
zerochen
Posts: 273
Joined: Wed Jan 07, 2009 1:17 am
Location: Germany

Re: Raycasting with Irrbullet

Post by zerochen »

it looks good

only a few things to do:

- #include <BulletCollision/CollisionShapes/btCylinderShape.h> is missing in cylindershape.cpp
- delete bool overrideMargin from the constructor aswell from the createShape function call

- #include "CCylinderShape.h" in irrbullet.h

also after that you have to recompile the irrbullet.lib

Edit:
oh wait you dont have to delete overrideMargin instead add the parameter to the createShape function
Last edited by zerochen on Sun Jul 15, 2012 2:36 pm, edited 1 time in total.
eejin
Posts: 97
Joined: Sun Jul 24, 2011 11:50 am

Re: Raycasting with Irrbullet

Post by eejin »

It seems to compile fine but where do I find it. I use code::blocks does that matter?
zerochen
Posts: 273
Joined: Wed Jan 07, 2009 1:17 am
Location: Germany

Re: Raycasting with Irrbullet

Post by zerochen »

i dont use code blocks so i cant tell you that.

if recompile works you might find the libs in <irrBullet>\lib folder
eejin
Posts: 97
Joined: Sun Jul 24, 2011 11:50 am

Re: Raycasting with Irrbullet

Post by eejin »

I get the errors

||=== Irrlicht Example 01 Hello World, Windows ===|
C:\Users\Stijn\Documents\Irrlicht\irrBullet-0.1.8\source\irrBullet.h|51|warning: missing terminating " character|
C:\Users\Stijn\Documents\Irrlicht\irrBullet-0.1.8\source\irrBullet.h|51|error: #include expects "FILENAME" or <FILENAME>|
C:\Users\Stijn\Documents\Irrlicht\irrlicht-1.7.2\examples\01.HelloWorld\main.cpp||In function 'int main()':|
C:\Users\Stijn\Documents\Irrlicht\irrlicht-1.7.2\examples\01.HelloWorld\main.cpp|69|error: expected type-specifier before 'CCylinderShape'|
C:\Users\Stijn\Documents\Irrlicht\irrlicht-1.7.2\examples\01.HelloWorld\main.cpp|69|error: cannot convert 'int*' to 'ICollisionShape*' in initialization|
C:\Users\Stijn\Documents\Irrlicht\irrlicht-1.7.2\examples\01.HelloWorld\main.cpp|69|error: expected ',' or ';' before 'CCylinderShape'|
||=== Build finished: 4 errors, 4 warnings ===|
zerochen
Posts: 273
Joined: Wed Jan 07, 2009 1:17 am
Location: Germany

Re: Raycasting with Irrbullet

Post by zerochen »

what is in line 51 in irrbullet.h?

where is a error. maybe a missing "?
eejin
Posts: 97
Joined: Sun Jul 24, 2011 11:50 am

Re: Raycasting with Irrbullet

Post by eejin »

what is in line 51 in irrbullet.h?

Code: Select all

#include "CCylinderShape.h
where is a error. maybe a missing "?

Code: Select all

ICollisionShape *Floorshape = new CCylinderShape(Floor, 0, false);
zerochen
Posts: 273
Joined: Wed Jan 07, 2009 1:17 am
Location: Germany

Re: Raycasting with Irrbullet

Post by zerochen »

hm, dude you forgot a " -> #include "CCylinderShape.h"
eejin
Posts: 97
Joined: Sun Jul 24, 2011 11:50 am

Re: Raycasting with Irrbullet

Post by eejin »

How do you mean? I included it in irrbullet.h.
eejin
Posts: 97
Joined: Sun Jul 24, 2011 11:50 am

Re: Raycasting with Irrbullet

Post by eejin »

Mhmm I misunderstood what you meant but now fixed it. Although I get this error message now:

Code: Select all

C:\Users\Stijn\Documents\Irrlicht\irrlicht-1.7.2\examples\01.HelloWorld\main.cpp|69|undefined reference to `CCylinderShape::CCylinderShape(irr::scene::ISceneNode*, float)'|
When I call it like this:

Code: Select all

ICollisionShape *Floorshape = new CCylinderShape(Floor, 0);
But it seems to recognise the function because when I call

Code: Select all

ICollisionShape *Floorshape = new CCylinderShape(Floor, 0,false);
I get this:

Code: Select all

C:\Users\Stijn\Documents\Irrlicht\irrlicht-1.7.2\examples\01.HelloWorld\main.cpp||In function 'int main()':|
C:\Users\Stijn\Documents\Irrlicht\irrlicht-1.7.2\examples\01.HelloWorld\main.cpp|69|error: no matching function for call to 'CCylinderShape::CCylinderShape(irr::scene::ISceneNode*&, int, bool)'|
C:\Users\Stijn\Documents\Irrlicht\irrBullet-0.1.8\source\cylindershape.h|15|note: candidates are: CCylinderShape::CCylinderShape(irr::scene::ISceneNode*, irr::f32)|
C:\Users\Stijn\Documents\Irrlicht\irrBullet-0.1.8\source\cylindershape.h|13|note:                 CCylinderShape::CCylinderShape(const CCylinderShape&)|
||=== Build finished: 1 errors, 3 warnings ===|
 
zerochen
Posts: 273
Joined: Wed Jan 07, 2009 1:17 am
Location: Germany

Re: Raycasting with Irrbullet

Post by zerochen »

also after that you have to recompile the irrbullet.lib
yeah always told you that you have to recompile irrbullet.
open project file from irrbullet folder add the cylindershape files to the proj and push compiling^^
Post Reply