Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Hey, I drew many small cylinders. First, I used a array to store all data, e.g. {x1,y1,z1,x2,y2,z2,x3,y3,z3}.
I wrote a function that can draw a cylinder according to two inputted points (x1,y1,z1) and (x2,y2,z2), or (x2,y2,z2) and (x3,y3,z3). Here is the function. public static void drawCylinder(GL2 gl2, double x1, double y1, double z1, double x2, double y2, double z2, double radius) { double dx = x2 - x1; double dy = y2 - y1; double dz = z2 - z1; double distance = Math.sqrt(dx*dx + dy*dy + dz*dz); double px = x1; double py = y1; double pz = z1; double bx = px; double by = py; double bz = distance + pz; double sx = bx - x1; double sy = by - y1; double sz = bz - z1; double fx = sy * dz - dy * sz; double fy = sz * dx - sx * dz; double fz = sx * dy - dx * sy; double ax = x2 - bx; double ay = y2 - by; double az = z2 - bz; double length = Math.sqrt(ax * ax + ay * ay + az * az); float angle = (float)(Math.acos((distance*distance*2 - length*length)/(2*distance*distance))*180.0f / Math.PI); GLUT glut = new GLUT(); gl2.glPushMatrix(); gl2.glTranslated(x1, y1, z1); gl2.glRotated(angle, fx, fy, fz); glut.glutSolidCylinder(radius, distance, 32, 32); gl2.glPopMatrix(); } There are many small gaps like this: ![]() |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Administrator
|
Hi
Use gluCylinder with 2 different values at the base and at the top. It's more flexible than glutSolidCylinder.
Julien Gouesse | Personal blog | Website
|
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
I don't get it. How does it make the gaps disappear? I tried. I looks like this
![]() |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Administrator
|
Actually, you can keep your source code unchanged to draw the cylinders with glutSolidCylinder and you can draw some cylinders with different radius at the top and at the base to fill your gaps with gluCylinder.
Julien Gouesse | Personal blog | Website
|
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Hi, I still don't get it. I wrote a demo to explain it. First, I drew c1 according to p(0,0,0) and p(0,0,1), and c2 according to p(0,0,1) and p(1,0,2),
![]() Then I calculated the angle between two cylinders and drew many disks to fill the gap. It works well when there is only one gap. But it slows down the project since there are so many gaps in the real project. ![]() You said I could use gluCylinder with different base and top value to fill the gaps. How to set the base and top that can perfectly fit the gaps? |
Free forum by Nabble | Edit this page |