Pergunta

I want to get a Collide Vector of a Mesh using a Up-Vector.

I have a position and a Up Vector.. with these both I calculate the far vector

public Vector3 SetPlayerToGround(Matrix Object, Matrix Player, Mesh GroundObject)
        {

            Vector3 IntersectVector = new Vector3(0, 0, 0);

            if (GroundObject != null)
            {
                Vector3 Player_UP = new Vector3(Player.M12, Player.M22, Player.M32);
                Vector3 PlayerPos = new Vector3(Player.M14, Player.M24, Player.M34);
                Vector3 PlayerPos_Far = PlayerPos - Player_UP ;

                gameengine.m_Device.Transform.World = Object;


                IntersectInformation closestIntersection;


             
                if (GroundObject.Intersect(PlayerPos, PlayerPos_Far, out closestIntersection))
                {
                    IntersectVector = Player_UP + (PlayerPos_Far * closestIntersection.Dist);

                }
            }

            return IntersectVector;
        }

Well if I do

Vector3 PlayerPos_Far = PlayerPos + Player_UP;

It will always intersect with nothing... But the Object which I want to intersect is always under the "position - UpVector"

so I think

Vector3 PlayerPos_Far = PlayerPos - Player_UP ;

is right

why I cant intersect?

Here is a better Description:

Image of a Scene where I need the Intersect

Here is the Player and he is into a Ship. the Player is always at 0,0,0 because I move the world around the player. if I Move the Player forward I Chance the playerposition vector which chance only the positions of all other objects. But I think the player has nothing to do with the Intersect.. but the ship itself. I use the Position 0,0,0 and the upvector as direction to get the intersectvector of the ground from the ship. the Matrix of the Ship is (Matrix Object):

Vector3 com = ship.position - gamemanager.player.position;
                    Matrix world;
                    world = Matrix.Identity * Matrix.Scaling(0.001f, 0.001f, 0.001f) * Matrix.Translation(com);
                    m_Device.Transform.World = world;

I tried something and I think he wont use my translated Matrix of the ship...

Foi útil?

Solução

You have to provide a ray defined by a position and a direction. You do not have to specify two points. So pass -PLAYER_UP instead of PlayerPos_Far.

Furthermore, the Intersect method will not care about transformations. You have to pretransform the ray. Transform both the ray position and the direction with the inverse world matrix (transform from world space to model's space) and you should be fine.

Vector3 rayStart = PlayerPos;
Vector3 rayDir = -PLAYER_UP;
Matrix world; //the ship's world matrix
world = Matrix.Invert(matrix);
rayStart = Vector3.TransformCoordinate(rayStart, world); //you may need to add an out parameter
rayDir = Vector3.TransformNormal(rayDir, world);
GroundObject.Intersect(rayStart, rayDir, ...
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top