TTriangle is a TPrimitive used to render triangles. This creates and renders your simple OpenGL triangle. Usually used for testing, but you have to start somewhere...
ProtoObjectObjectTObjectTFrameTPrimitiveTTriangle
| normal | v1 | v2 | v3 |
| instance | class |
|---|---|
| accessing initialize render | no messages
|
| normal |
|---|
| v1 |
|---|
| v2 |
|---|
| v3 |
|---|
| accessing |
|---|
| v1: vv1 v2: vv2 v3: vv3 |
v1 _ vv1. v2 _ vv2. v3 _ vv3. normal _ nil. self boundsChanged. |
| initialize |
|---|
| initBounds |
| d1 d2 d3 c1 c2 c3 c radius center| " Graphics Gems 1 - page 22" d1 _ (v2-v1) dot: (v2-v1). d2 _ (v3-v2) dot: (v1- v2). d3 _ (v1-v3) dot: (v2-v3). c1 _ d2*d3. c2 _ d3*d1. c3 _ d1*d2. c _ c1+c2+c3. radius _ ((d1+d2)*(d2+d3)*(d3+d1)/c)sqrt * 0.5. center _ (((c2+c3)*v1) + ((c3+c1)*v2) + ((c1+c2)*v3))/(2*c). boundSphere _ TBoundSphere localPosition: center radius: radius. boundSphere frame: self. |
| initialize |
| c h | super initialize. h _ (1-(0.5*0.5))sqrt. c _ ((0.5*0.5)/h )negated. v1 _ B3DVector3 x: 0.0 y:h+c z: 0.0. v2 _ B3DVector3 x: -0.5 y:c z: 0.0. v3 _ B3DVector3 x: 0.5 y:c z:0.0. self initBounds. normal _ (v1 cross: v2) normalized. ^self |
| render |
|---|
| pick: pointer |
^ pointer pickTriangle: normal tri: v1 tri: v2 tri: v3. |
| renderPrimitive: ogl |
normal ifNil: [ normal _ (v1 cross: v2) normalized.]. ogl glBegin: GLTriangles; glNormal3fv: normal; glTexCoord2f:0.5 with: 0.0; glVertex3fv: v1; glTexCoord2f:1.0 with:1.0; glVertex3fv: v3; glTexCoord2f:0.0 with:1.0; glVertex3fv: v2; glEnd. |