CODEF
CODEF copied to clipboard
using codef_3d.js
I am trying to convert the Mindbomb 3D Ball Screen from JS/Codef to C# for conversion to C++/DirectX which I have wanted to do for years but I am having problems with the perspective calculations.
There seems to be no documentation for codef_3d.js
I have tried to separate the shape definition from the transformation but I still don't understand how this works.
Given this setup: my3d=new codef3D(ballcanvas, 400, 40, 1, 900 ); my3d.vectorball_img(myobjworm, ball ); my3d.group.scale.x=my3d.group.scale.y=my3d.group.scale.z=30; my3d.group.position.z = mover; And these rotations: my3d.group.rotation.x+=0.00; my3d.group.rotation.y+=0.04; my3d.group.rotation.z+=0.00;
Is this updating a COPY of the shapes definition: my3d.group.children[i].position.y = siny-2;
But how is this transformed for display into real x,y coordinates? Are the bobs transformed and then sorted in Z-order so the furthest away are displayed first? What are the perspective calculations given the depth of the field and current mover position?
Codef3d is just a super tiny wrapper around an ancient version of three.js (version 49 I believe). So you need to consult the three.js docs to figure this all out, although good luck, because they are famously incomplete.
Even though I have used the codef_3d.js myself a lot, I still don't understand how it works fully! :-)
the command... my3d.group.children[i].position.y=siny-2; would adjust ONLY the "y" position of element "i" of the 3d group to a static position of whatever "siny-2" is.
If you wanted to change ALL of the component elements, then maybe something like this....
for (var a=0; a<max_number_of_sprites; a++){ my3d.group.children[a].position.x = new position; my3d.group.children[a].position.y = new position; my3d.group.children[a].position.z = new position; }
Of course these new positions could be calculated "on the fly", or drawn from a precalc array, depending on how you wish to do it.
Sadly many of the screens I've made using the codef_3d have often been as a result of more luck than judgement! (Sorry!)