Re: Drawing curved lines in VRML

James Waldrop ([email protected])
Mon, 29 May 1995 09:48:57 PDT


This is excellent, thanks. I do have one question, though. I
have gotten as far as using an IndexedFaceSet, although I'm still
trying to figure out how to systematically avoid the "2d half the
triangles aren't there" problem. It's not *quite* as simple as just
building the faces, you have to build them in a particular way it
seems. I do have some very interesting shapes that I'll be putting
on my home page, though. :-)

At any rate, my question is about IndexedLineSet -- my copy of the
draft 1.0 spec doesn't mention it. Is it part of the spec, or would
I be one of the horrid non-compliers if I started using it? ;-)

James

(p.s. My solution for drawing lines using an IndexedFaceSet was to draw
very tight triangles -- it works well enough, so I supposed I don't
*need* IndexedLineSet, but it'd be a lot more efficient.)

Timothy F. Rohaly wrote:
>On May 24, 10:20, James Waldrop wrote:
>> Subject:
>>
>> Here's a simple question for the 3D / Open Inventor experts out there.
>>
>> I need to draw a curved line in VRML. I'm drawing this line on the fly,
>> with a program (cgi-bin for vrml), and I don't know how to do it. :(
>>
>> So, let's say that I had a simple curve of the form:
>>
>> for (y=-10; y <= 10; y++) { x = z = pow(2, y); }
>>
>> This gets me a set of points.
>>
>> How do I draw them? I have some clues, but would appreciate real VRML.
>>
>> Thanks!
>>
>> James
>>-- End of excerpt from James Waldrop
>
>Here is an example program with output:
>------------------------------------------------------------------------------
>--
>
>#include <stdio.h>
>#include <math.h>
>
>/*
> * Program to generate a VRML file for a line given by
> * a functional form. In this case x = z = 2**y.
> *
> */
>main()
>{
> int y;
> float x,z;
>
> printf("#VRML V1.0 ascii\n\n");
> printf("Separator {\n");
> printf(" Coordinate3 {\n");
> printf(" point [\n");
>
> /* Insert your favorite function here */
> for (y = -10; y <= 10; y++) {
> x = z = pow(2, y);
> printf(" %f %f %f,\n", x, (float) y, z);
> }
>
> printf(" ]\n");
> printf(" }\n");
> printf(" IndexedLineSet {\n");
> printf(" coordIndex [\n ");
> for (y = 0; y < 21; y++) { /* This also depends on your function */
> printf("%d, ",y);
> }
> printf("-1,\n");
> printf(" ]\n");
> printf(" }\n");
> printf("}\n");
>
> return 0;
>}
>
>Output:
>------------------------------------------------------------------------------
>--
>
>#VRML V1.0 ascii
>
>Separator {
> Coordinate3 {
> point [
> 0.000977 -10.000000 0.000977,
> 0.001953 -9.000000 0.001953,
> 0.003906 -8.000000 0.003906,
> 0.007812 -7.000000 0.007812,
> 0.015625 -6.000000 0.015625,
> 0.031250 -5.000000 0.031250,
> 0.062500 -4.000000 0.062500,
> 0.125000 -3.000000 0.125000,
> 0.250000 -2.000000 0.250000,
> 0.500000 -1.000000 0.500000,
> 1.000000 0.000000 1.000000,
> 2.000000 1.000000 2.000000,
> 4.000000 2.000000 4.000000,
> 8.000000 3.000000 8.000000,
> 16.000000 4.000000 16.000000,
> 32.000000 5.000000 32.000000,
> 64.000000 6.000000 64.000000,
> 128.000000 7.000000 128.000000,
> 256.000000 8.000000 256.000000,
> 512.000000 9.000000 512.000000,
> 1024.000000 10.000000 1024.000000,
> ]
> }
> IndexedLineSet {
> coordIndex [
> 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
>19
>, 20, -1,
> ]
> }
>}