Page 1 of 3
3D library
Posted: Mon May 19, 2014 12:07 pm
by MaxV
Hello,
I'm converting to Livecode a 3D library that I used on another programming language. I want to release it under GPL.
I'm working on arrays, a lot of arrays, so I need some trick to reduce the line to write.
For example I wrote this:
function r3d_translate x,y,z
#Create a translation matrix:
#1 0 0 X
#0 1 0 Y
#0 0 1 Z
#0 0 0 1
repeat with i=1 to 4
repeat with j=1 to 4
if i = j then
put 1 into temp[j]
else
put 0 into temp[j]
end if
end repeat
end repeat
put x into temp[1][4]
put y into temp[2][4]
put z into temp[3][4]
return temp
end r3d_translate
Is there a better solution or more elegant solution to write it?
Re: 3D library
Posted: Tue May 20, 2014 5:09 pm
by MaxV
I'm working on the conversion of this old libray, it doesn't use OpenGL, just flat 2D polygons.
I already converted all matrix functions needed, now I need more information about creating a 2D drawing in Livecode.
Where I can found these information?
This is my goal:
Re: 3D library
Posted: Wed May 21, 2014 7:34 am
by malte
What kind of information are you looking for?
Re: 3D library
Posted: Wed May 21, 2014 9:19 am
by MaxV
Hi malte,
I noticed that Livecode permit to draw using the "paint tools". I need to know how to create and specify the vertexes (x,y) of a polygon.
Re: 3D library
Posted: Wed May 21, 2014 12:04 pm
by malte
Hi, you might be way better off using the graphic primitive. Using the paint tools will be much slower.
Best,
Malte
Re: 3D library
Posted: Wed May 21, 2014 1:24 pm
by bn
Hi Max,
have a look at this thread
http://forums.runrev.com/viewtopic.php?f=9&t=7824
last stack is a sort of pseudo 3D made with graphic objects
or this thread
http://forums.runrev.com/viewtopic.php?f=9&t=13399
Kind regards
Bernd
Re: 3D library
Posted: Wed May 21, 2014 2:26 pm
by MaxV
malte wrote:Hi, you might be way better off using the graphic primitive. Using the paint tools will be much slower.
I imagined that a single image was faster and less memory consuming; but your are saying me that is better graphic polygonal object for each 3D object?
Unfortunately if I use polygonal objects, I need one fore each face of the solid; because I need to change each face luminosity (color) to give a correct 3D effect.
Look at this picture:
It's just a simple cube with only 3 faces shown, but they are 3 polygons.
I'm not an expert, but are you sure that using polygons is the best way?
Re: 3D library
Posted: Wed May 21, 2014 2:58 pm
by MaxV
I write here some code to explain me better.
A the present I'm using the following code:
on mouseUp
set the style of the templateGraphic to polygon
create graphic face1
create graphic face2
create graphic face3
put "40,60" & return into temp
put "60,40" & return after temp
put "40,20" & return after temp
put "20,40" & return after temp
put "40,60" & return after temp
set the points of graphic face1 to temp
set the opaque of graphic face1 to true
set the backgroundcolor of graphic face1 to 230,0,0
put "40,60" & return into temp
put "20,40" & return after temp
put "20,80" & return after temp
put "40,100" & return after temp
put "40,60" & return after temp
set the points of graphic face2 to temp
set the opaque of graphic face2 to true
set the backgroundcolor of graphic face2 to 255,0,0
put "40,60" & return into temp
put "60,40" & return after temp
put "60,80" & return after temp
put "40,100" & return after temp
put "40,60" & return after temp
set the points of graphic face3 to temp
set the opaque of graphic face3 to true
set the backgroundcolor of graphic face3 to 200,0,0
end mouseUp
but I'd prefer images, something like :
Code: Select all
set the rect of the templateImage to 100,100,400,400
create image
choose polygon tool
#here I don't know how to continue...
What do you think?
What is the best solution?
Re: 3D library
Posted: Wed May 21, 2014 5:48 pm
by bn
Hi Max,
I think you should go with graphics.
If you want to go with images then here is some code, combining your two scripts.
Code: Select all
set the rect of the templateImage to 10,10,400,400
create image
choose polygon tool
#here I don't know how to continue...
put "40,60" & return into temp
put "60,40" & return after temp
put "40,20" & return after temp
put "20,40" & return after temp
put "40,60" & return after temp
repeat with i = 2 to the number of lines of temp
drag from line i - 1 of temp to line i of temp
end repeat
choose pointer tool
Kind regards
Bernd
Re: 3D library
Posted: Fri May 23, 2014 9:36 pm
by ChessGredon
MaxV, this is the REBOL language, right? Just wanted to ask, I have seen it rarely, but looks powerful, easier to write than C# and cool outfit. Is it close to LiveCode?
Re: 3D library
Posted: Tue May 27, 2014 11:00 am
by MaxV
Yes, it is. It's very simpler and powerful. It's like Livecode, but you have to write jus few line of text, no IDE, no binary file format.
Now it's opensource and you can get the source here:
https://github.com/rebol/rebol
A simple e guide to Rebol is here:
http://www.re-bol.com/rebol.html
Re: 3D library
Posted: Tue May 27, 2014 11:01 am
by MaxV
However Rebol now is abandoned, so I switched to Livecode.
Re: 3D library
Posted: Wed May 28, 2014 1:00 pm
by FredBeck
Hi there,
I'm very interested in this.
I'm a designer (sailing boats mainly) and amateur programmer.
I use Rhino as 3d modeler and it has a graphical programming language called grasshopper (see my page).
I'd love to see lc and gh working together.
I don't have time right now to check all these posts but
I'll be back!
F.
Re: 3D library
Posted: Thu May 29, 2014 9:44 am
by MaxV
I'm near to finish, I have just to correct last 2 functions (
render and
r3d_Render2dTriangles_Simple). You can see the developments here:
https://github.com/angerangel/LCR3D/blob/master/r3d.txt
Re: 3D library
Posted: Thu May 29, 2014 11:25 am
by FredBeck
Nice, I wasn't expecting so much! Thank you so much for sharing! I'll take a look soon and post my questions.
Can you put an example of
#"world" contains a list of object to render:
# it has
#[1]["model"] (contains faces and points of the boject)
#[1]["properties"] (contains traslation, rotation and other transormationof the object, very usefu in animation)
#[1]["color"] (the color to render the object)
I'll make a tool in grasshopper to format meshes correctly. I already imported polylines with a bunch of attributes the other day.