SLIDING DOOR

At this lesson we have 2 new pieces. The Plate13x05x13 is very simple and will be used like a roof for the room we are constructing.

Please download these files:

wallDoor12x7x1.ase - in the folder wallDoor12x7x1

wallDoor12x7x1.jpg - in its subfolder Textures

Pbutton.jpg - in its subfolder Textures

door1.jpg - in its subfolder Textures

plate13x05x13.ase - in the folder plate13x05x13

plate13x05x13.jpg - in its subfolder Textures

After this you need to create a new Class for each piece: WallDoor12x7x1 and Plate13x05x13 - capitalized.

At the piece WallDoor12x7x1 we have something new! A part of the piece has a name (defined in 3ds max): door.

The creation of the Class has some "instance variables":

TGroup subclass: #WallDoor12x7x1
	instanceVariableNames: 'inControl tframe door  open '
	classVariableNames: ''
	poolDictionaries: ''
	category: 'MyCroquet'

The "initialize" method for the Class of the Plate is obvious. But for the WallDoor has something new:

initialize

super initialize.
open:=false.

tframe := (TLoad3DSMax new initializeWithFileName: 
	   (FileDirectory pathFrom:
           {FileDirectory default pathName.  'Content'.   'wallDoor12x7x1'. 'wallDoor12x7x1.ase'}) 
	   scale: 0.1 shadeAngle: 90.1 textureMode: GLReplace) frame.
tframe collapse.
tframe boundsDepth: 3.
tframe initBounds.
self addChild: tframe.
tframe objectOwner: self.
"Finding door"
door := (tframe find:[:frm | frm objectName = 'door']) at: 1. 
inControl := false. 

CODE COMMENTS

Now, the action !

The method keyDown:pointer for the Plate is similar we have seeing. But look that for the WallDoor:

keyDown: pointer

| c |
c := pointer event2D keyCharacter.
"To move X+" 
c = $w ifTrue:[ 
 tframe translation:  tframe translation+( tframe localTransform column1*0.5).			 
 inControl := true.
].
"To move X-" 
c = $s ifTrue:[  
  tframe translation:  tframe translation-( tframe localTransform column1*0.5).	
 inControl := true.
].
"To turn left"
c = $a ifTrue:[  
  tframe addRotationAroundY:-1.
 inControl := true.
].
"To turn right"
c = $d ifTrue:[  
   tframe addRotationAroundY: 1.			 
 inControl :=true.
].
"To go up:Y+"
c = $z ifTrue:[ 
 tframe translation:  tframe translation+( tframe localTransform column2*0.5).		 
 inControl := true.
].
"To go down (oops!):Y-"
c = $x ifTrue:[  
 tframe translation:  tframe translation-( tframe localTransform column2*0.5).		 
inControl := true.
].
"To move Z+"
c = $c ifTrue:[  
  tframe translation: tframe translation+( tframe localTransform column3*0.5).		 
 inControl:= true.
].
"To move Z-"
c = $v ifTrue:[ "Z-" 
  tframe translation:  tframe translation-( tframe localTransform column3*0.5).		 
 inControl := true.
].

 
"To open/cloce door"
c = $p ifTrue:[
  door := (tframe find:[:frm | frm objectName = 'door']) at: 1. 
  open=false ifTrue:[
   door translation: door translation+(door localTransform column1*5).
   open:=true.
  ]
  ifFalse:[	 
  door translation: door translation-(door localTransform column1*5).
  open:=false.
  ].
  inControl := true.
].

CODE COMMENTS

Look the code of its method:
initializeDefaultSpace 

| space    base  w1 wW1 wD1 wD2 pT1 |
"Create a new space"
space := TSpace new.
"Make a light"
self makeLight: space.
 
base:=BasePlate70x3x70 new.
space addChild:base.
 
w1:=Wall12x7x1 new.
space addChild:w1.
w1 translationX: 5 y: 0 z: 10.

wW1:=WallWindow12x7x1 new.
space addChild:wW1.
wW1 translationX: 20 y: 0 z: -10.

wD1:=WallDoor12x7x1 new.
space addChild:wD1.
wD1 translationX: 30 y: 0 z: -20.

wD2:=WallDoor12x7x1 new.
space addChild:wD2.
wD2 translationX: 0 y: 0 z: -20.
 
pT1:=Plate13x05x13 new.
space addChild:pT1.
pT1 translationX: -10 y: 10 z: -10.
 
^space.

CODE COMMENTS

And "do-itizing" the "script-for-Workspace" we can play with our pieces in the Private space.

TIP: The red button in the wall having the door is a "dirt trick". The user can "mouse-over" any part of the wall and press "P" to open/close the door.

Look our photo album :




PREVIOUS LESSON NEXT LESSON
T. CONTENTS HOMEPAGE

DISCLAIMER: This material can be translated for any language, and reproduced total or partially by anybody using any type of media. But, please, don't put your name like author. And let me know if it was useful (americo@dmu.com).The use of any code, 3D model or technique published is free and doesn't need to have any reference about this source.The author is not responsible for any damage that the material can cause to your professional or sexual life.