Hallihallo,
gerade bin ich fertig geworden mit der "Übersetzung" einer ActionScript Library in Autoit. Da ich Autoit noch nicht "doll" kann, möchte ich euch bitten einmal über den Code zu schauen. Besonders ab Zeile 283 bis 326. Da habe ich die Funktion drawAt noch nicht so richtig hinbekommen.
Achtung!: Es mag zwar nach viel Code aussehn, ist es aber nicht! Ich habe nur den Code aus dem ASScript in das AutoitScript als Kommentar, zur jeweiligen Funktion, eingefügt.
"Übersetztes":
Spoiler anzeigen
#cs
private var __x:Number;
private var __y:Number;
private var __normal:Vector;
private var __len:Number;
private var bInvalidLen:Boolean;
private var bInvalidNormal:Boolean;
#ce
Global $__x
Global $__y
Global $__normal = Vector($__x, $__y)
Global $__len
Global $bInvalidLen
Global $bInvalidNormal
#cs
/**
* constructor
* initializes x and y, invalidates length and normal
* @param x Number
* @param y Number
*/
function Vector(x:Number, y:Number){
this.__x = x;
this.__y = y;
this.bInvalidLen = true;
this.bInvalidNormal = true;
}
#ce
Func Vector($f__x, $f__y)
$__x = $f__x
$__y = $f__y
$bInvalidLen = True
$bInvalidNormal = True
EndFunc ;==>Vector
#cs
/ * *
* Updates this vectors' x and y values
* @param x Number
* @param y Number
* /
public function setVector(x:Number, y:Number) {
this.__x = x;
this.__y = y;
this.bInvalidLen = True;
this.bInvalidNormal = True;
}
#ce
Func setVector($f__x, $f__y)
$__x = $f__x
$__y = $f__y
$bInvalidLen = True
$bInvalidNormal = True
EndFunc ;==>setVector
#cs
/**
* Calculates the dot product of this vector and vetor v
* @param v Vector
* @return returns a new vector
*/
public function dot(v:Vector){
return this.x * v.x + this.y * v.y;
}
#ce
Func dot($f__x, $f__y)
Return $__x * $f__x + $__y * $f__y
EndFunc ;==>dot
#cs
/**
* Calculates the cross product of this vector and number n
* @param n Number
* @return returns a new vector
*/
public function cross(n:Number){
return new Vector(this.x * n, this.y * n);
}
#ce
Func cross($fn)
Return Vector($f__x * $fn, $f__y * $fn)
EndFunc ;==>cross
#cs
/**
* Adds vector v to this vector
* @param v Vector
* @return returns a new vector
*/
public function plus(v:Vector){
return new Vector(this.x + v.x, this.y + v.y);
}
#ce
Func plus($f__x, $f__y)
Return Vector($__x + $f__x, $__y + $f__y)
EndFunc ;==>plus
#cs
/**
* Substracts vector v from this vector
* @param v Vector
* @return returns a new vector
*/
public function minus (v:Vector){
return new Vector(this.x - v.x, this.y - v.y);
}
#ce
Func minus($f__x, $f__y)
Return Vector($__x - $f__x, $__y - $f__y)
EndFunc ;==>minus
#cs
/**
* Returns inverted vector
* @return returns a new vector
*/
public function getInverted (){
return new Vector(-this.x, -this.y);
}
#ce
Func getInverted()
Return Vector(-$__x, -$__y)
EndFunc ;==>getInverted
#cs
/**
* Returns a normalized version of this vector
* @return returns a new vector or null
*/
public function getNormalized () {
if (this.len == 0){
return null;
} else {
return new Vector(this.__x / this.len, this.__y / this.len)
}
}
#ce
Func getNormalized()
If len() == 0 Then
Return 0
Else
Return Vector($__x / len(), $__y / len())
EndIf
EndFunc ;==>getNormalized
#cs
/**
* Inverts this vector
* @return nothing
*/
public function invert (){
this.__x *= -1;
this.__y *= -1;
this.bInvalidNormal = true;
}
#ce
Func invert()
$__x = $__x * - 1
$__y = $__y * - 1
$bInvalidNormal = True
EndFunc ;==>invert
#cs
/**
* Normalizes this vector
* @return nothing
*/
public function normalize(Void):Void {
if (this.len == 0){
this.__x = 0;
this.__y = 0;
} else {
this.__x /= this.len;
this.__y /= this.len;
}
this.bInvalidLen = true;
}
#ce
Func normalize()
If len() == 0 Then
$__x = 0
$__y = 0
Else
$__x = $__x / len()
$__y = $__y / len()
EndIf
EndFunc ;==>normalize
#cs
public function set x (n:Number) {
this.__x = n;
this.bInvalidLen = true;
this.bInvalidNormal = true;
}
#ce
Func set_x($fn)
$__x = $fn
$bInvalidLen = True
$bInvalidNormal = True
EndFunc ;==>set_x
#cs
public function set y (n:Number) {
this.__y = n;
this.bInvalidLen = true;
this.bInvalidNormal = true;
}
#ce
Func set_y($fn)
$__y = $fn
$bInvalidLen = True
$bInvalidNormal = True
EndFunc ;==>set_y
#cs
public function get x (){
return this.__x;
}
#ce
Func get_x()
Return $__x
EndFunc ;==>get_x
#cs
public function get y (){
return this.__y;
}
#ce
Func get_y()
Return $__y
EndFunc ;==>get_y
#cs
public function get normal (){
if (this.bInvalidNormal) this.updateNormal();
return this.__normal;
}
#ce
Func get_normal()
If $bInvalidLen = updateNormal() Then Return $__normal
EndFunc ;==>get_normal
#cs
public function get len (){
if (this.bInvalidLen) this.updateLen();
return this.__len;
}
#ce
Func get_len()
If $bInvalidLen = updateLen() Then Return $__normal
EndFunc ;==>get_len
#cs
//////////////////////////// misc public functions //////////////////////////
public function toString(Void):String {
return "Vector(" + this.__x + ", " + this.__y + ")";
}
#ce
[/autoit] [autoit][/autoit] [autoit]Func toString()
Return "Vector(" & $__x & "," & $__y & ")"
EndFunc ;==>toString
#cs
/**
* Draws the vector, useful when debugging
* @param mc MovieClip to draw onto
* @param px start point x coordinate
* @param py start point y coordinate
* @param scale optional scale
* @param col optional color
*/
public function drawAt(mc:MovieClip, px:Number, py:Number, scale:Number, col:Number){
!> if (scale == undefined) scale = 1;
!> if (col == undefined) col = 0xFF0000;
!> var ex, ey;
!> ex = px + this.__x * scale;
!> ey = py + this.__y * scale;
mc.lineStyle(1, col, 100);
mc.moveTo(px, py);
mc.lineTo(ex, ey);
// draw arrow
!> var tmpVector = new Vector(px, py).plus(this.getNormalized().cross(this.len*scale-6));
!> var nVector = this.normal;
nVector.normalize();
nVector = nVector.cross(4);
var tmpVector = tmpVector.plus(nVector);
mc.moveTo(tmpVector.x, tmpVector.y);
mc.lineTo(ex, ey);
var tmpVector = tmpVector.plus(nVector.cross(-2));
mc.lineTo(tmpVector.x, tmpVector.y);
}
#ce
Func drawAt($px, $py,$scale,$col)
Local $ex, $ey, $tmpVector, $nVector
If $scale <> IsDeclared Then $scale = 1
If $col <> IsDeclared Then $col = 0xFF0000
$ex = $px + $__x * $scale
$ey = $py + $__y * $scale
$tmpVector = Vector($px,$py) + getNormalized() + cross($__len*$scale-6)
$nVector = get_normal()
EndFunc
[/autoit] [autoit][/autoit] [autoit]#cs
//////////////////////////// private functions //////////////////////////
private function updateLen() {
this.__len = Math.sqrt(this.__x*this.__x + this.__y*this.__y);
this.bInvalidLen = false;
}
#ce
Func updateLen()
$__len = Sqrt($__x * $__x + $__y * $__y)
$bInvalidLen = False
EndFunc ;==>updateLen
#cs
private function updateNormal() {
this.__normal = new Vector(-this.__y/this.len, this.__x/this.len);
this.bInvalidNormal = false;
}
#ce
Func updateNormal()
$__normal = Vector(($__y * - 1) / len(), ($__x * - 1) / len())
EndFunc ;==>updateNormal
Normale AS-Library:
Spoiler anzeigen
class be.atomik.gamelib.geom.Vector {
private var __x:Number;
private var __y:Number;
private var __normal:Vector;
private var __len:Number;
private var bInvalidLen:Boolean;
private var bInvalidNormal:Boolean;
/**
* constructor
* initializes x and y, invalidates length and normal
* @param x Number
* @param y Number
*/
function Vector(x:Number, y:Number){
this.__x = x;
this.__y = y;
this.bInvalidLen = true;
this.bInvalidNormal = true;
}
/**
* Updates this vectors' x and y values
* @param x Number
* @param y Number
*/
public function setVector(x:Number, y:Number){
this.__x = x;
this.__y = y;
this.bInvalidLen = true;
this.bInvalidNormal = true;
}
//////////////////////////// operators //////////////////////////
/**
* Calculates the dot product of this vector and vetor v
* @param v Vector
* @return returns a new vector
*/
public function dot(v:Vector){
return this.x * v.x + this.y * v.y;
}
/**
* Calculates the cross product of this vector and number n
* @param n Number
* @return returns a new vector
*/
public function cross(n:Number){
return new Vector(this.x * n, this.y * n);
}
/**
* Adds vector v to this vector
* @param v Vector
* @return returns a new vector
*/
public function plus(v:Vector){
return new Vector(this.x + v.x, this.y + v.y);
}
/**
* Substracts vector v from this vector
* @param v Vector
* @return returns a new vector
*/
public function minus (v:Vector){
return new Vector(this.x - v.x, this.y - v.y);
}
/**
* Returns inverted vector
* @return returns a new vector
*/
public function getInverted (){
return new Vector(-this.x, -this.y);
}
/**
* Returns a normalized version of this vector
* @return returns a new vector or null
*/
public function getNormalized () {
if (this.len == 0){
return null;
} else {
return new Vector(this.__x / this.len, this.__y / this.len)
}
}
/**
* Inverts this vector
* @return nothing
*/
public function invert (){
this.__x *= -1;
this.__y *= -1;
this.bInvalidNormal = true;
}
/**
* Normalizes this vector
* @return nothing
*/
public function normalize(Void):Void {
if (this.len == 0){
this.__x = 0;
this.__y = 0;
} else {
this.__x /= this.len;
this.__y /= this.len;
}
this.bInvalidLen = true;
}
//////////////////////////// setters //////////////////////////
public function set x (n:Number) {
this.__x = n;
this.bInvalidLen = true;
this.bInvalidNormal = true;
}
public function set y (n:Number) {
this.__y = n;
this.bInvalidLen = true;
this.bInvalidNormal = true;
}
//////////////////////////// getters //////////////////////////
public function get x (){
return this.__x;
}
public function get y (){
return this.__y;
}
public function get normal (){
if (this.bInvalidNormal) this.updateNormal();
return this.__normal;
}
public function get len (){
if (this.bInvalidLen) this.updateLen();
return this.__len;
}
//////////////////////////// misc public functions //////////////////////////
public function toString(Void):String {
return "Vector(" + this.__x + ", " + this.__y + ")";
}
/**
* Draws the vector, useful when debugging
* @param mc MovieClip to draw onto
* @param px start point x coordinate
* @param py start point y coordinate
* @param scale optional scale
* @param col optional color
*/
public function drawAt(mc:MovieClip, px:Number, py:Number, scale:Number, col:Number){
if (scale == undefined) scale = 1;
if (col == undefined) col = 0xFF0000;
var ex, ey;
ex = px + this.__x * scale;
ey = py + this.__y * scale;
mc.lineStyle(1, col, 100);
mc.moveTo(px, py);
mc.lineTo(ex, ey);
// draw arrow
var tmpVector = new Vector(px, py).plus(this.getNormalized().cross(this.len*scale-6));
var nVector = this.normal;
nVector.normalize();
nVector = nVector.cross(4);
var tmpVector = tmpVector.plus(nVector);
mc.moveTo(tmpVector.x, tmpVector.y);
mc.lineTo(ex, ey);
var tmpVector = tmpVector.plus(nVector.cross(-2));
mc.lineTo(tmpVector.x, tmpVector.y);
}
//////////////////////////// private functions //////////////////////////
private function updateLen() {
this.__len = Math.sqrt(this.__x*this.__x + this.__y*this.__y);
this.bInvalidLen = false;
}
private function updateNormal() {
this.__normal = new Vector(-this.__y/this.len, this.__x/this.len);
this.bInvalidNormal = false;
}
}
Alles anzeigen
Der Quellcode stammt von folgender Seite: http://www.johanvanmol.org/content/view/45/37/1/7/</a>
Ihr würdet mir echt einen großen Gefallen tun, den nur so lerne ich weiter
Einen schönen Tag noch - Vectorix