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.

Re: Raycasting with Irrbullet

Postby eejin » Wed Jul 11, 2012 9:42 am

zerochen wrote:hi,

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

eg
cpp Code: Select all
 
body->setActivationState(EAS_DISABLE_DEACTIVATION)
 

Thanks it works :D. Now how would I get a cilinder as a collisionshape ?
eejin
 
Posts: 93
Joined: Sun Jul 24, 2011 11:50 am

Re: Raycasting with Irrbullet

Postby zerochen » Wed Jul 11, 2012 4:08 pm

it is not so hard to implement one yourself

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

cpp 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));
}
zerochen
 
Posts: 196
Joined: Wed Jan 07, 2009 1:17 am
Location: Germany

Re: Raycasting with Irrbullet

Postby eejin » Sat Jul 14, 2012 2:27 pm

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?
eejin
 
Posts: 93
Joined: Sun Jul 24, 2011 11:50 am

Re: Raycasting with Irrbullet

Postby zerochen » Sat Jul 14, 2012 3:01 pm

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

allow Y rotation:
cpp Code: Select all
   
rigidBody->setAngularFactor(vector3df(0,1,0));
 
zerochen
 
Posts: 196
Joined: Wed Jan 07, 2009 1:17 am
Location: Germany

Re: Raycasting with Irrbullet

Postby eejin » Sun Jul 15, 2012 12:34 pm

Mhmm I get these errors:

cpp 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
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
cpp 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:
cpp 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?
eejin
 
Posts: 93
Joined: Sun Jul 24, 2011 11:50 am

Re: Raycasting with Irrbullet

Postby zerochen » Sun Jul 15, 2012 2:05 pm

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.
zerochen
 
Posts: 196
Joined: Wed Jan 07, 2009 1:17 am
Location: Germany

Re: Raycasting with Irrbullet

Postby eejin » Sun Jul 15, 2012 2:36 pm

It seems to compile fine but where do I find it. I use code::blocks does that matter?
eejin
 
Posts: 93
Joined: Sun Jul 24, 2011 11:50 am

Re: Raycasting with Irrbullet

Postby zerochen » Sun Jul 15, 2012 3:00 pm

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

if recompile works you might find the libs in <irrBullet>\lib folder
zerochen
 
Posts: 196
Joined: Wed Jan 07, 2009 1:17 am
Location: Germany

Re: Raycasting with Irrbullet

Postby eejin » Sun Jul 15, 2012 6:35 pm

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 ===|
eejin
 
Posts: 93
Joined: Sun Jul 24, 2011 11:50 am

Re: Raycasting with Irrbullet

Postby zerochen » Sun Jul 15, 2012 7:44 pm

what is in line 51 in irrbullet.h?

where is a error. maybe a missing "?
zerochen
 
Posts: 196
Joined: Wed Jan 07, 2009 1:17 am
Location: Germany

Re: Raycasting with Irrbullet

Postby eejin » Sun Jul 15, 2012 8:17 pm

what is in line 51 in irrbullet.h?
cpp Code: Select all
#include "CCylinderShape.h


where is a error. maybe a missing "?
cpp Code: Select all
ICollisionShape *Floorshape = new CCylinderShape(Floor, 0, false);
eejin
 
Posts: 93
Joined: Sun Jul 24, 2011 11:50 am

Re: Raycasting with Irrbullet

Postby zerochen » Sun Jul 15, 2012 8:38 pm

hm, dude you forgot a " -> #include "CCylinderShape.h"
zerochen
 
Posts: 196
Joined: Wed Jan 07, 2009 1:17 am
Location: Germany

Re: Raycasting with Irrbullet

Postby eejin » Sun Jul 15, 2012 10:07 pm

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

Re: Raycasting with Irrbullet

Postby eejin » Mon Jul 16, 2012 6:46 pm

Mhmm I misunderstood what you meant but now fixed it. Although I get this error message now:
cpp 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:
cpp Code: Select all
ICollisionShape *Floorshape = new CCylinderShape(Floor, 0);


But it seems to recognise the function because when I call
cpp Code: Select all
ICollisionShape *Floorshape = new CCylinderShape(Floor, 0,false);


I get this:
cpp 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 ===|
 
eejin
 
Posts: 93
Joined: Sun Jul 24, 2011 11:50 am

Re: Raycasting with Irrbullet

Postby zerochen » Mon Jul 16, 2012 7:07 pm

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^^
zerochen
 
Posts: 196
Joined: Wed Jan 07, 2009 1:17 am
Location: Germany

PreviousNext

Return to Beginners Help

Who is online

Users browsing this forum: No registered users and 1 guest