major overhaul for Lua API and additions for using texture coordinates
Signed-off-by: Hartmut Seichter <hartmut@technotecture.com>
This commit is contained in:
parent
939195b851
commit
749bb67c6c
10 changed files with 242 additions and 142 deletions
|
@ -6,45 +6,114 @@
|
|||
pw.script:load_all()
|
||||
|
||||
-- vector3
|
||||
local v1 = pw.vector3.new(3,2,1)
|
||||
local v1 = pw.vector3(3,2,1)
|
||||
print("v1 ",v1.x,v1.y,v1.z)
|
||||
|
||||
-- quaternion
|
||||
local q = pw.quaternion.new()
|
||||
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.new(0,0,0,1)
|
||||
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)
|
||||
|
||||
-- bug!
|
||||
-- qm = pw.quaternion.lerp(q,qi,0.5)
|
||||
|
||||
-- axisangle
|
||||
local aa = pw.axisangle.new(v1,0.707)
|
||||
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)
|
||||
|
||||
-- mesh
|
||||
local somemesh = pw.mesh.new()
|
||||
|
||||
somemesh.indices:add(0)
|
||||
somemesh.vertices:add(pw.vector3.new(3,4,5))
|
||||
|
||||
--
|
||||
print(somemesh.vertices)
|
||||
print(somemesh.indices)
|
||||
local g = pw.geometry()
|
||||
g.indices = { 11, 22, 33 }
|
||||
|
||||
|
||||
for i=1,#somemesh.indices do
|
||||
print(i," - ", somemesh.indices:get(i))
|
||||
-- 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
|
||||
|
||||
|
||||
for k,v in ipairs(somemesh.indices) do
|
||||
print(k,v)
|
||||
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
|
||||
|
||||
for k,v in ipairs(somemesh.vertices) do
|
||||
print(k,v)
|
||||
|
||||
-- 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
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue