OK, here is the 'Smash The Wall' physics demo.
Things to note...
The frustum clipping is broken, its a bug, its stuck on portrait, so in landscape, things get clipped a bit short horizontally. This has already been fixed but not upload to the users yet.
The 'DIM z%[1]' is necessary to allow the GLB graphics engine to kick-in/initialise, as its the first command. So its function is not to create a variable but to 'wake' up GLBasic for iXors3D to take over later.
I had trouble with iOS 4.0, this may be a problem with GLB or iXors. Any ways, I set "Base SDK" and "iPhone OS Deployment Target" to 3.2 in the project settings and everything works fine.
Have fun,
Ian
GLOBAL light%
// camera entity
GLOBAL mainCamera% = 0;
// ground entity
GLOBAL ground% = 0;
// control images
GLOBAL control% = 0;
GLOBAL fire% = 0;
GLOBAL wallTexture%
GLOBAL grass%
DIM z%[1]
init()
WHILE 1=1
drawView()
xUpdateWorld(1)
xRenderWorld()
xDrawImage(control%, 190, 190, 0)
xDrawImage(fire%, 5, 270, 0)
xText(0,0,"FPS:"+xFPSCounter(),FALSE,FALSE)
xFlip()
WEND
// initialize engine
FUNCTION init:
xGraphics3D(1)
light%=xCreateLight(0,0)
// create camera
mainCamera% = xCreateCamera(0);
xPositionEntity(mainCamera%, 0.0, 50.0, 50.0, FALSE)
xRotateEntity(mainCamera%, -45.0, 0.0, 0.0, FALSE)
// create ground
ground% = xCreateCube(0);
xScaleEntity(ground%, 100.0, 0.1, 100.0, FALSE)
xEntityAddBoxShape(ground%, 0.0, 0.0, 0.0, 0.0);
grass% = xLoadTexture("Media/grass.png", 1 + 8)
xEntityTexture(ground%, grass%, 0, 0)
xFreeTexture(grass%)
// create wall
wallTexture% = xLoadTexture("Media/logo.png", 1 + 8)
GLOBAL wallSize% = 6
GLOBAL cube%
FOR y% = 0 TO wallSize% - 1
FOR x% = 0 TO wallSize% - 1
cube% = xCreateCube(0)
xPositionEntity(cube%, (x - wallSize% / 2) * 2.0, 1.1 + y * 2.0, 0.0, FALSE)
xEntityTexture(cube%, wallTexture%, 0, 0)
xEntityAddBoxShape(cube%, 1.0, 0.0, 0.0, 0.0)
NEXT
NEXT
// load default font
xSetFont(xLoadFont("Media/Tahoma22"))
// load control images
control% = xLoadImage("Media/control.png");
fire% = xLoadImage("Media/fire.png");
ENDFUNCTION
// checks if button prssed
FUNCTION InButton: x%, y%, cx%, cy%, radii%
x = x - cx
y = y - cy
RETURN (ABS(SQR(x * x + y * y)) <= radii)
ENDFUNCTION
// shoot sphere to wall
FUNCTION ShootSphere:
LOCAL sphere% = xCreateSphere(8, 0)
xPositionEntity(sphere%, xEntityX(mainCamera%, TRUE), xEntityY(mainCamera%, TRUE), xEntityZ(mainCamera%, TRUE), FALSE)
xTFormNormal(0.0, 0.0, -1.0, mainCamera%, 0)
xEntityAddSphereShape(sphere, 1.0, 0.0)
xEntityApplyCentralImpulse(sphere%, xTFormedX() * 100.0, xTFormedY() * 100.0, xTFormedZ() * 100.0)
xEntityColor(sphere%, 120, 0, 0)
ENDFUNCTION
FUNCTION drawView:
// Background
xClsColor( ABS(SIN(GETTIMERALL()/100))*255, ABS(SIN(GETTIMERALL()/300))*255, ABS(SIN(GETTIMERALL()/600))*255 )
xCls()
// camera controll
LOCAL radii% = 24;
LOCAL fcx% = 70 + 190
LOCAL fcy% = 28 + 190
LOCAL bcx% = 70 + 190
LOCAL bcy% = 98 + 190
LOCAL lcx% = 35 + 190
LOCAL lcy% = 62 + 190
LOCAL rcx% = 104 + 190
LOCAL rcy% = 62 + 190
LOCAL tlcx% = 182 + 190
LOCAL tlcy% = 62 + 190
LOCAL trcx% = 252 + 190
LOCAL trcy% = 62 + 190
LOCAL tucx% = 218 + 190
LOCAL tucy% = 28 + 190
LOCAL tdcx% = 218 + 190
LOCAL tdcy% = 98 + 190
FOR i = 0 TO xCountTouches()
IF (xTouchPhase(i) > 0)
// forward
IF (InButton(xTouchX(i), xTouchY(i), fcx, fcy, radii)) THEN xMoveEntity(mainCamera%, 0.0, 0.0, -1.0, FALSE)
// backward
IF (InButton(xTouchX(i), xTouchY(i), bcx, bcy, radii)) THEN xMoveEntity(mainCamera%, 0.0, 0.0, 1.0, FALSE)
// left
IF (InButton(xTouchX(i), xTouchY(i), lcx, lcy, radii)) THEN xMoveEntity(mainCamera%, -1.0, 0.0, 0.0, FALSE)
// right
IF (InButton(xTouchX(i), xTouchY(i), rcx, rcy, radii)) THEN xMoveEntity(mainCamera%, 1.0, 0.0, 0.0, FALSE)
// turn left
IF (InButton(xTouchX(i), xTouchY(i), tlcx, tlcy, radii)) THEN xTurnEntity(mainCamera%, 0.0, -1.0, 0.0, TRUE)
// turn right
IF (InButton(xTouchX(i), xTouchY(i), trcx, trcy, radii)) THEN xTurnEntity(mainCamera%, 0.0, 1.0, 0.0, TRUE)
// turn up
IF (InButton(xTouchX(i), xTouchY(i), tucx, tucy, radii)) THEN xTurnEntity(mainCamera%, 1.0, 0.0, 0.0, TRUE)
// turn down
IF (InButton(xTouchX(i), xTouchY(i), tdcx, tdcy, radii)) THEN xTurnEntity(mainCamera%, -1.0, 0.0, 0.0, TRUE)
// fire button
IF ((InButton(xTouchX(i), xTouchY(i), 29, 294, 24)) AND (xTouchPhase(i) = TOUCH_BEGAN%)) THEN ShootSphere()
ENDIF
NEXT
ENDFUNCTION
[attachment deleted by admin]