尔冬橙

博客园 首页 新随笔 联系 订阅 管理

flare.collisions

Class

Description

CollisionInfo

The CollisionInfo class provides   information on collisions.

MouseCollision

The MouseCollision class provides tools   to detect collision of objects with the mouse or with a 2D coordinate   relative to the screen.

RayCollision

The RayCollision class provides tools to   detect collisions along an infinite 3D virtual line.

SphereCollision

The SphereCollision class provides tools   to detect the collisions of a sphere against polygonal objects.

Package: flare.collisions

Class: public class CollisionInfo

Inheritance: CollisionInfo-->Object

 

The CollisionInfo class provides information on collisions.

This information is issued by MouseCollision, RayCollision and SphereCollision classes. Each of these classes has a CollisionInfo-type data Vector where the information related to one or more collisions is returned.

Property Detail

public var mesh:Mesh3D

Mesh it collided with.

public var normal:Vector3D

Collision normal in the global space of the scene.

public var point:Vector3D

Point it collided with in the global space of the scene.

public var poly:Poly3D

Polygon of the mesh it collided with.

public var surface:Surface3D

surface it collided with.

public var u:Number

Horizontal coordinate of texture at the collision point. The value returned corresponds to the texture primary channel and it goes from 0 to 1, where 0 is the left side and 1 is the right side. The right texture pixel results from multiplying the value returned at 'u' by texture width.

public var v:Number

Vertical coordinate of texture at collision point. The value returned corresponds to the texture primary channel and it goes from 0 to 1, where 0 is the upper side and 1 is the lower side. The right texture pixel results from multiplying the value returned at 'v' by texture height.

MouseCollision

Package: flare.collisions

Class: public class MouseCollision

Inheritance MouseCollision-->Object

 

The MouseCollision class provides tools to detect collision of objects with the mouse or with a 2D coordinate relative to the screen.

 

Property Detail

camera:Camera3D

Camera to be used in checks.

Implementation

    public function get camera():Camera3D
    public function set camera(value:Camera3D):void

collided:Boolean  [read-only]

Returns whether collision occurred or not in the last check.

Implementation

    public function get collided():Boolean

collisionCount:int  [read-only]

Returns the number of objects to be checked.

Implementation

    public function get collisionCount():int

collisionTime:int  [read-only]

Returns the time taken to perform the last check in milliseconds.

Implementation

    public function get collisionTime():int

public var data:Vector.<CollisionInfo>

CollisionInfo-type vector with the results of the collision.

ray:RayCollision  [read-only]

An instance of ray collision used to do the tests.

Implementation

    public function get ray():RayCollision

 

Constructor Detail

public function MouseCollision(camera:Camera3D = null)

Creates a new MouseCollision object. Camera and canvas are both optional. If null, those used during the collision are selected.

Parameters

camera:Camera3D (default = null) — Camera3D object that will be used to check the collision.

Method Detail

addCollisionWith () method

public function addCollisionWith(pivot:Pivot3D, includeChildren:Boolean = true):void

Adds objects that will be used to check for collisions.

Parameters 

pivot:Pivot3D — Pivot3D object to be checked for collisions 

     includeChildren:Boolean (default = true) — defines whether Pivot3D children are to be included. 

 

public function dispose():void

 

removeCollisionWith () method  

public function removeCollisionWith(pivot:Pivot3D, includeChildren:Boolean = true):void

Removes a Pivot3D in order to stop its checking process.

 

Parameters 

pivot:Pivot3D — Pivot3D object to be removed. 

     includeChildren:Boolean (default = true) — defines whether Pivot3D children are to be removed. 

 

test () method  

public function test(x:Number, y:Number, getAllPolysUnderPoint:Boolean = false, ignoreInvisible:Boolean = true, ignoreBackFace:Boolean = true):Boolean

Performs the collision check. "x" and "y" coordinates are relative to the canvas.

Parameters 

x:Number — Canvas X coordinate. 

      y:Number — Canvas Y coordinate. 

      getAllPolysUnderPoint:Boolean (default = false) — Defines whether all the collisions or only the first collision are to be taken. 

ignoreInvisible:Boolean (default = true) — Defines whether invisible objects are to be ignored. 

      ignoreBackFace:Boolean (default = true)

Returns Boolean — true if collision occurred. 

 

 

 

RayCollision

Package: flare.collisions

Class: public class RayCollision

Inheritance: RayCollision-->Object

 

The RayCollision class provides tools to detect collisions along an infinite 3D virtual line.

The RayCollision class has a wide variety of applications. It could be used to find out which object is below a given character or to align an object in an area by shooting a ray in a downward direction or even to calculate where this object will impact a bullet moving in a specific direction, etc. Information about the environment can be taken by shooting virtual rays in any direction from a given position.

 

Property Detail

collided:Boolean  [read-only]

Returns whether collision occurred or not in the last check.

Implementation

    public function get collided():Boolean

 

collisionCount:int  [read-only]

Returns the number of objects to be checked.

Implementation

    public function get collisionCount():int

 

collisionTime:int  [read-only]

Returns the time taken to perform the last check in milliseconds.

Implementation

    public function get collisionTime():int

 

public var data:Vector.<CollisionInfo>

CollisionInfo-type vector with collision results.

 

Constructor Detail

RayCollision () Constructor

public function RayCollision()

Creates a new RayCollision object.

 

Method Detail

addCollisionWith () method

public function addCollisionWith(pivot:Pivot3D, includeChildren:Boolean = true):void

 

Adds objects that will be used to check for collisions.

Parameters 

pivot:Pivot3D — Pivot3D object to be checked for collisions 

includeChildren:Boolean (default = true) — defines whether Pivot3D children are to be included. 

 

dispose () method  

public function dispose():void

removeCollisionWith () method  

public function removeCollisionWith(pivot:Pivot3D, includeChildren:Boolean = true):void

Removes a Pivot3D in order to stop its checking process.

Parameters 

pivot:Pivot3D — Pivot3D object to be removed. 

includeChildren:Boolean (default = true) — defines whether Pivot3D children are to be removed. 

 

test () method  

public function test(from:Vector3D, direction:Vector3D, getAllPolysUnderPoint:Boolean = false, ignoreInvisible:Boolean = true, ignoreBackFace:Boolean = true):Boolean

Performs the collision check. Both the from parameter and the direction parameter must be in the global scene space. The direction parameter is a Vector3D that represents the direction the ray is pointing to, eg. ( 0, -1, 0 ) would be downward, ( 0, 0, 1 ) would be forward, etc.

Parameters 

from:Vector3D — Point of origin of the ray. 

direction:Vector3D — Direction the ray points to. 

getAllPolysUnderPoint:Boolean (default = false) — Defines whether all the collisions or only the first collision is to be taken. 

ignoreInvisible:Boolean (default = true)

ignoreBackFace:Boolean (default = true)

Returns: Boolean — true if collision occurred. 

 

SphereCollision

collided:Boolean  [read-only]

Returns whether collision occurred or not in the last check.

Implementation

    public function get collided():Boolean

 

collisionCount property  

collisionCount:int  [read-only]

Returns the number of objects that will be checked.

Implementation

    public function get collisionCount():int

 

collisionTime property  

collisionTime:int  [read-only]

Returns the time taken to perform the last check in milliseconds.

Implementation

    public function get collisionTime():int

 

data property  

public var data:Vector.<CollisionInfo>

CollisionInfo-type vector with collision results.

 

offset property  

offset:Vector3D

Sets or returns the displacement of the colliding sphere center.

Implementation

    public function get offset():Vector3D

    public function set offset(value:Vector3D):void

 

radius property  

radius:Number

Sets or returns the collision radius that will be used to detect collisions.

Implementation

    public function get radius():Number

    public function set radius(value:Number):void

 

Constructor Detail

SphereCollision () Constructor

public function SphereCollision(source:Pivot3D, radius:Number = 1, offset:Vector3D = null)

Creates a new SphereCollision object.

Parameters 

source:Pivot3D — Pivot that will serve as colliding object. It could be a character, a camera, etc. 

radius:Number (default = 1) — Collision radius that will be used to detect collisions. 

offset:Vector3D (default = null) — By default, the virtual sphere center will be placed at the origin of the Pivot3D that is used as source, i.e. at the (0,0,0) point. The offset parameter allows the user to move the sphere center to a more convenient position manually if necessary. The offset parameter must be represented in the object’s local space; therefore, if the 'source' object is rotated, the offset will also be rotated. 

 

Method Detail

addCollisionWith () method

public function addCollisionWith(pivot:Pivot3D, includeChildren:Boolean = true):void

Adds objects that will be used to test collisions.

Parameters 

pivot:Pivot3D — Pivot3D object to be checked for collisions. 

includeChildren:Boolean (default = true) — defines whether Pivot3D children are to be included. 

 

fixed () method  

public function fixed():Boolean

The fixed method detects collisions and generates a static response, locating the colliding object exactly at the collision point. When this method is used, the object will stop at the first collision it encounters and will remain in that position without sliding, which is typical of the slider method.

Returns Boolean — true if collision occurred. 

 

intersect () method  

public function intersect():Boolean

The intersect method detects when the colliding object intersects another 3d mesh but will not generate any response. It can be used to detect collisions with invisible zones, for example.

Returns Boolean — true si hubo colisión. 

 

removeCollisionWith () method  

public function removeCollisionWith(pivot:Pivot3D, includeChildren:Boolean = true):void

Removes a Pivot3D to stop its checking process.

Parameters 

pivot:Pivot3D — Pivot3D object to be removed. 

includeChildren:Boolean (default = true) — defines whether Pivot3D children are to be removed. 

 

reset () method  

public function reset():void

The SphereCollision class calculates collisions based on object trajectory and previous position. In some cases, when the source object is to be removed and forced to a given position, collisions should be reset. The reset method must be used after repositioning the object.

 

slider () method  

public function slider(precision:int = 2):Boolean

The slider method detects collisions and provides a sliding response depending on the collision inclination (normal).

Parameters  precision:int (default = 2)

Returns Boolean — true if collision occured. 

 

posted on 2012-05-16 15:54  尔冬橙  阅读(342)  评论(0编辑  收藏  举报