My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org + blog.papervision3d.org + osflash.org/papervision3d
*/

/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

// ______________________________________________________________________
// Vertex3D
package org.papervision3d.core.geom.renderables
{
import flash.utils.Dictionary;

import org.papervision3d.core.math.Number3D;
import org.papervision3d.core.render.command.IRenderListItem;


/**
* The Vertex3D constructor lets you create 3D vertices.
*/
public class Vertex3D extends AbstractRenderable implements IRenderable
{
/**
* An Number that sets the X coordinate of a object relative to the scene coordinate system.
*/
public var x :Number;

/**
* An Number that sets the Y coordinate of a object relative to the scene coordinates.
*/
public var y :Number;

/**
* An Number that sets the Z coordinate of a object relative to the scene coordinates.
*/
public var z :Number;

/**
* An object that contains user defined properties.
*/
public var extra :Object;

/**
* Used for removing duplicates in clipping procedures
*/
public var timestamp:Number;

/**
* Vertex2D instance
*/
public var vertex3DInstance:Vertex3DInstance;

//To be docced
public var normal:Number3D;
public var connectedFaces:Dictionary;

private var persp:Number=0;

protected var position:Number3D = new Number3D();

/**
* Creates a new Vertex3D object whose three-dimensional values are specified by the x, y and z parameters.
*
* @param x The horizontal coordinate value. The default value is zero.
* @param y The vertical coordinate value. The default value is zero.
* @param z The depth coordinate value. The default value is zero.
*
* */
public function Vertex3D( x:Number=0, y:Number=0, z:Number=0 )
{
this.x = position.x = x;
this.y = position.y = y;
this.z = position.z = z;

this.vertex3DInstance = new Vertex3DInstance();
this.normal = new Number3D();
this.connectedFaces = new Dictionary();
}

public function getPosition():Number3D
{
position.x = x;
position.y = y;
position.z = z;
return position;
}

public function toNumber3D():Number3D
{
return new Number3D(x,y,z);
}

public function clone():Vertex3D
{
var clone:Vertex3D = new Vertex3D(x,y,z);
clone.extra = extra;
clone.vertex3DInstance = vertex3DInstance.clone();
clone.normal = normal.clone();
return clone;
}

public function calculateNormal():void
{
var face:Triangle3D;
var count:Number = 0;
normal.reset();
for each(face in connectedFaces)
{

if(face.faceNormal){
count++;
normal.plusEq(face.faceNormal);
}
}
//normal.x/=count;
//normal.y/=count;
//normal.z/=count;
var p:Number3D = getPosition();
p.x /= count;
p.y /= count;
p.z /=count;
p.normalize();
normal.plusEq(p);
normal.normalize();
}

override public function getRenderListItem():IRenderListItem
{
return null;
}

public static function weighted(a:Vertex3D, b:Vertex3D, aw:Number, bw:Number):Vertex3D
{
var d:Number = aw + bw;
var ak:Number = aw / d;
var bk:Number = bw / d;
return new Vertex3D(a.x*ak+b.x*bk, a.y*ak + b.y*bk, a.z*ak + b.z*bk);
}

public function perspective(focus:Number):Vertex3DInstance
{
persp = 1 / (1 + z / focus);

return new Vertex3DInstance(x * persp, y * persp, z);
}

}
}

Change log

r754 by azupko on Oct 13, 2008   Diff
QuadTree Support
Render Pipeline changes
Go to: 
Project members, sign in to write a code review

Older revisions

r741 by azupko on Sep 26, 2008   Diff
Speed Updates, Clipping
r708 by neoriley on Aug 25, 2008   Diff
Updating Trunk to 2.0 Beta
All revisions of this file

File info

Size: 5157 bytes, 176 lines
Powered by Google Project Hosting