📄 displayobject3d.as.svn-base
字号:
if( this.culled ){ renderSessionData.renderStatistics.culledObjects ++ ; return 0; } if( parent !== renderSessionData.camera ) this.view.calculateMultiply4x4( parent.view, this.transform ); } else if( parent !== renderSessionData.camera ) this.view.calculateMultiply( parent.view, this.transform ); var screenZs :Number = 0; var children :Number = 0; //To get own containers. if(_useOwnContainer){ } for each( var child:DisplayObject3D in this._childrenByName ) { if( child.visible ) { screenZs += child.project( this, renderSessionData ); children++; } } return this.screenZ = screenZs / children; } /** * TODO : This is broken on the frustum camera. */ private function calculateScreenCoords( camera :CameraObject3D ):void { var persp:Number = (camera.focus * camera.zoom) / (camera.focus + view.n34); screen.x = view.n14 * persp; screen.y = view.n24 * persp; screen.z = view.n34; } /** * Translate the display object in the direction it is facing, i.e. it's positive Z axis. * * @param distance The distance that the object should move forward. */ public function moveForward ( distance:Number ):void { translate( distance, FORWARD ); } /** * Translate the display object in the opposite direction it is facing, i.e. it's negative Z axis. * * @param distance The distance that the object should move backward. */ public function moveBackward ( distance:Number ):void { translate( distance, BACKWARD ); } /** * Translate the display object lateraly, to the left of the direction it is facing, i.e. it's negative X axis. * * @param distance The distance that the object should move left. */ public function moveLeft ( distance:Number ):void { translate( distance, LEFT ); } /** * Translate the display object lateraly, to the right of the direction it is facing, i.e. it's positive X axis. * * @param distance The distance that the object should move right. */ public function moveRight ( distance:Number ):void { translate( distance, RIGHT ); } /** * Translate the display object upwards, with respect to the direction it is facing, i.e. it's positive Y axis. * * @param distance The distance that the object should move up. */ public function moveUp ( distance:Number ):void { translate( distance, UP ); } /** * Translate the display object downwards, with respect to the direction it is facing, i.e. it's negative Y axis. * * @param distance The distance that the object should move down. */ public function moveDown ( distance:Number ):void { translate( distance, DOWN ); } // ___________________________________________________________________________________________________ // L O C A L T R A N S L A T I O N /** * Move the object along a given direction. * * @param distance The distance that the object should travel. * @param axis The direction that the object should move towards. */ public function translate( distance:Number, axis:Number3D ):void { var vector:Number3D = axis.clone(); if( this._transformDirty ) updateTransform(); Matrix3D.rotateAxis( transform, vector ); this.x += distance * vector.x; this.y += distance * vector.y; this.z += distance * vector.z; } // ___________________________________________________________________________________________________ // L O C A L R O T A T I O N /** * Rotate the display object around its lateral or transverse axis —an axis running from the pilot's left to right in piloted aircraft, and parallel to the wings of a winged aircraft; thus the nose pitches up and the tail down, or vice-versa. * * @param angle The angle to rotate. */ public function pitch( angle:Number ):void { angle = Papervision3D.useDEGREES? angle * toRADIANS : angle; var vector:Number3D = RIGHT.clone(); if( this._transformDirty ) updateTransform(); Matrix3D.rotateAxis( transform, vector ); _tempMatrix = Matrix3D.rotationMatrix( vector.x, vector.y, vector.z, angle, _tempMatrix ); this.transform.calculateMultiply3x3( _tempMatrix ,transform ); this._rotationDirty = true; } /** * Rotate the display object around about the vertical axis —an axis drawn from top to bottom. * * @param angle The angle to rotate. */ public function yaw( angle:Number ):void { angle = Papervision3D.useDEGREES? angle * toRADIANS : angle; var vector:Number3D = UP.clone(); if( this._transformDirty ) updateTransform(); Matrix3D.rotateAxis( transform, vector ); _tempMatrix = Matrix3D.rotationMatrix( vector.x, vector.y, vector.z, angle, _tempMatrix ); this.transform.calculateMultiply3x3( _tempMatrix ,transform ); this._rotationDirty = true; } /** * Rotate the display object around the longitudinal axis —an axis drawn through the body of the vehicle from tail to nose in the normal direction of flight, or the direction the object is facing. * * @param angle */ public function roll( angle:Number ):void { angle = Papervision3D.useDEGREES? angle * toRADIANS : angle; var vector:Number3D = FORWARD.clone(); if( this._transformDirty ) updateTransform(); Matrix3D.rotateAxis( transform, vector ); _tempMatrix = Matrix3D.rotationMatrix( vector.x, vector.y, vector.z, angle, _tempMatrix ); this.transform.calculateMultiply3x3( _tempMatrix ,transform ); this._rotationDirty = true; } /** * Make the object look at a specific position. * * @param targetObject Object to look at. * @param upAxis The vertical axis of the universe. Normally the positive Y axis. */ public function lookAt( targetObject:DisplayObject3D, upAxis:Number3D=null ):void { position.reset( this.x, this.y, this.z ); target.reset( targetObject.x, targetObject.y, targetObject.z ); zAxis.copyFrom(target); zAxis.minusEq(position); zAxis.normalize(); if( zAxis.modulo > 0.1 ) { xAxis = Number3D.cross( zAxis, upAxis || UP, xAxis ); xAxis.normalize(); yAxis = Number3D.cross( zAxis, xAxis, yAxis ); yAxis.normalize(); var look :Matrix3D = this.transform; // scale fix for lookAt() look.n11 = xAxis.x * _scaleX; look.n21 = xAxis.y * _scaleX; look.n31 = xAxis.z * _scaleX; look.n12 = -yAxis.x * _scaleY; look.n22 = -yAxis.y * _scaleY; look.n32 = -yAxis.z * _scaleY; look.n13 = zAxis.x * _scaleZ; look.n23 = zAxis.y * _scaleZ; look.n33 = zAxis.z * _scaleZ; this._transformDirty = false; this._rotationDirty = true; } else { trace("lookAt error") } } /** * Copies the position information (x, y and z coordinates) from another object or Matrix3D. * * @param reference A DisplayObject3D or Matrix3D object to copy the position from. */ public function copyPosition( reference:* ):void { var trans :Matrix3D = this.transform; var matrix :Matrix3D = (reference is DisplayObject3D)? reference.transform : reference; trans.n14 = matrix.n14; trans.n24 = matrix.n24; trans.n34 = matrix.n34; } /** * Copies the transformation information (position, rotation and scale) from another object or Matrix3D. * * @param reference A DisplayObject3D or Matrix3D object to copy the position from. */ public function copyTransform( reference:* ):void { var trans :Matrix3D = this.transform; var matrix :Matrix3D = (reference is DisplayObject3D)? reference.transform : reference; trans.n11 = matrix.n11; trans.n12 = matrix.n12; trans.n13 = matrix.n13; trans.n14 = matrix.n14; trans.n21 = matrix.n21; trans.n22 = matrix.n22; trans.n23 = matrix.n23; trans.n24 = matrix.n24; trans.n31 = matrix.n31; trans.n32 = matrix.n32; trans.n33 = matrix.n33; trans.n34 = matrix.n34; this._transformDirty = false; this._rotationDirty = true; } /** * [internal-use] Updates the transform Matrix3D with the current rotation and scale values. */ // TODO OPTIMIZE (HIGH) protected function updateTransform():void { _tempQuat = Matrix3D.euler2quaternion( -this._rotationY, -this._rotationZ, this._rotationX, _tempQuat ); // Swapped //var m:Matrix3D = Matrix3D.quaternion2matrix( q.x, q.y, q.z, q.w ); _tempMatrix = Matrix3D.quaternion2matrix( _tempQuat.x, _tempQuat.y, _tempQuat.z, _tempQuat.w, _tempMatrix ); //var q:Quaternion = Quaternion.createFromEuler( -this._rotationY, -this._rotationZ, this._rotationX ); //var m:Matrix3D = q.toMatrix(); var transform:Matrix3D = this.transform; _tempMatrix.n14 = transform.n14; _tempMatrix.n24 = transform.n24; _tempMatrix.n34 = transform.n34; transform.copy( _tempMatrix ); // Scale //var scaleM:Matrix3D = Matrix3D.IDENTITY; _tempMatrix.reset(); _tempMatrix.n11 = this._scaleX; _tempMatrix.n22 = this._scaleY; _tempMatrix.n33 = this._scaleZ; this.transform.calculateMultiply( transform, _tempMatrix ); this._transformDirty = false; } // ___________________________________________________________________________________________________ /** * Returns a string value representing the three-dimensional position values of the display object instance. * * @return A string. */ public override function toString(): String { return this.name + ': x:' + Math.round(this.x) + ' y:' + Math.round(this.y) + ' z:' + Math.round(this.z); } /** * @author Ralph Hauwert * * Some stuff for the viewports. */ public function set useOwnContainer(b:Boolean):void { _useOwnContainer = b; } public function get useOwnContainer():Boolean { return _useOwnContainer; } public function set containerSortMode(sortMode:int):void { _containerSortMode = sortMode; } public function get containerSortMode():int { return _containerSortMode; } public function set containerBlendMode(blendmode:int):void { _containerBlendMode = blendmode; } public function get containerBlendMode():int { return _containerBlendMode; } public function set filters(filters:Array):void { _filters = filters; } public function get filters():Array { return _filters; } use namespace pv3dview; pv3dview function setLayerForViewport(layer:ViewportLayer):void { //Register it here under the correct viewport. } public function set userData(userData:UserData):void { _userData = userData; } public function get userData():UserData { return _userData; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -