I'll scratch your back you scratch mine?

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.
kendric
Posts: 71
Joined: Tue May 29, 2007 9:05 pm

Post by kendric »

The reference point would be the position of the parent.
I was looking at the custom scene node example and he has an animator on there that rotates it. So that would lead me to believe these vertexs are effected by the rotation of the scene node they are attached on.. Grr.

Another observation I have made.

if i move my mouse across an object clicking for bullet holes to appear, i get them appearing say left to right as i move my mouse up and down, if i then go bump that box so its rotated 90 degrees to the right and do the same test on the same face of the box, the bullet holes change the direction that they move in relation to my mouse.

This leads me to believe it must be related to the rotation of the parent scene node.

Let me know if this makes any sense to you:
Box is rotated at some random x,y,z.

The triangle that we hit the box on is therefor rotated that same x,y,z
When we attach the bullet hole to the parent, we are using the x,y,z math we got using this already rotated object

Thus when we attach using those as our offset, we are really telling it this is my offset then im not rotated at all.

So when it renderes, it does our rotation once as normal but then the rotation our math generated causes us to rotate a bit more.
Does that make any sense?

I am not sure how to solve this. You would have to take the absolute rotation of the parent node, and factor that in to give you the absolute offset x,y,z that your hit location is at.

Update:
By adding the following at the end, the bullet holes get the correct center location now:

vector3df parentRotation=parent->getRotation();
parentRotation.invert();
setRotation(parentRotation);

and now the bullet hole always appears in the right spot on my first code technique. I tried putting that on the one you came up with and didnt have correct results. I have to modify the original one some more though as even though its putting the bullet hole in the right location, they are still not flat against the surface of the box, and still stick out at various angles. This is probably still related to the fact that the x,y,z we get from the collision detection is in absolute co-ords and we are converting it to relative cords with a rotation.


Update 2 :)
Its 95% working now. Unfortuneatly what its doing now is very hard to figure out.

So first bug i found was that using the ab center variable caused the bulets to be at an angle. So now I just use the ab line as my XNorm.
I don't know if thats because of rounding issues or what. It gets normalized so no clue why that would cause a problem.

Another issue i fixed was that you need custom logic to prevent a decal from being attached to another decal since decal scene nodes will be valid picks using the getSceneCollisionManager()->getSceneNodeFromRayBB(line) function.

So now where we stand is as follows:
They work properly except on a very few boxes ;)
I dont know what this means. On usually 1 box on my map i get the bullet holes sticking out at odd angles still. On the other boxes i try (say 9 of 10) the bullet holes are perfect and they stick to the box like glue when its rolling around etc.

Here is what the code looks like now.

trinormal=tri.getNormal();
trinormal.normalize();
vector3df LineBA = pointA- pointB;

vector3df NormX = LineBA;//.normalize();
vector3df NormY = trinormal.crossProduct(NormX);
NormX.normalize();
NormY.normalize();

f32 ModSquareSize = size; //(Place your value here to modify the size of the square)

f32 Displacement = 0.1f; // (How far above the triangle the square will be)

vector3df DisNormal = ( Displacement * trinormal);
intersection=intersection-parent->getAbsolutePosition();
squarepA = intersection + (NormX * ModSquareSize ) + DisNormal;
squarepB = intersection + (NormY * ModSquareSize ) + DisNormal;
squarepC = intersection - (NormX * ModSquareSize ) + DisNormal;
squarepD = intersection - (NormY * ModSquareSize ) + DisNormal;

Vertices[0] = S3DVertex(squarepA.X,squarepA.Y,squarepA.Z, 1,0,0,SColor(255,255,255,255),1,0);
Vertices[1] = S3DVertex(squarepB.X,squarepB.Y,squarepB.Z, 1,0,0,SColor(255,255,255,255),1,1);
Vertices[2] = S3DVertex(squarepC.X,squarepC.Y,squarepC.Z, 1,0,0,SColor(255,255,255,255),0,1);
Vertices[3] = S3DVertex(squarepD.X,squarepD.Y,squarepD.Z, 1,0,0,SColor(255,255,255,255),0,0);


Box.reset(Vertices[0].Pos);
for (s32 i=1; i<4; ++i)
Box.addInternalPoint(Vertices.Pos);
//setPosition(parent->getBoundingBox().getCenter()); <--- note this line is not required. I guess they get a default location that is ok??
vector3df parentRotation=parent->getRotation();
parentRotation.invert();
setRotation(parentRotation);
Post Reply