66 lines
2.0 KiB
Lua
66 lines
2.0 KiB
Lua
|
|
--
|
|
-- Anaglym std library
|
|
--
|
|
-- History:
|
|
-- 2009-11-02 Josh Holtrop Initial Revision
|
|
--
|
|
|
|
std = {}
|
|
|
|
-- Compute the cross product of two vectors
|
|
-- Input:
|
|
-- vec1: the first vector (table; indices 1..3)
|
|
-- vec2: the second vector (table; indices 1..3)
|
|
-- Output:
|
|
-- The cross product vector (table; indices 1..3)
|
|
std.crossProduct = function(vec1, vec2)
|
|
local vec_result = {}
|
|
vec_result[1] = vec1[2] * vec2[3] - vec1[3] * vec2[2]
|
|
vec_result[2] = vec1[3] * vec2[1] - vec1[1] * vec2[3]
|
|
vec_result[3] = vec1[1] * vec2[2] - vec1[2] * vec2[1]
|
|
return vec_result
|
|
end
|
|
|
|
-- Compute the dot product of two vectors
|
|
-- Input:
|
|
-- vec1: the first vector (table; indices 1..3)
|
|
-- vec2: the second vector (table; indices 1..3)
|
|
-- Output:
|
|
-- The dot product scalar
|
|
std.dotProduct = function(vec1, vec2)
|
|
return vec1[1] * vec2[1] + vec1[2] * vec2[2] + vec1[3] * vec2[3]
|
|
end
|
|
|
|
-- Create a plane
|
|
-- Input:
|
|
-- x, y, z: coordinates of a point on the plane
|
|
-- nx, ny, nz: normal vector of the plane
|
|
-- Output:
|
|
-- Plane object (returned from ag.createPlane())
|
|
std.createPlanePointNormal = function(x, y, z, nx, ny, nz)
|
|
-- calculate the d plane parameter based on the point coordinates
|
|
-- invoke the ag routine to create a plane based on a, b, c, d parameters
|
|
return ag.createPlane(nx, ny, nz, nx * x, ny * y, nz * z)
|
|
end
|
|
|
|
-- Convert screen percent to pixel count along X axis
|
|
-- Input:
|
|
-- percent: percent (0.0 - 1.0) of the screen's X axis
|
|
-- Output:
|
|
-- Number of pixels corresponding to 'percent' percent of the X axis
|
|
std.pctx = function(percent)
|
|
local width = ag.getScreenSize()
|
|
return width * percent
|
|
end
|
|
|
|
-- Convert screen percent to pixel count along Y axis
|
|
-- Input:
|
|
-- percent: percent (0.0 - 1.0) of the screen's Y axis
|
|
-- Output:
|
|
-- Number of pixels corresponding to 'percent' percent of the Y axis
|
|
std.pcty = function(percent)
|
|
local width, height = ag.getScreenSize()
|
|
return height * percent
|
|
end
|