TSphere


Croquet-Teapot

Comment:

TSphere is a TPrimitive used to render a sphere.

DAS

Hierarchy:

ProtoObject
Object
TObject
TFrame
TPrimitive
TSphere

Summary:

instance variables:

segments

methods:

instance class
accessing initialize render no messages

Detail:

instance variables:

segments

instance methods:

accessing
boundSphere


	^ boundSphere.
boundSphere: bndSphr


	boundSphere _ bndSphr.
localPosition


	^ boundSphere localPosition.
localPosition: pval


	boundSphere localPosition: pval.
	self boundsChanged.
radius

	
	^ boundSphere radius
radius: rval


	boundSphere radius: rval.
	self boundsChanged.
segments

	^ segments
segments: segs

	segments _ segs

initialize
initialize

	super initialize.
	boundSphere _ TBoundSphere localPosition: (B3DVector3 new x:0.0 y:0.0 z:0.0) radius: 1.0.
	boundSphere frame: self.
	segments _ 10.
	^self
		

render
pick: pointer


	^ pointer pickSphere: self boundSphere localPosition 
		radiusSquared: self boundSphere radiusSquared.
render: ogl sphere: bndSphr

	| position radius ringSin ringCos pi2 seg2 vert rts rbs rtc rbc ax u du v dv |

	position _ bndSphr localPosition.
	radius _ bndSphr radius.
	seg2 _ 1+ (segments * 2) .
	ringSin _ FloatArray ofSize: seg2.
	ringCos _ FloatArray ofSize: seg2.
	vert _ B3DVector3 new.
	pi2 _ Float pi *2.0.

	1 to: seg2-1 do:[ :index | 
		ax _ ((index) * pi2)/ (seg2-1).
		ringSin at:index put: ax sin.
		ringCos at:index put: ax cos.].
	ringSin at: seg2 put: (ringSin at: 1).
	ringCos at: seg2 put: (ringCos at: 1).

	rts _ 0.0.
	rtc _ 1.0.
	rbs _ringSin at: 1.
	rbc _ ringCos at: 1.
	du _ 1.0/(seg2-1).
	v _ 0.0.
	dv _ 1.0/segments.
	1 to: segments do:[ :iv |
		ogl glBegin: GLTriangleStrip.
		u _ 0.0.
		1 to: seg2 do: [ :ih | 
			vert x: rts*(ringSin at: ih) y: rtc z: rts*(ringCos at: ih).
			ogl glNormal3fv: vert;
				glTexCoord2f: u with: v;
				glVertex3fv:  (vert * radius)+ position.

			vert x: rbs*(ringSin at: ih) y: rbc z: rbs*(ringCos at: ih).
			ogl glNormal3fv: vert;
				glTexCoord2f: u with: v+dv;
				glVertex3fv:  (vert * radius)+ position.

			u_ u+du.].
		v _ v+dv.
		rts _ rbs.
		rtc _ rbc.
		rbs _ ringSin at: iv+1.
		rbc _ ringCos at: iv+1.
		ogl glEnd.].

renderPrimitive: ogl

	
	self render: ogl sphere:boundSphere.

class methods:

^top


- made by Dandelion -