Fix SphereCast() with mesh shapes. #29

Closed
and3md wants to merge 1 commit from sphere_cast into master
and3md commented 2023-05-09 12:38:21 +00:00 (Migrated from github.com)

Hello,

I tried to use SphereCast() but it sometimes not works for me. I found the problem is in function SphereCastTriangle(). We have here code:

   if t<0.0 then begin
    result:=false;
    exit;
   end else begin
    Time:=-t;
    aU:=U;
    aV:=V;
    result:=true;
    exit;
   end;

But in function that call it (TKraftShapeMesh.SphereCast()) there is a condition (Time>=0.0):

       if SphereCastTriangle(Origin,
                             Radius,
                             Direction,
                             fMesh.fVertices[Triangle^.Vertices[DoubleSidedTriangleVertexOrderIndices[SidePass,0]]],
                             fMesh.fVertices[Triangle^.Vertices[DoubleSidedTriangleVertexOrderIndices[SidePass,1]]],
                             fMesh.fVertices[Triangle^.Vertices[DoubleSidedTriangleVertexOrderIndices[SidePass,2]]],
                             Time,
                             u,
                             v) then begin
        p:=Vector3Add(Origin,Vector3ScalarMul(Direction,Time));
        if ((Time>=0.0) and (Time<=SphereCastData.MaxTime)) and (First or (Time<Nearest)) then
        begin

So when t is greater than 0 it changes it sign and always is negative.
My fix is to change that line to:

Time:=t;

After that SphereCast() works perfectly.
My test case project is CGE simple game located in examples/physics/physics_3d_shooter in physics_walk_navigation branch commit 6fea532ae3550102bf3b6916c8a489a0022fe2ba.

Hello, I tried to use `SphereCast()` but it sometimes not works for me. I found the problem is in `function SphereCastTriangle()`. We have here code: ``` if t<0.0 then begin result:=false; exit; end else begin Time:=-t; aU:=U; aV:=V; result:=true; exit; end; ``` But in function that call it (`TKraftShapeMesh.SphereCast()`) there is a condition `(Time>=0.0)`: ``` if SphereCastTriangle(Origin, Radius, Direction, fMesh.fVertices[Triangle^.Vertices[DoubleSidedTriangleVertexOrderIndices[SidePass,0]]], fMesh.fVertices[Triangle^.Vertices[DoubleSidedTriangleVertexOrderIndices[SidePass,1]]], fMesh.fVertices[Triangle^.Vertices[DoubleSidedTriangleVertexOrderIndices[SidePass,2]]], Time, u, v) then begin p:=Vector3Add(Origin,Vector3ScalarMul(Direction,Time)); if ((Time>=0.0) and (Time<=SphereCastData.MaxTime)) and (First or (Time<Nearest)) then begin ``` So when `t` is greater than `0` it changes it sign and always is negative. My fix is to change that line to: ``` Time:=t; ``` After that `SphereCast()` works perfectly. My test case project is CGE simple game located in `examples/physics/physics_3d_shooter` in [physics_walk_navigation](https://github.com/castle-engine/castle-engine/tree/physics_walk_navigation) branch commit 6fea532ae3550102bf3b6916c8a489a0022fe2ba.
BeRo1985 commented 2023-05-10 04:51:04 +00:00 (Migrated from github.com)

It should also be fixed with github.com/BeRo1985/kraft@8e4c714960 now. :-)

It should also be fixed with https://github.com/BeRo1985/kraft/commit/8e4c714960e6c79e8d5bb1267b42aab4b0719d66 now. :-)
and3md commented 2023-05-10 19:19:58 +00:00 (Migrated from github.com)

Thanks :)

Thanks :)

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
BeRo1985/kraft!29
No description provided.