[comp.sys.sgi] libsphere - how do I get a sphere into an object?

merritt@milton.u.washington.edu (Ethan Merritt) (11/02/90)

I have been playing with libsphere on a PI under 3.3.1.  I like it,
but I haven't been able to figure out how to get spheres into a graphics
object.  The example in 4Dgifts/src/sphere doesn't use objects, so that
hasn't helped.

The simple-minded approach:
		makeobj( sphere_object );
		sphdraw( &params[i] );
		closeobj();
produces nothing when the corresponding callobj( sphere_object ) is done.

The library routine sphobj() looks relevent, but the documentation is,
shall we say, terse.  Calling sphobj( sphereobj ) seems to draw a sphere
into sphereobj all right, but always at the origin (I think).  Anyway
preceding the call with a move( x,y,z ) call seems to have no effect.
I.e.:
	sphobj( sphere_object );
	makeobj( spheres );
	for (i = 0; i < nspheres; i++ )
		{
		move( &xyz[i] );
		callobj( sphere_object );
		}
	closeobj();
	callobj( spheres );
doesn't seem to do anything other than pile up spheres on top of each other.

Can anyone enlighten me?

				thanks,
				            Ethan A Merritt
------------------------------------------------------------------------------
Dept of Biological Structure                H510 Health Sciences
University of Washington SM-20              (206)543-8865
Seattle, WA 98195                           MERRITT@XRAY0.BCHEM.WASHINGTON.EDU
------------------------------------------------------------------------------

kurt@cashew.asd.sgi.com (Kurt Akeley) (11/06/90)

In article <10445@milton.u.washington.edu>,
merritt@milton.u.washington.edu (Ethan Merritt) writes:
|> I have been playing with libsphere on a PI under 3.3.1.  I like it,
|> but I haven't been able to figure out how to get spheres into a graphics
|> object.  The example in 4Dgifts/src/sphere doesn't use objects, so that
|> hasn't helped.
|> 
|> The simple-minded approach:
|> 		makeobj( sphere_object );
|> 		sphdraw( &params[i] );
|> 		closeobj();
|> produces nothing when the corresponding callobj( sphere_object ) is done.
|> 
|> The library routine sphobj() looks relevent, but the documentation is,
|> shall we say, terse.  Calling sphobj( sphereobj ) seems to draw a sphere
|> into sphereobj all right, but always at the origin (I think).  Anyway
|> preceding the call with a move( x,y,z ) call seems to have no effect.
|> I.e.:
|> 	sphobj( sphere_object );
|> 	makeobj( spheres );
|> 	for (i = 0; i < nspheres; i++ )
|> 		{
|> 		move( &xyz[i] );
|> 		callobj( sphere_object );
|> 		}
|> 	closeobj();
|> 	callobj( spheres );
|> doesn't seem to do anything other than pile up spheres on top of each other.
|> 
|> Can anyone enlighten me?

You're almost there, but you dropped the ball by calling move() to reposition
the spheres.  The way to reposition any GL object, including the sphere
objects, is to redefine the object-to-eye coordinate transformation by calling
translate().  Just replace your move() call with a translate() call and things
should work well.

Sorry for the terse documentation.  Just another case of something that seemed
obvious to us, but is not to others.

-- kurt

mg@ (Mike Gigante) (11/07/90)

kurt@cashew.asd.sgi.com (Kurt Akeley) writes:

]In article <10445@milton.u.washington.edu>,
]merritt@milton.u.washington.edu (Ethan Merritt) writes:
]|> I.e.:
]|> 	sphobj( sphere_object );
]|> 	makeobj( spheres );
]|> 	for (i = 0; i < nspheres; i++ )
]|> 		{
]|> 		move( &xyz[i] );
]|> 		callobj( sphere_object );
]|> 		}
]|> 	closeobj();
]|> 	callobj( spheres );
]|> doesn't seem to do anything other than pile up spheres on top of each other.
]|> 

]You're almost there, but you dropped the ball by calling move() to reposition
]the spheres.  The way to reposition any GL object, including the sphere
]objects, is to redefine the object-to-eye coordinate transformation by calling
]translate().  Just replace your move() call with a translate() call and things
]should work well.

]-- kurt

You probably want
	{
	pushmatrix();
	translate(x, y, z);
	callobj( .. );
	popmatrix();
	}

i.e. wrap a push/pop matrix pair around the translate/callobj,
otherwise each transform will be accumulated with the previous
transforms..  (that is asuming that the x,x,z correspond to the "world
coordinate" position of the spheres)

Mike Gigante, RMIT Australia