Topic: Line3df
I'm trying to make a function that gets me the height of an ITriangleSelector at a certain point.
I found this function posted somewhere on the Irrlicht forums:
float GetHeight(irr::IrrlichtDevice *device,scene::ITriangleSelector *Ground, const vector3df& pos, float maxHeight) {
scene::ISceneCollisionManager* colMan = device->getSceneManager()->getSceneCollisionManager();
vector3df yAxis(0,maxHeight,0);
line3d<f32> ray(pos, pos-yAxis);
vector3df ptoCol(0,0,0);
triangle3df triangle;
if(colMan->getCollisionPoint(ray, Ground, ptoCol, triangle)) {
return ptoCol.Y;
}
else
{
return -maxHeight;
}
}
This is what I came up with, trying to convert it:
Function getHeight:Float(dev1:IrrlichtDevice , ground:ITriangleSelector , pos:vector3df , maxHeight:Float)
Local colMan:ISceneCollisionManager = dev1.getSceneManager().getSceneCollisionManager()
Local yAxis:vector3df = (_VECTOR3DF(0 , maxHeight , 0))
Local tmppos:vector3df = (_VECTOR3DF(pos.getX() , pos.getY() - yAxis.getY() , pos.getZ()))
Local ray:line3df
ray.createFromVects(pos , tmppos)
Local ptoCol:vector3df = (_VECTOR3DF(0, 0, 0))
Local triangle:triangle3df = New triangle3df
If(colMan.getCollisionPoint(ray , ground , ptoCol , triangle) )
Return ptoCol.getY()
Else
Return maxHeight
EndIf
EndFunction
The colMan.getCollisionPoint functions, is supposed to get the collision between a line3df (ray) and an ITriangleSelector (ground) and return the collision point in a vector3df (ptoCol) and the triangle the collision is on as a triangle3df (triangle).
When I try this function out, it gives me an error, saying that "If(colMan.getCollisionPoint(ray , ground , proCol , triangle))" is trying to access a field or method of a NULL object.
When I look in the Debug tab of the Bmax IDE it says that 'Local ray:Line3df=Null'.
When I add " = New line3df" behind "Local ray:line3df", it will compile, but when the program starts it will give me an error saying that te program stopped unexpected.
I would appreciate it if someone could help me out with this.
Thanks in advantage.