pixwerx/src/scripts/tests/test_core.lua
Hartmut Seichter 749bb67c6c major overhaul for Lua API and additions for using texture coordinates
Signed-off-by: Hartmut Seichter <hartmut@technotecture.com>
2021-02-02 23:23:40 +01:00

119 lines
1.9 KiB
Lua

--
-- pixwerx - test - core
--
-- loading our libraries
pw.script:load_all()
-- vector3
local v1 = pw.vector3(3,2,1)
print("v1 ",v1.x,v1.y,v1.z)
local v2 = pw.vector3(1,2,3)
print("v2 ",v2.x,v2.y,v2.z)
local v_up = pw.vector3.up
print("v_up",v_up.x,v_up.y,v_up.z)
local v3 = v1 + v2
print(v1 + v2)
print("v3 ",v3.x,v3.y,v3.z)
print("v3.norm",v3.norm)
print("v3.squared_norm",v3.squared_norm)
print(v1,v1.arr,v1.data[2])
local v4 = v3
print("v4",v4)
print(v4.table)
v4.table = { 11, 22, 33 }
print("v4 ", v4.x, v4.y, v4.z)
local m4 = pw.matrix4x4.identity
v44 = m4 * v4
print("v44 ", v44.x, v44.y, v44.z)
-- quaternion
local q = pw.quaternion.identity
print("q",q.x,q.y,q.z,q.w)
qi = q.inverse
print("q.inverse",qi.x,qi.y,qi.z,qi.w)
local q2 = pw.quaternion(1,1,1,2)
local qn = q2.normalized
print("q2.normalized",qn.x,qn.y,qn.z,qn.w)
local ql = pw.quaternion.lerp(q,q2,0.5).normalized
print("q-qi lerp",ql.x,ql.y,ql.z,ql.w)
local qsl = pw.quaternion.slerp(q,q2,0.5).normalized
print("q-qi slerp",qsl.x,qsl.y,qsl.z,qsl.w)
-- axisangle
local aa = pw.axisangle(pw.vector3.up,0.707)
print("aa.axis",aa.axis.x,aa.axis.y,aa.axis.z)
print("aa.angle",aa.angle)
local g = pw.geometry()
g.indices = { 11, 22, 33 }
-- alert! the returned table is a copy!
table.insert(g.indices,44)
print("#g.indices ",#g.indices)
-- to insert one needs to set the whole table
local temp = g.indices
temp[#temp + 1] = 44
g.indices = temp
for k,v in ipairs(g.indices) do
print("index: ",k,v)
end
g.vertices = {
{ 11, 11, 11 },
{ 22, 22, 22 },
{ 33, 33, 33 }
}
-- now look at the vertices
for k,v in ipairs(g.vertices) do
print("vertex: ",k,v.x,v.y,v.z)
end
-- now look at the texture coordinates
g.texture_coordinates = {
{
{ 0, 0 },
{ 1, 0 },
{ 1, 1 },
{ 0, 1 }
}
}
for k,v in ipairs(g.texture_coordinates) do
for ki,vi in ipairs(v) do
print("texture_coord",k,ki,vi.x,vi.y)
end
end