Skip to content

Instantly share code, notes, and snippets.

@komiga
Created July 18, 2010 01:48
Show Gist options
  • Save komiga/480034 to your computer and use it in GitHub Desktop.
Save komiga/480034 to your computer and use it in GitHub Desktop.
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)
}
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