Author Topic: depth sphere[BMAX]  (Read 6131 times)

0 Members and 1 Guest are viewing this topic.

Offline JumpMan

  • C= 64
  • **
  • Posts: 45
  • Karma: 11
    • View Profile
depth sphere[BMAX]
« on: January 15, 2007 »
here is some code I converted to blitzmax originally made by tracer for bplus I also added some controlls. is really neat.

Code: [Select]
Strict
' * DEPTH COLORED 3D DOT BALL *
' *****************************
' * CODING BY TRACER          *
' * TRACERBB@HOTMAIL.COM      *
' *****************************

Global dots_in_ball# = 2440.0 ' How many dots are in the ball?

' Globals For the 3d.

Type Tnode
Field threeDx#
Field threeDy#
Field threeDz#
Field color
Global twoDx1#
Global twoDy1#
Global twoDx2#
Global twoDy2#

End Type

Global numpoints# = dots_in_ball ' Number of points in the point table.
Global distance#  = 400.0 ' Needed For perspective.
Global vx# ' X location.
Global vy# ' Y location.
Global vz# ' Z location.
Global multiplier#=0.000777
' Arrays used by 3d code.
Global points#[numpoints, 3] ' Holds the point locations of the game over 3d.

Graphics 640,480,16

initdots()

' make points on the surface of a sphere
' calculation To make a sphere:
' x = Cos(theta) * Cos(phi)
' y = Cos(theta) * Sin(phi)
' z = Sin(theta)
' where theta = -90 To 90
' And phi = 0 To 360

' Loop till esc is pressed.
'setfont("agentorange.ttf",16)
While Not KeyDown(KEY_ESCAPE)
threed() ' Call the threed thing.
SetColor 255,255,255
DrawText "Depth Colored Real 3D Dot Ball",0,0
DrawText "origina Coding by Tracer For the Blitz CD.",0,15
DrawText "modified by me",0,30
DrawText "Use up/down arrow Keys To adjust multiplier",0,45
DrawText "multiplier = "+multiplier,0,60
Local dummy = MouseX() ' Removes the mouse from fullscreen.
If KeyDown(KEY_DOWN) Then
multiplier =multiplier-0.001
initdots()
EndIf
If KeyDown(KEY_UP) Then
multiplier=multiplier+0.001
initdots()
EndIf

Flip(0) ' Flip the screen.
Cls ' Clear the screen.
Wend
Function initdots()
For Local t= 0 To dots_in_ball-1
Local xd# = ((t*multiplier) Mod 180.0)-90.0    'Rnd(-90,90)
points[t,0] = (Cos(xd) * 10.0) * (Cos(t) * 10.0)
points[t,1] = (Cos(xd) * 10.0) * (Sin(t) * 10.0)
points[t,2] = Sin(xd) * 100.0
'points[t,0] = x0
'points[t,1] = y0
'points[t,2] = z0
Next

End Function

Function threed()
vx# = vx# + 0.5 ' X rotation speed of ball.
vy# = vy# + 0.5 ' Y rotation speed of ball.
vz# = vz# + 0.5 ' Z rotation speed of ball.

For Local n = 0 To numpoints-1
Local x3d = points[n, 0]
Local y3d = points[n, 1]
Local z3d = points[n, 2]
       
Local ty# = ((y3d * Cos(vx#)) - (z3d * Sin(vx#)))
Local tz# = ((y3d * Sin(vx#)) + (z3d * Cos(vx#)))
Local tx# = ((x3d * Cos(vy#)) - (tz# * Sin(vy#)))
tz# = ((x3d * Sin(vy#)) + (tz# * Cos(vy#)))
Local ox# = tx#
tx# = ((tx# * Cos(vz#)) - (ty# * Sin(vz#)))
ty# = ((ox# * Sin(vz#)) + (ty# * Cos(vz#)))
Local nx  = Int(512 * (tx#) / (distance - (tz#))) + 320
Local ny  = Int(240 - (512 * ty#) / (distance - (tz#)))
        'If tz>0 Then
SetColor 0,tz+100,(tz#+100)
Plot nx,ny'
'EndIf
Next
End Function

' This Function looks at the z-value of the pixel
' And sets the color accoordingly.
Function Color(t#)
SetColor 0,0,(t+200.0)',(t+200.0),(t+200.0)
End Function
« Last Edit: July 21, 2007 by Shockwave »

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: depth sphere
« Reply #1 on: January 15, 2007 »
Thats genius & welldone Jumpman, and thanks for submitting the code.
With the multiplier set around 0.075 it looks really cool.

Cheers,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: depth sphere
« Reply #2 on: January 15, 2007 »
exe exe exe  ;)
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: depth sphere
« Reply #3 on: January 15, 2007 »
Yip! Exe please! :) Have some Karma for the source though. Thanks for posting it Jumpman!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline JumpMan

  • C= 64
  • **
  • Posts: 45
  • Karma: 11
    • View Profile
Re: depth sphere
« Reply #4 on: January 15, 2007 »
I have added the zip which includes a source and exe.

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: depth sphere
« Reply #5 on: January 15, 2007 »
Bravo, reminds me of a marble if you hold up/down mighty fine work

Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: depth sphere
« Reply #6 on: January 16, 2007 »
Nice FX. Congratulations.
Thanks for sharing both, exe and source !!!
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline mind

  • Texture-San
  • DBF Aficionado
  • ******
  • Posts: 2324
  • Karma: 85
    • View Profile
    • boredom is a beatiful thing.
Re: depth sphere
« Reply #7 on: January 16, 2007 »
doesnt run on this laptop... i think the error message is something like "unable to calculate texture size"..

p3-700something with an ati mobility 128something..
Challenge Trophies Won:

Offline JumpMan

  • C= 64
  • **
  • Posts: 45
  • Karma: 11
    • View Profile
Re: depth sphere
« Reply #8 on: January 16, 2007 »
it runs any computer with at least dx7 and a threed graphics card minimum. Most likely it is not compatible with the integrated graphics card.  :(

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: depth sphere
« Reply #9 on: January 16, 2007 »
Nice, original, effect and definitely thanks for uploading an exe!
Well done.
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: depth sphere
« Reply #10 on: January 16, 2007 »
Very nice indeed! Thanks for posting the exe :D Now add a scroll, music, logo and some stars and there's your entry or the II comp (if you wanted to enter) :)

Incidentally this compresses to 47kb with UPX showing that Bmax would be a fine tool to make small intros / site-tros :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: depth sphere
« Reply #11 on: January 16, 2007 »
Yeah that'll be cool, and whilst your at it - see if Tracer will pop by! :)
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline JumpMan

  • C= 64
  • **
  • Posts: 45
  • Karma: 11
    • View Profile
Re: depth sphere
« Reply #12 on: January 17, 2007 »
I don't think he would mind sence then only thing that is his is the shape. the math and algorith are allover the internet. what I give myself credit for is the multyplier. That is all my idea and is what makes the shape interesting.
I even inproved on the color scheme from original post. below is code I downloaded some where from a Qbasic forum years ago and converted to Blitzmax: 
Code: [Select]
AppTitle = "cube"
Type Tnode
Field x#
Field y#
Field z#
End Type

Global  node:tnode
Global  X, Y, Z, sX#, sY#,sXs#, sYs#, D#
Global  AngleAxisz#, AngleAxisx#, AngleAxisy#, mZ#
Global  sinAngleAxisz#,cosAngleAxisz#, cosAngleAxisx#, sinAngleAxisx#, sinAngleAxisy#, cosAngleAxisy#
Global  nodeList:TList

RestoreData cube
Local nodes
ReadData nodes

For I = 1 To nodes
node= New tnode
If Not nodeList nodelist = CreateList()
nodelist.addlast(node)
ReadData node.x,node.y,node.z
Next

InitProgram()
MainLoop()
End

Function Calc3D()

X = -1 * X;
Local Xa# = cosAngleAxisz * X - sinAngleAxisz * Z;
Local Za# = sinAngleAxisz * X + cosAngleAxisz * Z
Local Ya# = cosAngleAxisx * Y - sinAngleAxisx * Xa;
X = cosAngleAxisx * Xa + sinAngleAxisx * Y;
Z = cosAngleAxisy * Za - sinAngleAxisy * Ya
Y = sinAngleAxisy * Za + cosAngleAxisy * Ya;
Z = Z + mZ
sX = D * X / Z
sY = D * Y / Z

End Function

Function DrawObject()

Rotateobject
Local I = 1
For node  = EachIn nodeList
X = node.x
Y = node.y
Z = node.z
Calc3D
If  Not (I Mod 2) DrawLine sXs, sYs , sX, sY 'get start and end points before drawing.
sXs = sX; sYs = sY
I = I+1
Next

End Function

Function  InitProgram()

Graphics 640,480
SetOrigin 320, 240
SetColor 255,0,0
D# = 500      'View point And rotation values
mZ# = -400   'shift from z axis away from viewpoint
AngleAxisz# = 0 'spin along y axis; angle of z
AngleAxisx# = 0 'spin along z axiz; angle of x
AngleAxisy# = 0 'spin along x axis; angle of y

End Function

Function  MainLoop()

While Not KeyDown(KEY_ESCAPE)
  Cls
  'AngleAxisz = AngleAxisz + 1; angleAxisz = AngleAxisz Mod 360 'comment out to spin all 3 axis
  AngleAxisx = AngleAxisx + 1; angleAxisx = AngleAxisx Mod 360
AngleAxisy = AngleAxisy + 3; angleAxisy = AngleAxisy Mod 360
DrawObject
Flip
Wend

End Function

Function Rotateobject()

sinAngleAxisz = Sin(AngleAxisz)
cosAngleAxisz = Cos(AngleAxisz)
sinAngleAxisx = Sin(AngleAxisx)
cosAngleAxisx = Cos(AngleAxisx)
sinAngleAxisy = Sin(AngleAxisy)
cosAngleAxisy = Cos(AngleAxisy)

End Function

' replace FACE in restoredata to CUBE to display a cube.

#CUBE 'LOOKING THINGY
DefData 50 'defines number of point to read
DefData -90,-90,-90, -90,-90,90,     -90,-90,90,    90,-90,90
DefData  90,-90,90,   90,-90,-90,     90,-90,-90,  -90,-90,-90
DefData -90,90,-90,  -90,90,90,      -90,90,90,    90,90,90
DefData  90,90,90,    90,90,-90,      90,90,-90,  -90,90,-90
DefData -90,90,-90,  -90,-90,-90,    -90,-90,90,  -90,90,90
DefData  90,90,90,    90,-90,90,      90,-90,-90,  90,90,-90
DefData -90,0,-90,   -90,0,90,       -90,0,90,    90,0,90
DefData  90,0,90,     90,0,-90,       90,0,-90,  -90,0,-90
DefData -90,0,-90,    0,90,0,        -90,0,90,    0,90,0
DefData  90,0,90,     0,90,0,         90,0,-90,   0,90,0
DefData -90,0,-90,    0,-25,0,       -90,0,90,    0,-25,0
DefData  90,0,90,     0,-25,0,        90,0,-90,   0,-25,0
DefData  0,-25,0, 0,90,0

 
« Last Edit: January 17, 2007 by JumpMan »

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: depth sphere
« Reply #13 on: January 21, 2007 »
Yo Jumpman you got PM

Challenge Trophies Won: