On occasion I like to look through old posts to find juicy tidbits I may not be aware of. I am finding a lot are un-answered or fail to use functions that are more suited to the question. The object of this post is; if you have an answer for an un-answered post, an answer using a seldom used function or just think an answer to a post just needs to be added to this thread as a one stop shop of answers for beginners, that is what this thread is for. So, to begin with here are two.
1:
Help please !! creating objects from triangles
I have never seen this obvious answer using the seldom used function - Add Mesh To Vertexdata to answer this question.
` turn sync on and set rate to 60
sync on
sync rate 60
` turn backdrop on and set color to black
backdrop on
color backdrop 0
` disable autocam and set camera position
autocam off
position camera 0, 0, -50
` create plane from two triangle objects
make object triangle 1, 10, -10, 0, -10, -10, 0, -10, 10, 0
make object triangle 2, -10, 10, 0, 10, 10, 0, 10, -10, 0
` create meshes from objects
make mesh from object 1, 1
make mesh from object 2, 2
` delete objects
delete object 1
delete object 2
` add mesh 2's vertexdata to mesh 1
lock vertexdata for mesh 1
add mesh to vertexdata 2
indxcnt = get vertexdata index count()
vertcnt = get vertexdata vertex count()
unlock vertexdata
` make object from mesh 1's combined vertexdata and set object culling on
make object 1, 1, 0
set object cull 1, 1
` delete meshes
delete mesh 1
delete mesh 2
` main loop
do
set cursor 0, 0
print "Indices: ";indxcnt
print "Vertices: ";vertcnt
` update display
sync
` turn object 1 on y axis
yrotate object 1, wrapvalue(object angle y(1)+1)
loop
2:
Default FOV
Given the formula for a projection matrix and the function Projection Matrix4, with a little algebra we can calculate to find the missing values.
null as integer
null = make matrix4(1)
sync on
sync rate 60
backdrop on
color backdrop 0
projection matrix4 1
do
set cursor 0, 0
print "Projection Matrix:"
print
PrintMatrix4(1)
print
print "Camera Vertical FOV: ";2.0*atan(1.0/get matrix4 element(1, 5))
print "Camera Horizontal FOV: ";2.0*atan(1.0/get matrix4 element(1, 0))
print "Camera Aspect Ratio: ";get matrix4 element(1, 5)/get matrix4 element(1, 0)
sync
loop
end
function PrintMatrix4(matID as integer)
local i as integer
local j as integer
local element as integer
for i = 0 to 3
for j = 0 to 3
print str$(get matrix4 element(matID, element));
if j<3 then print ", ";
inc element
next j
print
next i
endfunction
Please! Post only if you have something to contribute. If you find someone’s code in error please PM them so they can make the appropriate corrections.
Thank You.