Author Topic: simple 3d  (Read 2889 times)

Mopz

  • Guest
simple 3d
« on: June 07, 2013, 07:22:04 PM »
Well, this is just crap so far. But I'll add some better looking examples soon. I first wanted to write something with the math3d.lib that DJ posted. But I'm so damn used to old OpenGL with its matrix stack, so I decided to write a quick stack based library for dealing with common 3d transformations instead.

Now, the zip only contains the lib and an example showing some wavy dots. I'll add some images and better examples, like the "balls" movies I posted on youtube. I hope to create something with retro quality. 

http://www.naalaa.com/examples/simple3dtest.zip
« Last Edit: June 08, 2013, 08:37:31 PM by Mopz »

Mopz

  • Guest
Re: simple 3d
« Reply #1 on: June 07, 2013, 09:45:23 PM »
It's a tad nastier already.


DJLinux

  • Guest
Re: simple 3d
« Reply #2 on: June 08, 2013, 07:02:42 AM »
Nice example but needs "MSVCR100.DLL" on the target box.

Joshy

Mopz

  • Guest
Re: simple 3d
« Reply #3 on: June 08, 2013, 09:04:34 AM »
Added another thing to the zip. If you don't want to download and compile, you can watch a youtube clip instead.

http://youtu.be/o22y84H_ui4

@DJ You're using the binaries with DLL support, right? That one was compiled in VC2010 (not BCC, as the official version). Probably I can remove that dependancy somewhere :)

Mopz

  • Guest
Re: simple 3d
« Reply #4 on: June 08, 2013, 08:16:22 PM »
And a face of fire, using the vertices from an OFF file:

http://youtu.be/9Cu7PUB9aV0

The source code of all these examples can be downloaded from:

http://www.naalaa.com/examples.html

Mopz

  • Guest
Re: simple 3d
« Reply #5 on: June 08, 2013, 10:35:13 PM »
And a twisted donut:

http://youtu.be/uLpaDIAtwzk

Mopz

  • Guest
Simple 3D for Java
« Reply #6 on: June 10, 2013, 04:18:17 PM »
Making some examples that works with java too. Can't do additive blitting for the nice lighting effects, and therefor have to quicksort the vertices (thank god, I already wrote a lib for that):

http://www.naalaa.com/applets/test7.html

Code: [Select]
rem test 2.

import "Simple3D.lib"
import "Speed.lib"
import "QuickSort.lib"

hidden:

set redraw off

load image 0, "assets/ball32.bmp"
set image colorkey 0, 255, 0, 255

vertices#[16][16][3]
renderVertices#[256][3]
for z = 0 to 15
for x = 0 to 15
vertices[x][z][0] = (float(x) - 8.0)/8.0
vertices[x][z][1] = 0.0
vertices[x][z][2] = (float(z) - 8.0)/8.0
next
next

proc s3dSetView 65.0, 0.1, 4.0

a# = 0.0
do
a = a + 2.0
if shouldDraw
set color 0, 0, 128
cls
set color 255, 255, 255


proc s3dClearTransformation
proc s3dTranslate 0.0, 0.0, 2.0
proc s3dRotateX 40.0
proc s3dRotateY a*0.2

set additive true
i = 0
rv#[3]
for z = 0 to 15
for x = 0 to 15
vertices[x][z][1] = sin(a + float(x)*16.0)*cos(a + float(z)*8.0)*0.5
proc s3dProject_3f rv, vertices[x][z][0], vertices[x][z][1], vertices[x][z][2]
renderVertices[i][0] = rv[0]
renderVertices[i][1] = rv[1]
renderVertices[i][2] = rv[2]
i = i + 1
next
next

proc QuickSort2DF renderVertices, 2

for i = 255 downto 0
intens = int(255.0*renderVertices[i][2]/2.0)
set color 0, 0, 128, intens - 80

proc DrawImageScaled 0, renderVertices[i][0], renderVertices[i][1], 1.25/renderVertices[i][2]
next

set additive false
redraw
endif
shouldDraw = SPD_HoldFrameDraw(60)
until keydown(27, true) or not running()

procedure DrawImageScaled(img, centerx#, centery#, s#)
h = int(float(height(img))*s)
dv# = 1.0/float(h)

hw = int(0.5*s*float(width(img)))
xstart = int(centerx) - hw
xend = int(centerx) + hw
y = int(centery) - h/2

v# = 0.0
ym = h - 1
for iy = 0 to ym
draw hraster img, y + iy, xstart, xend, 0.0, v, 1.0, v
v = v + dv
next
endproc
« Last Edit: June 10, 2013, 04:50:41 PM by Mopz »