TSpaceImposter


Croquet-Teapot

Comment:

TSpaceImposter

This class is used as a place holder for a complete space when it is viewed through a portal. It is a portal connected to a TSpace containing only a cube where the surfaces are rendered from the position of the connected frame. This gives the portal a true 3D effect without having to transfer the entire world.

Hierarchy:

ProtoObject
Object
TObject
TFrame
TPrimitive
TRectangle
TPortal
TSpaceImposter

Summary:

instance variables:

box pixWidth space

methods:

instance class
initialize instance creation

Detail:

instance variables:

box
pixWidth
space

instance methods:

initialize
generateView: spc transFrom: tf transTo: tt extent: ext


	| ogl rect form txtr shrink smallForm file |
	ogl _ Processor activeProcess croquetWorld renderer ogl.
	ogl ifNotNil: [
		"We render 4x larger than we use, because we want to sample it down. This gives us a
		 nicer picture with fewer pixelated artifacts."
		rect _ 0@0corner:(pixWidth@pixWidth)*4.
		form _ spc snapShot: ogl rectangle:rect atLoc: tf view: 90.
		]
		ifNil: [
		file _ CroquetData findTextureFileName: 'checker.bmp'.
		form _ Form fromFileNamed: file.
		].
	smallForm _ Form extent: pixWidth@pixWidth depth: 16.
	form displayScaledOn: smallForm.
	txtr _ TTexture new initializeWithForm: smallForm mipmap: true shrinkFit: false.
	txtr material: material.
	txtr extent: ext@ext.
	txtr localTransform: tt.
	txtr solid: false.
	shrink _ (pixWidth - 1)/pixWidth.
	txtr translation:  (tt localPointToGlobal: 0@0@((shrink*ext/-2.0))).
	box addChild: txtr.
initializeWithSpace: spc transform: transform


	| ext tt trans orient |
	super initialize.
	material _ TMaterial new.
	material fullBright: true.
	material ambientColor: #(1.0 1.0 1.0 1.0)asFloatArray.
	material diffuseColor: #(1.0 1.0 1.0 1.0)asFloatArray.
	material emissiveColor: #(1.0 1.0 1.0 1.0)asFloatArray.

	ext _ 164.
	pixWidth _ 64.
	space _ TSpace new.
	space addChild: self.
	box _ TGroup new.
	box rotationAroundY:180.
	space addChild: box.
	trans _ transform translation.
	orient _ transform orientation.
	self renderOffscreen: [
	self generateView: spc transFrom: transform transTo: B3DMatrix4x4 identity extent: ext.
	tt _ B3DMatrix4x4 identity rotationAroundY:90.
	self generateView: spc transFrom: ((orient composeWith: tt) translation: trans) 
		transTo: tt extent: ext.
	tt _ B3DMatrix4x4 identity rotationAroundY:180.
	self generateView: spc transFrom: ((orient composeWith: tt) translation: trans) 
		transTo: tt extent: ext.
	tt _ B3DMatrix4x4 identity rotationAroundY:270.
	self generateView: spc transFrom: ((orient composeWith: tt) translation: trans) 
		transTo: tt extent: ext.

	tt _ B3DMatrix4x4 identity rotationAroundX:90.
	self generateView: spc transFrom: ((orient composeWith: tt) translation: trans) 
		transTo: tt extent: ext.
	tt _ B3DMatrix4x4 identity rotationAroundX:-90.
	self generateView: spc transFrom: ((orient composeWith: tt) translation: trans) 
		transTo: tt extent: ext.
	].
renderOffscreen: aBlock

	| ogl |
	ogl _ Processor activeProcess croquetWorld renderer ogl.
	ogl ifNotNil: [
		ogl renderWait: aBlock.
		]
		ifNil: [
		aBlock value.
		].

class methods:

^top


- made by Dandelion -