[Solved] raycasting bullet vehicle

johnsonalpha
Posts: 73
Joined: Fri May 01, 2015 8:23 pm

[Solved] raycasting bullet vehicle

Post by johnsonalpha »

Wow ive been searching for hours can someone please help me with a simple convex hull ive looked at ConvexDecompositionDemo i dont understand it Please Help!!!


What am i doing wrong here?

Code: Select all

		

btVector3 motstate(0, 0, 0);

btVector3 inertia(0, 0, 0);

// create a vertex cloud defining a square-based pyramid
btVector3 points[5] = { btVector3(-0.5,1,1), btVector3(-0.5,1,-1), btVector3(-0.5,-1,1), btVector3(-0.5,-1,-1), btVector3(1,0,0) };
	

[b]how do i add this to the dynamics world???[/b]

Also how does the add point method work? ===============================================

Code: Select all

	
btVector3 motstate(0, 0, 0);

btVector3 inertia(0, 0, 0);

// create a vertex cloud defining a square-based pyramid
btVector3 points[5] = { btVector3(-0.5,1,1), btVector3(-0.5,1,-1), btVector3(-0.5,-1,1), btVector3(-0.5,-1,-1), btVector3(1,0,0) };



WHERE DO I GO FROM HERE?
how do i add the points i just add to a convex hull?


Last edited by johnsonalpha on Mon May 11, 2015 1:59 pm, edited 2 times in total.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Does anyone now how to use btConvexHullShape???!!! ( HEL

Post by drleviathan »

To create a btConvexHull shape you would do something like this:

Code: Select all

    int NUM_POINTS = 5;
    btVector3 points[NUM_POINTS] = { 
        btVector3(-0.5, 1,  1),
        btVector3(-0.5, 1, -1),
        btVector3(-0.5,-1,  1),
        btVector3(-0.5,-1, -1), 
        btVector3(   1, 0,  0) };

    btConvexHullShape* shape = new btConvexHullShape();
    for (int i = 0; i < NUM_POINTS; ++i) {
        // passing 'false' as second argument is an optimization that avoids constantly calling 
        // recalcLocalAabb(), which can then be called once after all points are added.
        shape->addPoint(points[i], false);
    }           
    shape->recalcLocalAabb();
To use the shape on a btRigidBody:

Code: Select all

    // assuming you've computed mass, inertia, and have a pointer to a MotionState:
    body = new btRigidBody(mass, motionState, shape, inertia);
    dynamicsWorld->addBody(body);
johnsonalpha
Posts: 73
Joined: Fri May 01, 2015 8:23 pm

Re: Does anyone now how to use btConvexHullShape???!!! ( HEL

Post by johnsonalpha »

Is dynamicsWorld->addBody(body) the same as dynamicsWorld->addRigidBody(body)?
aviator
Posts: 13
Joined: Thu Apr 02, 2015 5:15 pm

Re: Does anyone now how to use btConvexHullShape???!!! ( HEL

Post by aviator »

johnsonalpha wrote:Is dynamicsWorld->addBody(body) the same as dynamicsWorld->addRigidBody(body)?
Ohh man you really need to learn Bullet more :)
He meant dynamicsWorld->addRigidBody(rBody).
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Does anyone now how to use btConvexHullShape???!!! ( HEL

Post by drleviathan »

Yes sorry, that was a typo. Use dynamicsEngine->addRigidBody(body);
ed_welch
Posts: 43
Joined: Wed Mar 04, 2015 6:16 pm

Re: Does anyone now how to use btConvexHullShape???!!! ( HEL

Post by ed_welch »

by the way, 2 things about btConvexHullShape:
1) don't use addPoint if you have more than a few points. It is incredably slow.
2) you will also probaly need to use btShapeHull for performance, if you are using models with more than a few dozen triangles
johnsonalpha
Posts: 73
Joined: Fri May 01, 2015 8:23 pm

Re: Does anyone now how to use btConvexHullShape???!!! ( HEL

Post by johnsonalpha »

How would i do that?
ed_welch
Posts: 43
Joined: Wed Mar 04, 2015 6:16 pm

Re: Does anyone now how to use btConvexHullShape???!!! ( HEL

Post by ed_welch »

johnsonalpha wrote:How would i do that?
This is the code I use:

Code: Select all

    btConvexHullShape convexHullShape(
        m_pPositions->GetVertexData(), m_pPositions->GetNumVertices(), m_pPositions->GetStride()*sizeof(float));
    //create a hull approximation
	btShapeHull* hull = new btShapeHull(&convexHullShape);
	btScalar margin = convexHullShape.getMargin();
	hull->buildHull(margin);

johnsonalpha
Posts: 73
Joined: Fri May 01, 2015 8:23 pm

Re: Does anyone now how to use btConvexHullShape???!!! ( HEL

Post by johnsonalpha »

Thats all O_o?