Results 1 to 3 of 3

Thread: Collisions in webgl. Can you do it with a shader?

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    13

    Collisions in webgl. Can you do it with a shader?

    Hi all, excuse my pseudo code.

    Can you confirm my method for determining collisions.

    I have given my player model a bounding cube (so i dont have to check all the humps and bumps colliding, rather just one plane).

    I know that the plane that faces the direction im walking can be represented by 3 vertices:

    Code :
    var frontPlane = [p1, p2, p3] //gives a way of measuring distance from player to object points
    var normalOfFrontPlane = [v1x, v1y, v1z] //gives a direction of that plane

    I know that the current object (objects that are not my player) I'm iterating through has many normals/planes.

    If I find the dot product (cosine) between my players normalFrontPlane and all the normals on the object im currently checking.

    Code :
    if ( cos <= 90 )

    then find the distance between any 2 points on that plane (including the vertices that create the plane itself) -

    Code :
    sqrt((x2-x1) + (y2-y1) + (z2-z1))

    if that distance is <= playerMaxCloseness, then movement stops.

    Does that sound right? If so.. great. tell me, coz im unsure.
    Second question is, is there a better way to do all this in the shader file?
    It seems like this operation would be quite slow?

  2. #2
    Junior Member
    Join Date
    Feb 2012
    Posts
    13

    Re: Collisions in webgl. Can you do it with a shader?

    Too late to edit but.. < 90, not <= 90. thatd be dumb

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    13

    Re: Collisions in webgl. Can you do it with a shader?

    I did a simple sqrt(x + y + z). thats from player origin to each point on all the objects and if the distance is > 2, then move.

    But it's so flimsy.

    If i have a very long wall.. i need to know if i hit into that too.. so im gnna have to "cast a ray" from my player and interpolate the wall.. but surely thats gnna be slow.. is there a way of doing this shiz in the shader?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •