Re: Xors3d for Purebasic
Posted: Thu Jun 23, 2011 5:43 pm
That was fast, thanks chi!
704 looks great, nice physics overhaul. Can't wait to test it.
704 looks great, nice physics overhaul. Can't wait to test it.
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
Declare.f calcleng( x.f, y.f, z.f)
Procedure.f RandF(Min.f, Max.f, Resolution.i = 10000)
ProcedureReturn (Min + (Max - Min) * Random(Resolution) / Resolution)
EndProcedure
Global.f dx, dy, x, y, z
Global wd, ht, i, count, n, iter
Global.f w, leng, tx, ty, tz, tem
Global.f cr, ci, cj, ck, wk, inc, distance
Global mand, zval
Global.f angle
Dim v(100000) ; to hold vertices indexes
Define.f red, green, blue
wd = 500
ht = 500
;defines the shape of the Julia Set
cr = -0.200
ci = 0.800
cj = 0.000
ck = 0.000
wk = 0.000
;mand = 0 is Julia Set
;mand = 1 is Mandelbrot 3D
mand = 1
;zval = 1 shows entire set
;zval = 0 cuts set in half
;zval = 0 is an interesting effect
zval = 1
iter = 5
inc = 5
;#quat = 1
zval = 1
iter = 5
inc = 5
XIncludeFile #PB_Compiler_Home + "\Compilers\Xors3d.pbi"
XIncludeFile #PB_Compiler_Home + "\Compilers\Xors3d_FastImage.pbi"
xGraphics3D( 640, 480, 32, #False, #True)
; initialize fastimage font + image
xInitDraw()
xSetImageFont(xLoadImageFont(".\media\Tahoma.txt"));xSetTextureFiltering(TF_ANISOTROPIC)
light = xCreateLight(1)
;xAntiAlias(True)
mesh = xCreateMesh ()
xMeshPrimitiveType (mesh, 1)
surf = xCreateSurface(mesh, brush)
xSurfacePrimitiveType (surf, 1)
;wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
zz.f
foo.l
;iterations = 2266000
iterations = 2000000
count = 0
If zval = 0
zz = 2.0
Else
zz = 4.0
EndIf
For foo = 0 To iterations
;x.f = RandF(0, 1)
;y.f = RandF(0, 1)
x.f = RandF(-2, 2)
y.f = RandF(-2, 2)
z.f = zz*RandF(0, 1) -2.0
;calls the quaternion calculation
leng.f = calcleng(x,y,z)
If leng < 4
red = (x+Cos(15*leng))*255
green = (y+Sin(1-leng)*Cos(5*leng))*255
blue = (z+Sin(0.75*leng))*255
If red < 0 : red = 0 : EndIf
If green < 0 : green = 0 : EndIf
If blue < 0 : blue = 0 : EndIf
If red > 255 : red = red-255 : EndIf
If green > 255 : green = green-255 : EndIf
If blue > 255 : blue = blue-255 : EndIf
i+1
;xAddVertex (Surface *surface, float x, float y, float z, float u=0.0f, float v=0.0f, float w=0.0f)
v(i)= xAddVertex(surf, x, y, z)
xVertexColor(surf, v(i), red, green, blue, 1)
EndIf
Next
;the following line is to make xEntityFX(mesh, 2|1) to not giving an error
tri1 = xAddTriangle(surf, v(0), v(0), v(0))
;wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
;creating the camera
cam = xCreateCamera()
xMoveEntity(cam, 0, 0, -7)
xEntityFX(mesh, 2|1)
xFlipMesh(mesh)
xUpdateNormals(mesh)
While(Not (xKeyHit(#KEY_ESCAPE) Or xWinMessage("WM_CLOSE")))
xTurnEntity(mesh, 0, 1, 0)
xUpdateWorld()
xRenderWorld()
xText(10, 10, "Mandelbrot set 3D!")
xText(10, 30, "FPS: " + xGetFPS())
xFlip()
Wend
End
Procedure.f calcleng( x.f, y.f, z.f)
w.f: kr.f: ki.f: kj.f: kk.f
w = wk
n = 0
If mand = 1 ;full Mandelbrot set
kr = x
ki = y
kj = z
kk = 0
Else ;else draw Julia Set
kr = cr
ki = ci
kj = cj
kk = ck
EndIf
While n < iter
tem = x+x
x = x*x-y*y-z*z-w*w+kr
y = tem*y + ki
z = tem*z + kj
w = tem*w + kk
n+1
distance = x*x+y*y+z*z+w*w
If distance > 4
n = iter
EndIf
Wend
;Return distance
ProcedureReturn distance
EndProcedure
Code: Select all
XIncludeFile #PB_Compiler_Home + "\Compilers\Xors3d.pbi"
XIncludeFile #PB_Compiler_Home + "\Compilers\Xors3d_FastImage.pbi"
xGraphics3D( 640, 480, 32, #False, #True)
; initialize fastimage font + image
xInitDraw()
xSetImageFont(xLoadImageFont(".\media\Tahoma.txt"));xSetTextureFiltering(TF_ANISOTROPIC)
light = xCreateLight(1)
;xLightColor(light, 255,255,255)
;xAntiAlias(True)
Dim v(1000000)
mesh = xCreateMesh ()
xMeshPrimitiveType (mesh, 1)
surf = xCreateSurface(mesh, brush)
xSurfacePrimitiveType (surf, 1)
For i=0 To 100000
;MP_SetPrimitives(Entity, i, Random(200,0), Random(200,0), Random(200,0), $FFFFFFFF)
x = Random(200)-100:y = Random(200)-100:z = Random(200)-100
If y< -80 And z< -80
r=255:g=0:b=0
ElseIf x < -80 And z< -80
r=0:g=255:b=0
ElseIf x< -80 And y< -80
r=0:g=0:b=255
Else
r=255:g=119:b=119
EndIf
;(x - x0)^2 + (y - y0)^2 + (z - z0)^2 <= r^2
;check if point inside a specific sphere:
If (Pow(x,2) + Pow(y,2) + Pow(z,2)) <= 4900
r=0:g=0:b=255
EndIf
v(i) = xAddVertex(surf, x, y, z, 0, 1)
xVertexColor(surf, v(i), r, g, b, 1)
Next
tri1 = xAddTriangle(surf, v0, v0, v0)
xUpdateNormals(mesh)
;creating the camera
cam = xCreateCamera()
xPositionEntity(mesh, 0,50,0)
xPositionEntity(cam, 0, 180, -500)
xRotateEntity(cam, 15,0,0)
xVertexCoords(surf, v2, 3, 5, 0)
;t1 = xLoadTexture("green.png")
;xEntityTexture(mesh, t1)
xEntityFX(mesh, 2|1)
;xFlipMesh(mesh)
xUpdateNormals(mesh)
While(Not (xKeyHit(#KEY_ESCAPE) Or xWinMessage("WM_CLOSE")))
xTurnEntity(mesh, 0,0.5, 0)
xUpdateWorld()
xRenderWorld()
xText(10, 10, "Hello 3D World!")
xText(10, 30, "FPS: " + xGetFPS())
xFlip()
Wend
EndCode: Select all
XIncludeFile #PB_Compiler_Home + "\Compilers\Xors3d.pbi"
XIncludeFile #PB_Compiler_Home + "\Compilers\Xors3d_FastImage.pbi"
xGraphics3D( 640, 480, 32, #False, #True)
; initialize fastimage font + image
xInitDraw()
xSetImageFont(xLoadImageFont(".\media\Tahoma.txt"))
;xHidePointer()
camera = xCreateCamera()
light = xCreateLight()
cube = xCreateCube()
line0 = xCreateLine3D (0, 0, 0, 1, 1, 2, 0, 255, 0, 255)
xPositionEntity(line0, -2.0, 0.0, 5.0)
xPositionEntity(cube, 0.0, 0.0, 10.0)
;While Not xKeyHit(1) Or xWinMessage("WM_CLOSE")
While(Not (xKeyHit(#KEY_ESCAPE) Or xWinMessage("WM_CLOSE")))
xTurnEntity(line0, 0.3, 0.3, 0.3)
xTurnEntity(cube, 0.1, 0.1, 0.1)
xRenderWorld()
xText(10, 10, "3D Line")
xText(10, 30, "FPS: " + xGetFPS())
xFlip()
Wend
End
Code: Select all
XIncludeFile #PB_Compiler_Home + "\Compilers\Xors3d.pbi"
XIncludeFile #PB_Compiler_Home + "\Compilers\Xors3d_FastImage.pbi"
Declare.f CurveValue( newvalue.f, oldvalue.f, increments )
Declare CreateCheckerTexture()
Declare Reset()
; initialize graphics mode
xGraphics3D( 640, 480, 32, #False, #True)
; initialize fastimage font + image
xInitDraw()
xSetImageFont(xLoadImageFont(".\media\Tahoma.txt"))
;wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
;wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
#maxCameraAngle = 85.0
#minCameraDistance = 50
#maxCameraDistance = 110
xCreateLog(LOG_HTML, LOG_INFO, "Concave body.html")
xHidePointer()
cameraDistance = 60
Global camPiv = xCreatePivot()
Global camera= xcreatecamera(camPiv)
xPositionEntity(camera,0,20, -cameraDistance)
xCameraClsColor(camera, 96, 128, 192)
xRotateEntity(camPiv, maxCameraAngle / 2, 45, 0)
xCameraEnableShadows(camera)
lightRed = xcreatelight()
xRotateEntity(lightRed, 60, 15, 0)
xLightColor(lightRed, 255, 255, 255)
lightBlue = xcreatelight()
xRotateEntity(lightBlue, 60, 195, 0)
xLightColor(lightBlue, 128, 128, 255)
xLightEnableShadows(lightBlue, True)
xLightShadowEpsilons(lightBlue, 0.0001, 0.0001)
xSetShadowParams(2, 0.75)
xInitShadows(1024, 0, 0)
tex = CreateCheckerTexture()
xScaleTexture(tex, 0.1, 0.1)
Global ground = xCreateCube()
xScaleEntity(ground, 100, 1, 100)
xEntityColor(ground, 64, 64, 64)
xEntityTexture(ground, tex)
xEntityFX(ground, #FX_FULLBRIGHT)
xEntityAddBoxShape(ground, 0)
Global concave = xCreateTorus(16, 1, 0.5)
;xScaleEntity(concave, 4.0, 4.0, 4.0)
xScaleMesh(concave, 4.0, 4.0, 4.0) ; don't use xScaleEntity with a concave body. It's a temporary issue
xEntityAddConcaveShape(concave, 100.0)
xEntityColor(concave, 255, 128, 32)
xEntityTexture(concave, tex)
Reset()
Global column = xCreateCylinder()
xScaleEntity(column, 1.0, 5.0, 1.0)
xEntityColor(column, 32, 128, 255)
xPositionEntity(column, 0.0, 5.0, 0.0)
xEntityAddCylinderShape(column, 0.0)
xEntityTexture(column, tex)
xPhysicsDebugRender(PXDD_WIREFRAME)
While Not xKeyDown(#KEY_ESCAPE)
; camera control
If xKeyDown(#KEY_W) : xMoveEntity( camera, 0, 0, 0.5 ) : EndIf
If xKeyDown(#KEY_S) : xMoveEntity( camera, 0, 0, -0.5 ) : EndIf
If xKeyDown(#KEY_A) : xMoveEntity( camera, -0.5, 0, 0 ) : EndIf
If xKeyDown(#KEY_D) : xMoveEntity( camera, 0.5, 0, 0 ) : EndIf
mxs.f = CurveValue(xMouseXSpeed() * mousespeed, mxs, camerasmoothness)
mys.f = CurveValue(xMouseYSpeed() * mousespeed, mys, camerasmoothness)
camxa.f = Mod( camxa - mxs, 360 )
camya.f = camya + mys
If camya < -89 : camya = -89 : EndIf
If camya > 89 : camya = 89 : EndIf
xMoveMouse( xGraphicsWidth() / 2, xGraphicsHeight() / 2 )
xRotateEntity( camera, camya, camxa, 0.0 )
If xKeyHit(#KEY_SPACE)
Reset()
EndIf
If xKeyHit(#KEY_x)
xRotateEntity(ground, 20, 0, 0.0)
EndIf
;UpdateCamera()
rot=rot+100
xRotateEntity(concave, -90.0, rot, 0.0)
xUpdateWorld()
xRenderWorld(1, True)
xText(10, 10, "FPS: " + xGetFPS())
xText(10, 30, "Press <Space> to reset scene")
xflip()
Wend
End
Procedure Reset()
xEntityReleaseForces(concave)
xPositionEntity(concave, 0.0, 20.0, 0.0)
xRotateEntity(concave, -35.0, 0.0, 0.0)
xEntityWakeUp(concave)
EndProcedure
Procedure CreateCheckerTexture()
size = 256
lTex.f = xCreateTexture(size, size)
xSetBuffer(xTextureBuffer(lTex))
xColor(222, 222, 222)
xRect(0, 0, size, size, 1)
xColor(255, 255, 255)
xRect(0, 0, size / 2, size / 2, 1)
xRect(size / 2, size / 2, size / 2, size / 2, 1)
xSetBuffer(xBackBuffer())
ProcedureReturn lTex
EndProcedure
Procedure.f CurveValue( newvalue.f, oldvalue.f, increments )
If increments > 1 : oldvalue = oldvalue - (oldvalue - newvalue) / increments : EndIf
If increments <= 1 : oldvalue = newvalue : EndIf
ProcedureReturn oldvalue
EndProcedure
At the moment I do NOT recommend purchasing a license for Xors3d as there hasn't been updates for well over a year and the engine developers have all gone missing. It's a great engine and works as expected, but its future is really uncertain. Don't purchase.applePi wrote:my opinion it is a good engine but its price $100 which are may be suitable for games makers but too much for the hobbyist , while a $50 are more suitable.
Squid posted a sign of life (http://area.xors3d.com/forums/viewtopic.php?f=5&t=1004) two days ago! So maybe...eesau wrote:... and the engine developers have all gone missing.
Okay, didn't know that. Good news I guess, glad to hear he wasn't dead.chi wrote:Squid posted a sign of life (http://area.xors3d.com/forums/viewtopic.php?f=5&t=1004) two days ago! So maybe...