TCamera
Croquet-Teapot
Comment:
The z value of the camera matrix actually points away from the direction of view. This seems to be a standard approach for OpenGL.
instance variables:
viewPort
Typically the underlying morph in this implementation. Any valid OpenGL buffer should work.
bounds
Usually nil, which means that its actual value will be derived from the bounds of the current viewPort. bounds is the area that is rendered into. You can set this (#bounds:) to have an explicit hard value.
viewAngle
This is the view angle of the camera measured top to bottom. The default is 45 degrees, which means that the angle of the top and bottom edges of the rendered image are 45 degrees apart.
zNear, zFar
The near and far clipping planes in the graphics engine.
zScreen
This is the z distance from the camera that the virtual screen would be. That is, when you have an x,y location on the real screen, you can add the zScreen value (x,y,zScreen) and normalize which gives you an accurate pointing vector in 3D space.
length
Computed by initClipPlanes and used to render the test camera.
clipPlanes, clipPlanesTransform
clipPlanes are the four frustum clip planes defined in the cameras local orientation.
clipPlanesTransform are the four clipPlanes in the cameras global orientation frame. This is what is used to determine if objects are visible inside of the view frustum.
viewClip
This is used to test the visibility culling of the camera. It makes the clipping planes visible. This is obsolete, but it may be useful again if we ever start playing with the object clipping code again.
portalClip
This is an additional clip plane defined by a portal. Objects on the near side of the portal need to be clipped away as well. This is a 4x4 transform.
portalPlane
This is a 3D vector calculated from the portalClip.
inPortal
A flag indicating whether we are rendering a portals contents from this camera or not. This is used to supress certain tests (such as finding floors), and to determine that the avatar should or should not be rendered.
texture
Simply a texture that gets added to the default rendered camera. Not used anymore unless you really need to see the default camera.
killFrame
A flag to indicate that the current rendered image is junk and should not be rendered. This suppresses a swapBuffers call.
goToPortal, goToPortalTransform
When a camera is moved through a portal into a new space, the new portal is set in goToPortal and the new transform inside the new space. Actually, goToPortal can be any valid frame, we are only looking for the root frame.
goToTransform is the global transform that the camera is moved to in the new world. See #skidoo for actual use.
lookAt, lookUp
Vectors that are computed from the global transform. They are the z-vector emerging from the camera in the center of the screen, and the y vector pointing straight up from the cameras view. These are useful for creating new objects directly in front of the camera.
renderInterval
Defines the time between renderings in milliseconds.
Hierarchy:
ProtoObject
Object
TObject
TFrame
TGroup
TCamera
Summary:
instance variables:
methods:
Detail:
instance variables:
instance methods:
| *Jana-Script |
| isPointerDown
|
"Answer whether the pointer is currently pressed on aFrame"
^self pointer isPointerDown
|
| isPointerDownOn: aFrame
|
"Answer whether the pointer is currently pressed on aFrame"
^self pointer isPointerDownOn: aFrame
|
| CIM |
| requestMeetingFrom: sender
|
(self confirm: sender nickname, ' wants to join you.
Do you want to tell him where you are?') ifFalse:[^self].
sender joinMeetingAt: self localTransform clone in: currentSpace.
|
| initialize |
| activate
|
Croquet world activeCamera: self
|
| deactivate
|
Croquet world activeCamera: nil.
|
| frustumChanged
|
|
| initClipPlanes
|
| aspect |
aspect _ self aspect.
length _ 1.0/(((viewAngle/2.0)*(Float pi/180.0))tan).
clipPlanes _ B3DVector3Array ofSize: 4.
clipPlanes at: 1 put: (B3DVector3 x: 0.0 y: length z: 1)normalize negated.
clipPlanes at: 2 put: (B3DVector3 x: 0.0 y: length negated z: 1)normalize negated.
clipPlanes at: 3 put: (B3DVector3 x: length y:0.0 z: aspect)normalize negated.
clipPlanes at: 4 put: (B3DVector3 x: length negated y:0.0 z: aspect)normalize negated.
|
| initFrustum: ogl
|
| radians bnds |
bnds _ self bounds.
radians _ (viewAngle/2.0)*(Float pi/180.0).
ogl initFrustum: viewAngle bounds: ((bnds left@(viewPort bounds height - bnds bottom)) corner: (bnds right @ (viewPort bounds height - bnds top))) zNear: zNear zFar: zFar.
zScreen _ (bnds height/2.0) / (radians tan).
self frustumChanged.
|
| initializeWithViewPort: vp
|
super initialize.
viewPort _ vp.
viewAngle _ 45.0.
zNear _ 0.5.
zScreen _ 0.5. "give it any value - initFrustum gives it a real value"
zFar _ 1500.0.
localTransform _ B3DMatrix4x4 identity.
self singleParent: true.
viewClip _ true.
self initClipPlanes.
inPortal _ false.
killFrame _ false.
self visible: false.
^self
|
| render |
| postRender
|
|
| preRender
|
|
| render: ogl
|
| vert origin scale sLength sAspect |
"This is deprecated code for sure, as there is no longer any way for a camera to render itself, but you never know if you will need to be able to visualize the viewport of a camera and this does just that."
ogl glDisable: GLCullFace.
origin _ B3DVector3 new.
vert _ B3DVector3 new.
scale _ 1.
sLength _ scale * length negated.
sAspect _ scale * self aspect.
ogl glBegin: GLTriangles.
ogl glNormal3fv: ((clipPlanes at:1) negated).
ogl glVertex3fv: origin.
vert x: sAspect y: scale z: sLength.
ogl glVertex3fv: vert.
vert x: sAspect negated y: scale z: sLength.
ogl glVertex3fv: vert.
ogl glNormal3fv: ((clipPlanes at:2) negated).
ogl glVertex3fv: origin.
vert x: sAspect negated y: scale negated z: sLength.
ogl glVertex3fv: vert.
vert x: sAspect y: scale negated z: sLength.
ogl glVertex3fv: vert.
ogl glNormal3fv: ((clipPlanes at:3) negated).
ogl glVertex3fv: origin.
vert x: sAspect y: scale negated z: sLength.
ogl glVertex3fv: vert.
vert x: sAspect y: scale z: sLength.
ogl glVertex3fv: vert.
ogl glNormal3fv: ((clipPlanes at:4) negated).
ogl glVertex3fv: origin.
vert x: sAspect negated y: scale z: sLength.
ogl glVertex3fv: vert.
vert x: sAspect negated y: scale negated z: sLength.
ogl glVertex3fv: vert.
ogl glEnd.
ogl setCull.
texture ifNotNil:[
texture enable: ogl.
ogl glBegin: GLQuads;
glNormal3f: 0.0 with: 0.0 with: -1.0;
glTexCoord2f:0.0 with: 0.0;
glVertex3f: sAspect negated with: scale with: sLength;
glTexCoord2f:1.0 with:0.0;
glVertex3f: sAspect with: scale with: sLength;
glTexCoord2f:1.0 with:1.0;
glVertex3f: sAspect with: scale negated with: sLength;
glTexCoord2f:0.0 with:1.0;
glVertex3f: sAspect negated with: scale negated with:sLength;
glEnd.
texture disable: ogl.].
|
| renderAlpha: ogl
|
| vert origin scale sLength sAspect |
ogl glDisable: GLCullFace.
origin _ B3DVector3 new.
vert _ B3DVector3 new.
scale _ 20.
sLength _ scale * length negated.
sAspect _ scale * self aspect.
ogl glBegin: GLTriangles.
ogl glNormal3fv: (clipPlanes at:1) negated.
ogl glVertex3fv: origin.
vert x: sAspect y: scale z: sLength.
ogl glVertex3fv: vert.
vert x: sAspect negated y: scale z: sLength.
ogl glVertex3fv: vert.
ogl glNormal3fv: (clipPlanes at:2) negated.
ogl glVertex3fv: origin.
vert x: sAspect negated y: scale negated z: sLength.
ogl glVertex3fv: vert.
vert x: sAspect y: scale negated z: sLength.
ogl glVertex3fv: vert.
ogl glNormal3fv: (clipPlanes at:3) negated.
ogl glVertex3fv: origin.
vert x: sAspect y: scale negated z: sLength.
ogl glVertex3fv: vert.
vert x: sAspect y: scale z: sLength.
ogl glVertex3fv: vert.
ogl glNormal3fv: (clipPlanes at:4) negated.
ogl glVertex3fv: origin.
vert x: sAspect negated y: scale z: sLength.
ogl glVertex3fv: vert.
vert x: sAspect negated y: scale negated z: sLength.
ogl glVertex3fv: vert.
ogl glEnd.
ogl setCull.
|
| renderView: ogl
|
self preRender.
ogl camera: self.
ogl reset.
ogl glEnable: GLDepthTest.
ogl viewportOffset: Croquet world morph bounds origin.
ogl clipRect: Croquet world morph bounds.
ogl beginFrame: Croquet teaTime asFloat.
ogl glEnable: GLLighting.
Croquet renderProtect: currentSpace in:
[ :sp |
"------ set up the view frustum ------"
self initFrustum: ogl.
sp renderClear: ogl.
sp renderSpace: ogl.
].
self renderOverlay: ogl.
ogl endFrame.
self postRender.
|
| testBounds: bnds
|
| position pposition d cp fsi |
bnds ifNil: [^ true].
position _ bnds globalPosition - self globalPosition.
"------- test to the near and far clip planes -------"
d _ (self lookAt dot: position) negated.
fsi _ Croquet world frameScaleInverse.
d + bnds radius < (zNear*fsi) ifTrue:[^ false].
d - bnds radius > (zFar*fsi) ifTrue:[^false].
1 to: 4 do:[:i|
cp := clipPlanesTransform at: i.
(0 > ((cp dot: position)+bnds radius)) ifTrue:[ ^ false.]].
" portalClip is the clipping plane of the portal if we happen to be rendering inside of one. "
portalClip ifNotNil:[
pposition _ bnds globalPosition - portalClip translation.
0 > ((portalPlane dot: pposition)+ bnds radius) ifTrue:[ ^ false].
].
^ true
|
| testSphere: pos radius: radius
|
| pposition position plane d fsi |
position _ pos - self globalPosition.
"------- test to the near and far clip planes -------"
plane _ self lookAt.
d _ ( plane dot: position ) negated.
fsi _ Croquet world frameScaleInverse.
d + radius < (zNear*fsi) ifTrue:[^ false].
d - radius > (zFar*fsi) ifTrue:[^false].
"------- test to the four clip planes -------"
1 to: 4
do: [:index | 0 > (((clipPlanesTransform at:index)
dot: position) + radius)
ifTrue: [^ false]].
" portalClip is the clipping plane of the portal if we happen to be rendering inside of one. "
portalClip ifNotNil:[
pposition _ position - portalClip translation.
plane _ B3DVector3 x: portalClip a13 negated y:portalClip a23 negated z: portalClip a33 negated.
0 > ((plane dot: pposition)+ radius) ifTrue:[^ false].
].
^ true
|
| toys |
| jump
|
self translation: self translation + (B3DVector3 x: 0 y: 20 z: 0).
|
class methods:
^top
- made by Dandelion -