TCube generates and renders a simple cube.
ProtoObjectObjectTObjectTFrameTPrimitiveTCube
| changed | extent | location | normals | quadFaces | txtCoords | vertices |
| changed |
|---|
| extent |
|---|
| location |
|---|
| normals |
|---|
| quadFaces |
|---|
| txtCoords |
|---|
| vertices |
|---|
| accessing |
|---|
| boxTop: top bottom: bottom |
self extent: (top - bottom). self location: (bottom + top)/2.0. self boundsChanged. changed _ true. |
| colorize: col |
| mat | mat _ TMaterial new. mat ambientColor: col. mat diffuseColor: col. mat textureMode: GLModulate. self material: mat. |
| extent |
^ extent. |
| extent: ext |
extent _ ext. self boundsChanged. changed _ true. |
| extentX: ex |
extent x: ex. self boundsChanged. changed _ true. |
| extentX: x y: y z: z |
extent x:x y:y z:z. self boundsChanged. changed _ true. |
| extentY: ey |
extent y: ey. self boundsChanged. changed _ true. |
| extentZ: ez |
extent z: ez. self boundsChanged. changed _ true. |
| location |
^ location. |
| location: loc |
location _ loc. self boundsChanged. |
| locationX: x y: y z: z |
location x: x y: y z: z. self boundsChanged. |
| quadFaces |
^ quadFaces. |
| scale: scl |
extent _ extent * scl. self translation: scl * self translation. self boundsChanged. changed _ true. |
| vertices |
^ vertices. |
| as yet unclassified |
|---|
| frameBox |
"Answer the local bounding box of this frame" ^TBox origin: extent/-2.0 corner: extent/2.0. |
| initialize |
|---|
| initBounds |
boundSphere _ TBoundSphere localPosition: location radius: (extent length)/2. boundSphere frame: self. |
| initialize |
super initialize. extent _ B3DVector3 x: 1.0 y: 1.0 z: 1.0. location _ B3DVector3 x: 0.0 y:0.0 z:0.0. self initBounds. changed _ true. self update. ^self. |
| update |
| dx dy dz x y z | dx _ extent x/2.0. dy _ extent y/2.0. dz _ extent z/2.0. x _ location x. y _ location y. z _ location z. vertices _ B3DVector3Array new: 8. vertices at: 1 put: (B3DVector3 x: x+(dx negated) y: y+(dy negated) z: z+dz). vertices at: 2 put: (B3DVector3 x: x+dx y: y+(dy negated) z: z+dz). vertices at: 3 put: (B3DVector3 x: x+dx y: y+ dy z: z+dz). vertices at: 4 put: (B3DVector3 x: x+(dx negated) y: y+dy z: z+dz). dz _ dz negated. vertices at: 5 put: (B3DVector3 x: x+(dx negated) y: y+(dy negated) z: z+dz). vertices at: 6 put: (B3DVector3 x: x+dx y: y+(dy negated) z: z+dz). vertices at: 7 put: (B3DVector3 x: x+dx y: y+ dy z: z+dz). vertices at: 8 put: (B3DVector3 x: x+(dx negated) y: y+dy z: z+dz). normals _ B3DVector3Array new: 6. normals at: 1 put: (B3DVector3 x: 0.0 y: 0.0 z: 1.0). normals at: 2 put: (B3DVector3 x: 0.0 y: 0.0 z: -1.0). normals at: 3 put: (B3DVector3 x: 1.0 y: 0.0 z: 0.0). normals at: 4 put: (B3DVector3 x: -1.0 y: 0.0 z: 0.0). normals at: 5 put: (B3DVector3 x: 0.0 y: 1.0 z: 0.0). normals at: 6 put: (B3DVector3 x: 0.0 y: -1.0 z: 0.0). quadFaces _ #(1 2 3 4 8 7 6 5 2 6 7 3 1 4 8 5 4 3 7 8 1 5 6 2) asIntegerArray. txtCoords _ B3DVector2Array new: 4. txtCoords at: 1 put: (B3DVector2 x: 1.0 y: 0.0). txtCoords at: 2 put: (B3DVector2 x: 0.0 y: 0.0). txtCoords at: 3 put: (B3DVector2 x: 0.0 y: 1.0). txtCoords at: 4 put: (B3DVector2 x: 1.0 y: 1.0). changed _ false. |
| render |
|---|
| pick: pointer |
| faceCount | faceCount _ 1. normals do: [ :norm | (pointer pickQuad: norm q1: (vertices at: (quadFaces at: faceCount)) q2: (vertices at: (quadFaces at: faceCount+1)) q3: (vertices at: (quadFaces at: faceCount+2)) q4: (vertices at: (quadFaces at: faceCount+3))) ifTrue:[^ true]. faceCount _ faceCount+4.]. ^ false. |
| renderPrimitive: ogl |
| faceCount uv tc | changed ifTrue: [self update]. uv _ 1@1. self texture ifNotNil:[uv _ self texture uvScale.]. faceCount _ 1. ogl glBegin: GLQuads. normals do:[ :norm | ogl glNormal3fv: norm. 1 to: 4 do:[ :cnt | tc _ (txtCoords at: cnt) copy. tc x: (tc x*uv x) y:(tc y*uv y). ogl glTexCoord2fv: tc; glVertex3fv: (vertices at:(quadFaces at: faceCount)). faceCount _ faceCount+1.].]. ogl glEnd. |