<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://pybullet.org/Bullet/phpBB3/app.php/feed/topic/13250" />

	<title>Real-Time Physics Simulation Forum</title>
	
	<link href="https://pybullet.org/Bullet/phpBB3/index.php" />
	<updated>2021-07-29T17:52:00+00:00</updated>

	<author><name><![CDATA[Real-Time Physics Simulation Forum]]></name></author>
	<id>https://pybullet.org/Bullet/phpBB3/app.php/feed/topic/13250</id>

		<entry>
		<author><name><![CDATA[paokakis]]></name></author>
		<updated>2021-07-29T17:52:00+00:00</updated>

		<published>2021-07-29T17:52:00+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43531#p43531</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43531#p43531"/>
		<title type="html"><![CDATA[Re: RayTest fails]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43531#p43531"><![CDATA[
Thank you very much for your support. I was able to solve my problem this way :<br><div class="codebox"><p>Code: </p><pre><code>btCollisionWorld::ClosestRayResultCallback rayCallback(rayFrom, rayTo);rayCallback.m_collisionFilterGroup = 0b1111111;rayCallback.m_collisionFilterMask = 0b1111111;mpDynamicsWorld-&gt;rayTest(rayFrom, rayTo, rayCallback);</code></pre></div>In case it helps someone...<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=13868">paokakis</a> — Thu Jul 29, 2021 5:52 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[drleviathan]]></name></author>
		<updated>2021-07-29T16:55:15+00:00</updated>

		<published>2021-07-29T16:55:15+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43530#p43530</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43530#p43530"/>
		<title type="html"><![CDATA[Re: RayTest fails]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43530#p43530"><![CDATA[
Check out the ctor implementation of <strong class="text-strong">RayResultCallback</strong>, from which <strong class="text-strong">ClosestRayHitCallback</strong> derives:<div class="codebox"><p>Code: </p><pre><code>                RayResultCallback()                        : m_closestHitFraction(btScalar(1.)),                          m_collisionObject(0),                          m_collisionFilterGroup(btBroadphaseProxy::DefaultFilter),                          m_collisionFilterMask(btBroadphaseProxy::AllFilter),                          //@BP Mod                          m_flags(0)                {                         }</code></pre></div>You can see the default <strong class="text-strong">group</strong> and <strong class="text-strong">mask</strong> being set.  If you track down where <strong class="text-strong">btBroadphaseProxy::DefaultFilter</strong> and <strong class="text-strong">btBroadphaseProxy::AllFilter</strong> are defined you'll learn their values are <strong class="text-strong">1</strong> and <strong class="text-strong">-1</strong> respectively (of course, interpreted as unsigned).  You can set those data members to whatever you want after instantiation: they are <strong class="text-strong">public</strong> because <strong class="text-strong">RayResultCallback</strong> is a C++ <strong class="text-strong">struct</strong>, which is just a <strong class="text-strong">class</strong> but with all methods and members defaulting to <strong class="text-strong">public</strong>.<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=11033">drleviathan</a> — Thu Jul 29, 2021 4:55 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[paokakis]]></name></author>
		<updated>2021-07-29T11:25:46+00:00</updated>

		<published>2021-07-29T11:25:46+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43529#p43529</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43529#p43529"/>
		<title type="html"><![CDATA[Re: RayTest fails]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43529#p43529"><![CDATA[
I used also other groups but no success... I tried for example group 4 with mask 4 but again I get no raytest results. Only when I use group 1 with mask 1 it works, ah also the default works (no groups and no mask specified). <br><blockquote class="uncited"><div>You need to set your callback's group to some single bit and then be sure set that same bit in the mask of all objects which should be pickable by rays.</div></blockquote>How can I set my callback's group to something different?<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=13868">paokakis</a> — Thu Jul 29, 2021 11:25 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[drleviathan]]></name></author>
		<updated>2021-07-28T20:22:02+00:00</updated>

		<published>2021-07-28T20:22:02+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43528#p43528</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43528#p43528"/>
		<title type="html"><![CDATA[Re: RayTest fails]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43528#p43528"><![CDATA[
The collision groups and masks are used at the BroadPhase to submit overlap pairs to the NarrowPhase.<br><br>AABB's overlaps in the BroadPhase are submitted to the NarrowPhase iff each object collides with the other's group.  In other words when: <strong class="text-strong">ObjectA.group &amp; ObjectB.mask &amp;&amp; ObjectB.group &amp; ObjectA.mask</strong>.<br><br>If you don't submit a custom <strong class="text-strong">mask</strong> when adding an object to the world it receives a default value of <strong class="text-strong">btBroadphaseProxy::AllFilter</strong> whose value is <strong class="text-strong">-1</strong> in unsigned context: e.g. all bits set.<br><br>When you use a zero <strong class="text-strong">mask</strong> then it collides with nothing, including ray traces...<br><br>... because <strong class="text-strong">btCollisionWorld::ClosestRayResultCallback</strong> derives from <strong class="text-strong">btCollisonWorld::RayResultCallback</strong> which has <strong class="text-strong">m_collisionFilterGroup</strong> and <strong class="text-strong">m_collisionFilterMask</strong> data members which default to <strong class="text-strong">btBroadphaseProxy::AllFilter</strong> and are used when checking for overlaps in the BroadPhase data structure.<br><br>You need to set your callback's group to some single bit and then be sure set that same bit in the mask of all objects which should be pickable by rays.<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=11033">drleviathan</a> — Wed Jul 28, 2021 8:22 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[paokakis]]></name></author>
		<updated>2021-07-28T15:45:43+00:00</updated>

		<published>2021-07-28T15:45:43+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43526#p43526</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43526#p43526"/>
		<title type="html"><![CDATA[RayTest fails]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43526#p43526"><![CDATA[
Hello to the group,<br><br>I am using bullet in an OpenGL application creating a 3D space shooter. At some point I want to ray cast from the middle of the screen to a rigid body on the screen. This works fine for rigid bodies with group 1 and mask 1. But I have some objects that don't collide with others set a group of 1 and mask of 0. On those objects the the ray misses. Here is the ray that I am casting : <br><div class="codebox"><p>Code: </p><pre><code>bool BphysicsManager::rayHasHit(glm::vec3&amp; rayFromWorld, glm::vec3&amp; rayToWorld, btVector3* hitPointWorld, btRigidBody** body){mMutex-&gt;lock();bool ret;rayFrom.setX(rayFromWorld.x);rayFrom.setY(rayFromWorld.y);rayFrom.setZ(rayFromWorld.z);rayTo.setX(rayToWorld.x);rayTo.setY(rayToWorld.y);rayTo.setZ(rayToWorld.z);btCollisionWorld::ClosestRayResultCallback rayCallback(rayFrom, rayTo);mpDynamicsWorld-&gt;rayTest(rayFrom, rayTo, rayCallback);if (rayCallback.m_collisionObject){*body = (btRigidBody*)btRigidBody::upcast(rayCallback.m_collisionObject);*hitPointWorld = rayCallback.m_hitPointWorld;auto colShape = (*body)-&gt;getCollisionShape();if (dynamic_cast&lt;btConcaveShape*&gt;(colShape) != nullptr){*body = nullptr;}}ret = rayCallback.hasHit();mMutex-&gt;unlock();return ret;}</code></pre></div>and here is the rigid body creation : <div class="codebox"><p>Code: </p><pre><code>btRigidBody* BphysicsManager::loadBody(btVector3&amp; pLocation, float pSizeX, float pSizeY, float pSizeZ, btVector3&amp; scale , float pDensity, void* userPtr, shape_type_t type, int group, int mask){mMutex-&gt;lock();btCollisionShape* shape;switch (type) {case SHAPE_BOX:shape = new btBoxShape(btVector3(pSizeX, pSizeY, pSizeZ));break;case SHAPE_SPHERE:shape = new btSphereShape(pSizeX / 2);break;case SHAPE_CAPSULE:shape = new btCapsuleShape(pSizeY, pSizeY / 4);break;case SHAPE_CYLINDER:shape = new btCylinderShape(btVector3(pSizeX / 2, pSizeY / 2, pSizeZ / 2));break;default:shape = new btSphereShape(pSizeX / 2);break;}shape-&gt;setMargin(0.001f);shape-&gt;setLocalScaling(scale);btTransform startTransform = btTransform();startTransform.setIdentity();startTransform.setOrigin(pLocation);//put it to x,y,z coordinatesbtAssert((!shape || shape-&gt;getShapeType() != INVALID_SHAPE_PROXYTYPE));//rigidbody is dynamic if and only if mass is non zero, otherwise staticbool isDynamic = (pDensity != 0.f);btVector3 localInertia(0, 0, 0);if (isDynamic)shape-&gt;calculateLocalInertia(pDensity, localInertia);//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects#define USE_MOTIONSTATE 1#ifdef USE_MOTIONSTATEbtDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);vMotionStates.push_back(myMotionState);btRigidBody::btRigidBodyConstructionInfo cInfo(pDensity, myMotionState, shape, localInertia);btRigidBody* body = new btRigidBody(cInfo);body-&gt;setWorldTransform(startTransform);#elsebtRigidBody* body = new btRigidBody(mass, 0, shape, localInertia);body-&gt;setWorldTransform(startTransform);#endif//if (userPtr) body-&gt;setUserPointer(userPtr);vCollisionShapes.push_back(shape);vRigidBodies.push_back(body);body-&gt;setAngularFactor(1.f);body-&gt;setLinearVelocity(btVector3(0, 0, 0));body-&gt;setAngularVelocity(btVector3(0, 0, 0));body-&gt;setFriction(1.0);body-&gt;activate(true);body-&gt;setSleepingThresholds(0.f, 0.f);if (userPtr) body-&gt;setUserPointer(userPtr);mpDynamicsWorld-&gt;addRigidBody(body, group, mask);mMutex-&gt;unlock();return body;}</code></pre></div>Can someone identify some problem?<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=13868">paokakis</a> — Wed Jul 28, 2021 3:45 pm</p><hr />
]]></content>
	</entry>
	</feed>
