fixed bug in ag::createPlaneSpecify(), added standard lua library "std.lua"
git-svn-id: svn://anubis/anaglym/trunk@148 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
2ccff9db76
commit
24d37092e2
4
ag.cc
4
ag.cc
@ -381,7 +381,7 @@ namespace ag
|
|||||||
if (argc == 4 || argc == 6)
|
if (argc == 4 || argc == 6)
|
||||||
{
|
{
|
||||||
bool valid = true;
|
bool valid = true;
|
||||||
for (int i = 0; i < argc; i++)
|
for (int i = 1; i <= argc; i++)
|
||||||
{
|
{
|
||||||
if (!lua_isnumber(L, i))
|
if (!lua_isnumber(L, i))
|
||||||
{
|
{
|
||||||
@ -392,7 +392,7 @@ namespace ag
|
|||||||
if (valid)
|
if (valid)
|
||||||
{
|
{
|
||||||
refptr< vector<float> > args = new vector<float>();
|
refptr< vector<float> > args = new vector<float>();
|
||||||
for (int i = 1; i <= 6; i++)
|
for (int i = 1; i <= argc; i++)
|
||||||
args->push_back(lua_tonumber(L, i));
|
args->push_back(lua_tonumber(L, i));
|
||||||
addManagedObject(L, is_static, OdeWorld::PLANE, args);
|
addManagedObject(L, is_static, OdeWorld::PLANE, args);
|
||||||
return 1;
|
return 1;
|
||||||
|
45
lib/std.lua
Normal file
45
lib/std.lua
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
|
||||||
|
--
|
||||||
|
-- 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
|
Loading…
x
Reference in New Issue
Block a user