Page 1 of 3 123 LastLast
Results 1 to 10 of 25

Thread: Collision Slide Effect for 3DS Objects

  1. #1

    Collision Slide Effect for 3DS Objects

    Hi there,

    note: i use Delphi and OpenGL for programming

    how to make a slide collision between 2 or more 3DS Objects?
    for example:
    -i have a player(3DS or something)
    -i have a world(1 3DS or more created to 1 world)

    i dont need a 3DS to 3DS collision detection, it will also
    work with a Sphere or Cylinder collision detection.
    but i need a SLIDE effect!

    ive thinking a lot, but dont get an answer, at time my head will explode :roll:

    Thanks a lot for help
    Daikrys

  2. #2

    Collision Slide Effect for 3DS Objects

    uh? :cry:

    nobody can help me?
    ok i find this link http://nehe.gamedev.net/data/lessons....asp?lesson=30
    but i dont understand it :?
    i think my english is to bad or iam to silly

    if someone understand this tutorial(and i think many would understand it)
    can u write a simple short help for cylinder or sphere collision?
    if its easier it would work with cylinder-cylinder collision

    can anyone help me plz?

  3. #3

    Collision Slide Effect for 3DS Objects

    Hi Daikrys, and welcome!

    Well if i understand well, you just have to implement a sphere to sphere (or cylinder) collision.

    To see if two spheres are colliding, you just need to calculate the distance D between them, and then check if D is smaller then the sum of the two radius:

    if r1+r2 >= D then collision!

    This apply for both 3d and 2d (circles).
    Now, if you want a sphere to slide along another (if i understood correctly), you need some little complex calculation.

    I'm not too good with this.. I'll try to read the tutorial and see if i get it

    But is your world truly 3d? Becouse if the character can just move in four direction on a plane, then you can just use 2d circle collision.

    Bye!
    If you save your data in a proprietary format, the owner of the format owns your data.
    <br /><A href="http://msx80.blogspot.com">http://msx80.blogspot.com</A>

  4. #4

    Collision Slide Effect for 3DS Objects

    much thanks

    i think i understand what u mean
    first i try to use 2d collision, it will work for now
    but i think i need 3d collision later :roll:

    thank u again for trying to read the tutorial, i hope u can help me
    with the slide effect

    what mean the first parameter by glusphere?
    Code:
    GLusphere&#40;gluNewQuadric, radius,singlevar1,singlevar2&#41;;
    can anyone give me an example plz?

    or how i can create a sphere?

  5. #5

    Collision Slide Effect for 3DS Objects

    Quote Originally Posted by Daikrys
    what mean the first parameter by glusphere?
    Code:
    GLusphere&#40;gluNewQuadric, radius,singlevar1,singlevar2&#41;;
    can anyone give me an example plz?

    or how i can create a sphere?
    The first parameter is the quadric that you have to create before use.

    [pascal]
    sphereObj := gluNewQuadric();
    gluSphere(sphereObj, r, a, b);
    // ....
    // after use, delete it:
    gluDeleteQuadric(sphereObj)
    [/pascal]
    If you save your data in a proprietary format, the owner of the format owns your data.
    <br /><A href="http://msx80.blogspot.com">http://msx80.blogspot.com</A>

  6. #6

    Collision Slide Effect for 3DS Objects

    ok here it is the collisionscode for circle collision
    i use gludisk to create a circle

    [pascal]
    function check(x,y,size : single): boolean;
    var d:single;
    begin
    d:=sqr(x)+sqr(y);
    if d<=sqr(size+0.3) then result:=true else result:=false;
    end;

    procedure Render;
    var i: integer;
    rotation,xpos,ypos: double;
    sphereobj: gluquadricobj;
    begin
    glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
    glLoadidentity;

    glpushmatrix();
    gltranslatef(0,0,-6);

    glcolor3f(1,1,1);
    sphereobj:=glunewquadric();
    gludisk(sphereobj,0,0.3,12,1);
    gluDeleteQuadric(sphereObj);

    glpopmatrix();

    glpushmatrix();
    gltranslatef(posx,posy,-6);

    glcolor3f(1,1,1);
    sphereobj:=glunewquadric();
    gludisk(sphereobj,0,0.3,12,1);
    gluDeleteQuadric(sphereObj);

    glpopmatrix();

    if check(posx,posy,0.3) then Form1.Caption:='Collision!' else Form1.Caption:=nope!';

    SwapBuffers(myDC);
    end;
    [/pascal]

    so how to make a slide collision?

  7. #7

    Collision Slide Effect for 3DS Objects

    ok, i'd do this way for collision with slide:
    When 2 sphere collide, you find how much they compenetrate, that is

    compenetration := distance - (size1+size2);

    now, you must pull them "apart" by that value.
    You can choose how to distribute it between the two object. If one of them is fixed, just add all compenetration value to the other, elseway you can distribute it half way (so it will be possible to push something).

    The problem is that compenetration value is a scalar, so you need to obtain a vector of that dimension.
    Now the vector happends to be the subtraction between the positions (that must be normalized and scaled):

    [pascal]
    var
    comp,d:TFloat;
    v:TVector;
    // find compenetration value
    comp := distance(a.position, b.position)-(size1+size2);
    if d<0 then // if collide
    begin
    // find vector distance (it will have length=distance, no good, must be normalized)
    v:=sub(a.position,b.position);
    // normalize the vector, now direction is ok, and length is 1
    normalize(v);
    // make length equal to compenetration value
    scale(v,d);
    // ok, now vector points from a to b, length d. We subtract from position
    // so it will be pulled away
    a.position:=sub(a.position,v);
    end;
    [/pascal]

    That's it. If you want to distribute "sliding" between the two object, you can change it to:

    [pascal]
    // make length equal to half compenetration value
    scale(v,d/2);
    // pull them apart
    a.position:=sub(a.position,v);
    b.position:=add(b.position,v); // this is added becous v already points away from it
    [/pascal]

    Ok, this should work. IHTH
    If you save your data in a proprietary format, the owner of the format owns your data.
    <br /><A href="http://msx80.blogspot.com">http://msx80.blogspot.com</A>

  8. #8

    Collision Slide Effect for 3DS Objects

    hi again,

    iam back from my girlfriend and ready for programming

    ok i understand some of them but what are scale and normalize? :|
    if that a function or procedure i dont find it ops:
    or what are u mean by that?

    i hope it isnt that stupid question i think it is :toothy:

  9. #9

    Collision Slide Effect for 3DS Objects

    Quote Originally Posted by Daikrys
    hi again,

    iam back from my girlfriend and ready for programming
    Ehehe good for you
    ok i understand some of them but what are scale and normalize? :|
    if that a function or procedure i dont find it ops:
    or what are u mean by that?

    i hope it isnt that stupid question i think it is :toothy:
    As we say: there's no stupid questions, only stupid answares

    Scale and normalize are two operation you can do with vectors.
    As you know each vector (2d, 3d, and all others) have a length, (that can be calculated as: sqrt( x^2 + y^2 ), that is the suare root of the sum of all members squared).
    Now if a vector have length 1 it is said to be normalized. Normalized vectors have special properties that comes handy.
    Normalizing a vector means making it's length 1. So if a vector has length 15 then you divide each element by 15 and get a vector that's normalized (it points in the very same direction but it's length's 1)
    Here's the code:

    [pascal]
    procedure Normalize(var Vec:TVector);
    var Mag : TFloat;
    begin
    Mag := Magnitude(Vec); // the length
    vec.x := Vec.x / Mag;
    vec.y := Vec.y / Mag;
    end;
    [/pascal]

    The scale is similar, it means that you multiply the length of a vector by a given number. If you scale a vector with length 5 by 2 you obtain a vector (that points in the same direction) with length 10.
    Here's the code for scale:

    [pascal]
    procedure Scale(var vec:TVector; ascale:TFloat);
    begin
    vec.x := Vec.x * ascale;
    vec.y := Vec.y * ascale;
    end;
    [/pascal]

    IHTH
    Bye!
    If you save your data in a proprietary format, the owner of the format owns your data.
    <br /><A href="http://msx80.blogspot.com">http://msx80.blogspot.com</A>

  10. #10

    Collision Slide Effect for 3DS Objects

    ok i do something....(wrong)....

    As we say: there's no stupid questions, only stupid answares
    Thanks

    can u watch my sample and correct them?

    download it here:
    http://daikrys.funpic.de/collide.zip

    Thanks

    i gonna sleep
    good night

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

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