Advertisement Jump to content
Sign in to follow this  

Triangle-Voxel intersection question.

This topic is 976 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Initially, I got some code that works with calculating the pivot point of a quad is within

the area of a freely oriented triangle.


Now, I need to calculate whether the pivot point of a Voxel is within the area of the freely oriented triangle

If It is, I add it to the 8 children of the voxel and add the fragments by finding

the intersection of the triangle with the voxel. Okay, let's forget this for a moment.



Now I need to do this first,

I need the same stuff for this for 3D bounding boxes(Octrees)

The pivot has been changed to 3D (because octrees are 3-dimensional)

... but I don't know how to calculate the same thing

when vec1, 2 and 3 are 3-Dimensional, this works if the pivot is 3-dimensional and with y equals to 0.0

and the triangle is 2-Dimenional.

bool Vector3D::isPointInTriangle(const D3DXVECTOR2& vec1,
    const D3DXVECTOR2& vec2, const D3DXVECTOR2& vec3) const
    D3DXVECTOR2 diff1 = vec2 - vec1;
    D3DXVECTOR2 diff2 = vec3 - vec1;    
    D3DXVECTOR2 thisPivot(this->x, this->z);
    D3DXVECTOR2 diff3 = thisPivot - vec1;

    quad::vec2 cross1, cross2;
    // cross1 = crossproduct of (0, 0, 1) and diff1
    cross1.x = -diff1.y;
    cross1.y = diff1.x;
    // cross2 = crossproduct of (0, 0, 1) and diff2
    cross2.x = -diff2.y;
    cross2.y = diff2.x;
    REAL s = D3DXVec2Dot(&diff3, &cross2) / D3DXVec2Dot(&diff1, &cross2);
    REAL v = D3DXVec2Dot(&diff3, &cross1) / D3DXVec2Dot(&diff2, &cross1);

    if (s >= 0 && v >= 0 && ((s + v) <= 1))
        // point is inside or on the edge of this triangle
        return true;
    return false;

Edited by lucky6969b

Share this post

Link to post
Share on other sites

Not sure what you want, but to link triangles to an octree i see two main methods.


Using a loose octree (only one node per triangle, can be an internal or leaf node):

Calculate bounding box for triangle, use largest box dimension to determinate the tree level and box center to find the closest node.

Finally each triangle is ensured to be covered by it's node if the node would be extended half its size on each side.



Using a standart octree (multiple nodes per triangle, only leaf nodes contain triangles).

Write a conservative software rasterizer, find the dominant area plane per triangle (x, y, or z, aligned to the octree),

raster with orthonormal projection so  each rasterized 'pixel' refers to a depth range of octree nodes and link to those nodes.


An easier way would be to use the bounding box instead the rasterizer again and to check each bounded node for intersection with the triangle.



Im confused about the comparision with a 2D point in triangle test you make.

For a 2D quadtree what you should do is a rectangle / triangle intersection test to get correct results.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!