Created
July 18, 2010 01:48
-
-
Save komiga/480034 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use math | |
import math | |
//PI: const Float = 3.14159265359 | |
TWOPI: const Float = PI*2 | |
HALFPI: const Float = PI/2 | |
Rect: class { | |
x, y, width, height: Float | |
init: func(=x, =y, =width, =height) | |
} | |
Vec2: class { | |
x, y: Float | |
init: func(=x, =y) | |
Dot: func(t: Vec2) -> Float { | |
return x*t x+y*t y | |
} | |
Length: func() -> Float { | |
return sqrt(x*x+y*y) | |
} | |
Distance: func(t: Vec2) -> Float { | |
return (this-t) Length() | |
} | |
Normalize: func() -> Vec2 { | |
return this/Length() | |
} | |
Blend: func(t: Vec2, alpha: Float) -> Vec2 { | |
return (t-this)*alpha+this | |
} | |
} | |
operator [] (first: Vec2, i: Int) -> Float { | |
return *(first x) + i | |
//return (first x&)[i] | |
} | |
// Negation operator | |
//operator- (first: Vec2) -> Vec2 { | |
// return Vec2 new(-first.x, -first.y) | |
//} | |
operator+ (first: Vec2, t: Float) -> Vec2 { | |
return Vec2 new(first x+t, first y+t) | |
} | |
operator- (first: Vec2, t: Float) -> Vec2 { | |
return Vec2 new(first x-t, first y-t) | |
} | |
operator* (first: Vec2, t: Float) -> Vec2 { | |
return Vec2 new(first x*t, first y*t) | |
} | |
operator/ (first: Vec2, t: Float) -> Vec2 { | |
return Vec2 new(first x/t, first y/t) | |
} | |
operator+ (first, t: Vec2) -> Vec2 { | |
return Vec2 new(first x+t x, first y+t y) | |
} | |
operator- (first, t: Vec2) -> Vec2 { | |
return Vec2 new(first x-t x, first y-t y) | |
} | |
operator* (first, t: Vec2) -> Vec2 { | |
return Vec2 new(first x*t x, first y*t y) | |
} | |
operator/ (first, t: Vec2) -> Vec2 { | |
return Vec2 new(first x/t x, first y/t y) | |
} | |
operator+= (first, v: Vec2) -> Vec2 { | |
first x+=v x; first y+=v y; return first | |
} | |
operator-= (first, v: Vec2) -> Vec2 { | |
first x-=v x; first y-=v y; return first | |
} | |
operator*= (first, v: Vec2) -> Vec2 { | |
first x*=v x; first y*=v y; return first | |
} | |
operator/= (first, v: Vec2) -> Vec2 { | |
first x/=v x; first y/=v y; return first | |
} | |
operator*= (first: Vec2, t: Float) -> Vec2 { | |
first x*=t; first y*=t; return first | |
} | |
operator/= (first: Vec2, t: Float) -> Vec2 { | |
first x/=t; first y/=t; return first | |
} | |
operator== (first, v: Vec2) -> Bool { | |
return (first x==v x && first y==v y) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Name: Max3D | |
Version: head | |
Description: ooc conversion of Max3D | |
SourcePath: . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment