Results 1 to 6 of 6

Thread: Spheres and Cylinder using triangles?

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2001
    Posts
    3

    Spheres and Cylinder using triangles?

    I am looking for an algorithm to generate
    spheres, cylinders, and arcs with triangles
    only. I want to provide the dimensions of the shape (ie. radius, coordinates, height) and have an object composed of triangles.

    Basically what Im trying to do is do some collision detection using coldet. From my understanding, you have to have a shape consisting of triangles and... I want to test collisions on these shapes.

    If there is an easier way, please let me know. I just figured that there was a script or something already out there to do the shape conversions to triangles and that it would be pretty painless.

    Thanks for any help.
    -Thorrin

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Aug 2000
    Location
    Cardiff University
    Posts
    653

    Re: Spheres and Cylinder using triangles?

    Maybe useless but the red book (and in the sample gl code in the sdk) has recursive funcs for sphere generation.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Oct 2001
    Location
    Holland
    Posts
    179

    Re: Spheres and Cylinder using triangles?

    You could take a look at the GLUT sourcecode (or even use GLUT), since it contains glutSolidSphere() which generates spheres build out of QUADs.
    And it is quite easy to split each quad in two triangles using the same vertices.

    HTH

    Jean-Marc.

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Sep 2000
    Location
    SWEDEN
    Posts
    601

    Re: Spheres and Cylinder using triangles?

    If you're just going to use it for collision detection, composing those primitives into triangles is a bad way of doing it. You get less exact shapes, and they're much slower to test against. Instead, use specialised code to check for intersections between spheres, cylinders and other simple geometric primitives. Check out http://www.realtimerendering.com/int for lots of intersection formulas and code.

  5. #5
    Junior Member Newbie
    Join Date
    Oct 2001
    Posts
    3

    Re: Spheres and Cylinder using triangles?

    Thanks for the suggestions guys! I'll let you know how things turn out.

    -Thorrin

  6. #6
    Junior Member Newbie
    Join Date
    Oct 2001
    Posts
    3

    Re: Spheres and Cylinder using triangles?

    Well, just in case anyone is interested...

    Cylinders were pretty easy to triangulate! All you need to do is:

    1) Divide a circle into 'x' parts. 32 looked pretty nice.

    2) Get the sin and cos for each of the 32 sections and you have your (x,y) pair for your triangles. Store these in an array.

    3) Draw triangles between each x,y pair, the x,y pair next to it on the circle(ie x+1, y+1), and the center of the circle. If your circle is looking jagged, add more points.

    4) Do the same thing for the bottom of the circle, but translate into the screen a bit on the Z axis (behind the 1st circle).

    5) Now, go through each pair again, only this time your triangles go between the two circles. You draw triangles between:

    a) (x,y), (x+1, y+1) in the top circle and
    (x,y) in the bottom circle.

    b) (x,y), (x+1, y+1) in the bottom circle,
    (x+1, y+1) in the top circle...

    Now you have a cylinder looking 'at' you. It will look like a circle until you rotate the object. Best/easiest way to do this is to modify one of the nehe tutorials so it can be interactive...

    This is one of those 'a picture is worth a thousand words' kind of messages, but just read it again and you will get what I'm trying to say!

    I found this code for spheres... http://www.cs.unc.edu/~jon/

    -Thorrin

Similar Threads

  1. a line from surface of the cylinder to spheres
    By tuban in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 02-03-2010, 11:12 AM
  2. Spheres
    By in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 12-09-2004, 01:43 AM
  3. Spheres
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-23-2004, 06:31 AM
  4. Two Spheres ..
    By glcrazy in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 12-05-2003, 02:36 AM
  5. Spheres
    By orate! in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-23-2002, 01:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean