Avoid Vertexnx/y/z Problems

Blitz3D Forums/Blitz3D Programming/Avoid Vertexnx/y/z Problems

jfk EO-11110(Posted 2011) [#1]
I've spent several hours in finding the cause for some rare but strange artefacts in the alignement of the camera to a triangle, using vertexnx etc.

When you got similar problems then try this:

nx#=filterTroubles#(nx#)

function filterTroubles#(v#)
if v#=0 then return 0.0001
return v#
end function

Additionally I might suggest: to align an entity to the roll of two points (eg. to align the camera to a triangle) you should not use ProjectCamera to project the 3D coords to the 2D Screen, instead position 3 pivots at the tri-vertices coords, then parent them to the camera, then store the camera pitch yaw roll (for being able to restore it later), then rotate the camera to 0,0,0. Now you can use ENtityX and Y instead of ProjextedX and Y to be used with Atan2 to determine the angle you need to turn the camera roll in order to align the Triangle to the Camera Viewport, but amusingly you need to exchange X and Y (x#=projectedX becomes x#=entityy(piv)...). Probably I will make a more detailed tutorial about this thing soon.
You do this to prevent rounding errors that will occur when you ProjectCamera due to the Pixel resolution vs the 32 bit precision in 3d space.


Floyd(Posted 2011) [#2]
You might get some mileage out of this old code.

Be sure to read the comments before and after the code. Maybe it will make sense.