Plane intersection

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.
Post Reply
Escen
Competition winner
Posts: 167
Joined: Sun Jul 19, 2009 11:27 am
Location: the Netherlands
Contact:

Plane intersection

Post by Escen »

Hello guys

I'm struggling several days now and I need some help here...

I have made an simple CustomSceneNode (pic A). I want to extent the edges with line3df and get the intersection with the underlying plane, like wanted result in pic B.

After Rotating the node I do get intersections but it looks like the plane turns within the Node.
The object shape stays unchanged and looks like the original shape (pic A).

Can anyone give my some advice? How do I get the intersections with a static ground plane?

I tweaked the code snip a little but this is in general what I'm doing.

Image

Render part:

Code: Select all

 void vofcameraNode::render()
{
		u16 indices[] = {0,2,3, 1,3,0, 2,0,1, 3,2,4, 4,2,1, 3,1,4};
		
		video::IVideoDriver* driver = SceneManager->getVideoDriver();
		SenMaterial.BackfaceCulling=false;

		driver->setMaterial(SenMaterial);
        driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
		
		driver->drawIndexedTriangleList(&Vertices[0], 5, &indices[0], 6);

        video::SColor color =video::SColor(255,255,255,0);
        LineMaterial.Thickness=1;
        LineMaterial.AmbientColor = LineMaterial.DiffuseColor = LineMaterial.EmissiveColor = color;

		driver->setMaterial(LineMaterial);

        //sensor edges
        driver->draw3DLine(Vertices[2].Pos,Vertices[0].Pos,color);
        driver->draw3DLine(Vertices[2].Pos,Vertices[1].Pos,color);
        driver->draw3DLine(Vertices[2].Pos,Vertices[3].Pos,color);
        driver->draw3DLine(Vertices[2].Pos,Vertices[4].Pos,color);
        //footprint
        driver->draw3DLine(Vertices[0].Pos,Vertices[1].Pos,color);
        driver->draw3DLine(Vertices[1].Pos,Vertices[4].Pos,color);
        driver->draw3DLine(Vertices[4].Pos,Vertices[3].Pos,color);
        driver->draw3DLine(Vertices[3].Pos,Vertices[0].Pos,color);

        driver->draw3DLine(LineRay.start,LineRay.end,color);

};
Calculate intersection vertex #1

Code: Select all

void SensorManager::changeRoll()
{
        //calculate intersection vertex #1
        core::vector3df vert_pos (VOFNode->Vertices[0].Pos);

        line3df LineRay;
        irr::core::vector3df targetPosition;

        LineRay.start=VOFNode->getAbsolutePosition();
        LineRay.end=LineRay.start+(vert_pos-LineRay.start).normalize()*1000;

        vector3df normal = irr::core::vector3df(0,1,0);

        plane3df plane;
        plane.setPlane( irr::core::vector3df(0,0,0), normal);
        plane.getIntersectionWithLine(LineRay.start, LineRay.end, targetPosition);

        VOFNode->Vertices[0] = video::S3DVertex(targetPosition.X,targetPosition.Y,targetPosition.Z, 0,0,0,
        video::SColor(255,0,255,255), 0, 1);
};
Last edited by Escen on Sun Feb 21, 2010 11:47 pm, edited 1 time in total.
Zeus
Posts: 24
Joined: Sun Dec 13, 2009 1:03 pm
Location: Germany :P

Re: Plane intersection

Post by Zeus »

Escen wrote: Can anyone give my some advice? How do I get the intersections with a static ground plane?
if i understand you correct and you only want to know if a corner "intersects" the plane you just have to check if the Z coordinate of the corner of the mesh is greater or less the Z coordinate of the plane ...
Is there any posible answer ... i'm sick of it ...

http://irrlicht.sourceforge.net/phpBB2/ ... 919#215919

thanks ...
Escen
Competition winner
Posts: 167
Joined: Sun Jul 19, 2009 11:27 am
Location: the Netherlands
Contact:

Post by Escen »

Well, that's maybe a good suggestion, bud I wonder if that approach works for me. I do not see any way of applying this method.

In general I'm holding a (digital) camera at a given altitude, lets say 150 meter, face straight down...
With a lens ratio FOV Horizontal 56 degrees and 40.3 degrees Vertical my Image footprint on ground will be 110 meter high and 160 meter width.

I'm not moving this Node around, except in altitude and rotation, I want to keep this FOV ratio. Later I will use different camera's and different lens ratio.
When rotating the camera the footprint will lost this rectangle shape. My goal is to illustrate this changing footprint. (and do some calculation later)

My approach for now:

1. first calculate four corners at given altitude and FOV ratio.
2. get Image width and high.
3. create lines from camera position to every corner and extent.
4. get intersections with plane.
5. apply intersections to corners.
6. render.

To make sure that I using a correct FOV ratio I recalculate this before any new rendering.

When I place a plane below the camera at vector3df(0,0,0) normal vector3df(0,1,0) everything looks good.
but when I rotate the Node the plane stick to the Node. Everything stays the same like illustrated in Picture A.
I think this happens because all calculations are in a relative position of the origin and then rendered afterward with AbsoluteTransformation.

And this is were I got stuck. How do I get the intersections with a static ground plane?
Can someone give me some direction?
Escen
Competition winner
Posts: 167
Joined: Sun Jul 19, 2009 11:27 am
Location: the Netherlands
Contact:

Post by Escen »

Anyone?
Escen
Competition winner
Posts: 167
Joined: Sun Jul 19, 2009 11:27 am
Location: the Netherlands
Contact:

Post by Escen »

Hi Escen,

Maybe this is useful for you..
It align your plane in opposite Node rotation.

Code: Select all

 
        core::vector3df normal=core::vector3df(0, 1, 0);
        VOFNode->getAbsoluteTransformation().inverseRotateVect(normal);
        plane3df plane;

        plane.setPlane( irr::core::vector3df(0,0,0), normal);
Escen
Competition winner
Posts: 167
Joined: Sun Jul 19, 2009 11:27 am
Location: the Netherlands
Contact:

Re: Plane intersection

Post by Escen »

AHA...I figured out the problem
Post Reply