<?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/426" />

	<title>Real-Time Physics Simulation Forum</title>
	
	<link href="https://pybullet.org/Bullet/phpBB3/index.php" />
	<updated>2006-07-20T11:04:01+00:00</updated>

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

		<entry>
		<author><name><![CDATA[Pushapjit]]></name></author>
		<updated>2006-07-20T11:04:01+00:00</updated>

		<published>2006-07-20T11:04:01+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=1348#p1348</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=1348#p1348"/>
		<title type="html"><![CDATA[collision checks]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=1348#p1348"><![CDATA[
I am implementing BSP tree for organising 3d set of mesh polygons. tree compilation is ok. now i want to check collision of the 3d environment with the camera. my lineofsight() function is for ray/plane ray/polygon intersection. but the camera is still moving form walls. why is this so?<br><br><br><br>1)in lineofsight(), first i find the ray plane intersection details using getIntersect().<br>2) in lineofsight(), it's meant to allow the camera to cross <br>the polygon when going from behind to the front of the polygon but not when <br>going from the front to behind. <br>3) pointInPolygon is used to find whether point is in polygon or not<br>4)I have calculated the dot product and cross product of two 3d vector.<br><br>Am i going in right direction?<br>Code:<br><br><br>//-----------------------------------------------------------------------------<br>// Name : lineOfSight() (Recursive)<br>// Desc : Tests line of sight between two points.<br>//----------------------------------------------------------------------------- <br>bool My3DApplication::lineOfSight( D3DXVECTOR3 *Start, D3DXVECTOR3 *End, NODE *Node )<br>{<br>    D3DXVECTOR3 intersection;<br>    float       temp = 0.0f;<br>    bool flag;<br>    <br>   if( Node-&gt;bIsLeaf )<br>        return true;<br><br>   int PointA = classifyPoint(Start, Node-&gt;Splitter);<br>   int PointB = classifyPoint(End,   Node-&gt;Splitter);<br><br>   // Check if only in front or on polygon<br>   if( PointA != POINTPOSITION_BACK &amp;&amp; PointB != POINTPOSITION_BACK )<br>        return lineOfSight(Start,End,Node-&gt;Front);<br><br>   // check if only in back<br>   if( PointA != POINTPOSITION_FRONT &amp;&amp; PointB != POINTPOSITION_BACK ) <br>       return lineOfSight(Start,End,Node-&gt;Back);<br><br>   // Crossing polygon, need intersection point<br>   getIntersect(Start, End, (D3DXVECTOR3 *)&amp;Node-&gt;Splitter-&gt;VertexList[0], <br>        &amp;Node-&gt;Splitter-&gt;Normal, &amp;intersection, &amp;temp);<br>  <br>if( PointA == POINTPOSITION_FRONT )<br>    {<br>        // Crossing from front to back.<br> //       return lineOfSight( Start, &amp;intersection, Node-&gt;Front ) ||<br>        <br>// Don't allow crossing polygon from front to back.<br>//check whether point is in polygon                  <br>   flag = pointInPolygon( &amp;intersection, (D3DXVECTOR3 *)&amp;Node-&gt;Splitter-&gt;VertexList[0],<br>                Node-&gt;Splitter-&gt;nNumberOfVertices); <br>    if(flag == true)<br>return false;<br>      lineOfSight( &amp;intersection, End, Node-&gt;Back );<br>    } // End of if<br>  <br>   else<br>    {<br>       // Crossing from back to front.<br>        return lineOfSight( Start, &amp;intersection, Node-&gt;Back ) ||<br>               lineOfSight( &amp;intersection, End, Node-&gt;Front );<br>    }<br>}<br><br><br><br><br>//---------------------------------------------------------------------------<br>//Name:pointInPolygon<br>//Desc:<br>//---------------------------------------------------------------------------<br>bool My3DApplication::pointInPolygon(D3DXVECTOR3 *point, D3DXVECTOR3 *vertices, int numVertices)<br>{<br>    D3DXVECTOR3 p = cross(vertices[numVertices-1] - (*point), vertices[0] - (*point));<br>    for (int i = 0; i &lt; numVertices - 1; i++)<br>    {<br>        D3DXVECTOR3 q = cross(vertices<em class="text-italics"> - (*point), vertices[i+1] - (*point));<br>        if (dot(p, q) &lt; 0)<br>           // Point not in polygon<br>            return false;<br>    }<br>    return true;<br>}<br><br>//-----------------------------------------------------------------------------<br>//Name:dot<br>//Desc:Determines the dot-product of two 3-D vectors<br>//-----------------------------------------------------------------------------<br>inline float dot(D3DXVECTOR3&amp; v1, D3DXVECTOR3&amp; v2) <br>{<br> return ( v1.x * v2.x + v1.y * v2.y + v1.z * v2.z );<br>}         <br><br>//-----------------------------------------------------------------------------<br>//Name:cross<br>//Desc: Determines the cross-product of two 3-D vectors.<br>//-----------------------------------------------------------------------------<br>inline D3DXVECTOR3 cross (D3DXVECTOR3 v1, D3DXVECTOR3 v2)<br> {<br> D3DXVECTOR3 result;<br> <br> result.x = (v1.y * v2.z) - (v2.y * v1.z);<br> result.y = (v1.z * v2.x) - (v2.z * v1.x);<br> result.z = (v1.x * v2.y) - (v2.x * v1.y); <br> <br> return (result);<br>}         <br><br><br>//-----------------------------------------------------------------------------<br>// Name : getIntersect<br>// Desc : Get the ray / plane intersection details<br>//-----------------------------------------------------------------------------<br>bool My3DApplication::getIntersect( D3DXVECTOR3 *linestart, D3DXVECTOR3 *lineend, <br>D3DXVECTOR3 *vertex, D3DXVECTOR3 *normal, <br>D3DXVECTOR3 *intersection, float *percentage )<br>{<br>    D3DXVECTOR3 direction;<br>    D3DXVECTOR3 L1;<br>    float       linelength;<br>    float       dist_from_plane;<br><br>    direction.x = lineend-&gt;x - linestart-&gt;x;<br>    direction.y = lineend-&gt;y - linestart-&gt;y;<br>    direction.z = lineend-&gt;z - linestart-&gt;z;<br><br>    linelength = D3DXVec3Dot(&amp;direction, normal);<br>    <br>    if( fabsf( linelength ) &lt; 0.001f ) <br>        return false;<br><br>    L1.x = vertex-&gt;x - linestart-&gt;x;<br>    L1.y = vertex-&gt;y - linestart-&gt;y;<br>    L1.z = vertex-&gt;z - linestart-&gt;z;<br><br>    dist_from_plane = D3DXVec3Dot(&amp;L1, normal);<br><br>    // How far from Linestart , intersection is as a percentage of 0 to 1<br>     *percentage = dist_from_plane / linelength; <br><br>    // The ray does not reach, or is in front of the plane<br>    if( *percentage &lt; 0.0f || *percentage &gt; 1.0f ) <br>        return false;<br><br>    // add the percentage of the line to line start<br>    intersection-&gt;x = linestart-&gt;x + direction.x * (*percentage);<br>    intersection-&gt;y = linestart-&gt;y + direction.y * (*percentage);<br>    intersection-&gt;z = linestart-&gt;z + direction.z * (*percentage);   <br>    return true;<br>}</em><p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=644">Pushapjit</a> — Thu Jul 20, 2006 11:04 am</p><hr />
]]></content>
	</entry>
	</feed>
