gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > create 3D cylinder

#169409 - achu18 - Thu Jul 09, 2009 6:51 am

hi all,
trying to create a 3D cylinder without using a model(3D picking example from devkitpro) any suggestions?

#169414 - kusma - Thu Jul 09, 2009 10:29 am

connect two circles with a triangle strip?

#169425 - achu18 - Fri Jul 10, 2009 12:29 am

thanx for the reply kusma
i tried drawing a circle, but it just slows every thing down dramatically.

glBegin(GL_TRIANGLES);
for(i=0;i<=360;i++)
{
angle=(float)(((double)i)/57.29577957795135);
vectorX=originX+(radius*(float)sin((double)angle));
vectorY=originY+(radius*(float)cos((double)angle));
glVertex3f(originX,originY, 1.0f);
glVertex3f(vectorX1,vectorY1, 1.0f);
glVertex3f(vectorX,vectorY, 1.0f);
vectorY1=vectorY;
vectorX1=vectorX;
}
glEnd();
is there an efficient way of rendering a circle?
mind you what iam trying to do is have a cylinder just bounce off the edges of the screen. use the keys to flip/rotate it.
really appreciate your help!

#169426 - vuurrobin - Fri Jul 10, 2009 1:10 am

the ds doesn't have a floating point unit which makes using float and double very slow.

use fixed point instead.

http://www.coranac.com/tonc/text/fixed.htm

#169427 - elhobbs - Fri Jul 10, 2009 3:18 am

also, do not forget you are trying to render a cylinder on the fairly low resolution screen of the ds. you do not need double precision floating point values.

one approach is to draw a single quad with a circle texture on it. or you could make it an octogon instead of a circle. a 360 sided polygon is extreme overkill for the ds - that is nearly 20% of the triangle budget for a frame on the ds.

#169428 - achu18 - Fri Jul 10, 2009 5:35 am

hi elhobbs,
i tried the single quad (square) with a circle for texture(red circle in a transparent square). looks fine from the top, but when i try to look at its "depth", i get horrible blanks along the edges. i will look at the octagon approach with some circular texturing, if someone can advice me on the "smoothing the edges"??
cheers

#169471 - silent_code - Tue Jul 14, 2009 4:22 pm

You can precompute a few values, too, so that you don't need to call any trigonometric functions. That should be easy. ;^)
Oh, and a 24 sided cylinder looks just fine on the NDS. :^)
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.