Help iPhone & 3D

Previous topic - Next topic

Kyo

I test this simple 3D code:


Code (glbasic) Select

// Animation Demo
// Start: Friday, March 22, 2002
SYSTEMPOINTER TRUE
SETSCREEN 480,320,TRUE
SMOOTHSHADING TRUE

TYPE tMouse
x%
y%
active%
ENDTYPE

// Array to hold mice

GLOBAL mouse[] AS tMouse
DIM mouse[5]


X_LOADOBJ  "media/1.ddd", 1
LOADSPRITE "media/player01.jpg", 1

WHILE TRUE
updateMice()



IF mouse[0].active THEN phi=phi+GETTIMER()/100
// IF KEY(208) THEN MOVE = MOVE - 10
X_MAKE3D 1, 1000, 45
X_CAMERA 0, 0, -250 + MOVE, 0, 0, 0
X_SPOT_LT 0, RGB(255,255,255), 0,50,100,0,10,100,180

//phi=phi+GETTIMER()/100
permil=permil+GETTIMER()/20000; IF permil>=1 THEN permil=0

X_ROTATION 180, 1,0,0
X_ROTATION phi, 0,-1,0

X_SETTEXTURE 1,-1
X_DRAWANIM 1, 0, 128, permil, TRUE

GOSUB ShowFPS
PRINT "MOVE" + MOVE,0,20
SHOWSCREEN
WEND


// ------------------------------------------------------------- //
// -=#  SHOWFPS  #=-
// ------------------------------------------------------------- //
SUB ShowFPS:
X_MAKE2D
dtime=GETTIMER()
fps = ((1000/dtime)+fps)/2
delay=delay+dtime
IF delay>1000 // 1/2 sec
delay=0
fps_draw=fps
ENDIF
PRINT "FPS: "+fps_draw+"px:" + ply_x + " py:" + ply_y + " d:" + ply_dir, 0 ,0
ENDSUB // SHOWFPS



FUNCTION updateMice:
FOR imouse% = 0 TO GETMOUSECOUNT()-1
SETACTIVEMOUSE imouse%
MOUSESTATE mx%, my%, b1%, b2%
mouse[imouse].x=mx
mouse[imouse].y=my
mouse[imouse].active=b1
NEXT
ENDFUNCTION






I export the 3D model from 3D studio max to 3ds ... and i convert the 3ds (whit tool) in .ddd model

In Windows mode the code work fine, but in iphone runtime the model not show in screen ...

Detail model:
3d model polys -> 700
texture format -> jpg - 128x128

Help!

trucidare

Could be a DDD issue because ARM architecture. Wait for Kitty, he will check it.
MacBook Pro 2,2 GHz Core 2 Duo, 4 GB RAM, 160 GB HDD, 8600M GT
Core i3 - 3,07 GHz, 8 GB Ram, 2.5 TB HDD, Geforce GTX 260+ OC

Kyo

#2
I test sample cube ... (whit texture .png  and whitout texture ) but the result is the black screen ....

bigsofty

Make sure that your media paths/filenames have the same case on the iPhone as in your code. The windows version would work fine as it is not case sensitive, the iPhone would not.
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

matchy

Check if DOESFILEEXIST also!  Also you may discover 3DS files exported from 3D Studio Max give errors on the iPhone, but not when exported as OBJ for DDD conversion. ;)

Kyo

I export 3ds  and convert in DDD .... Export in Obj Format????

How many polys limit ????

Texture size????

matchy

Yes. Select the object and "Export selected...".
Any more than 24bit 512x512 png is really not needed for the iPhone.
Test experiment with low to high poly count model versus frame rate.

What is your 3D model of and have you got it running on the iPhone?

Kyo

I create a simple plane in 3ds max ... I use diffuse Map (from Material Editor of 3Dsmax) and I texture whit 64x64 png 16 bit image.

I export the plane in 3ds format and i convert it in ddd format (I check 1 frame)

The path in xcode project (for the model "Media\plane.ddd" - for the texture "Media\texture01.png") is the same in my code (Case sensitive).

But when i test in my iphone the Application, it start and after 3 sec. the application exit...


Kyo

#8
I surrender .. not work ...

any question.

I use this code for polyvector

Code (glbasic) Select
FUNCTION box:x%,y%,width%,height%,c1%,c2%,c3%,c4%
STARTPOLY 500
POLYVECTOR width%,y%,0,0,c1%
POLYVECTOR x%,y%,0,0,c2%
POLYVECTOR x%,height%,0,0,c3%
POLYVECTOR width%,height%,0,0,c4%
ENDPOLY
ENDFUNCTION


how to implement a texture for each polyvector?


------------------------------------

Resolved  ..... :good:

Schranz0r

STARTPOLY picture_id

Upper left: 0,0
Lower left: 0,1
Lower right: 1,1
upper right: 1,0
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

matchy

Export it as .OBJ (with texture coords) from 3ds Max and it won't crash on the iPhone.

Kyo

#11
Quote from: matchy on 2010-Feb-15
Export it as .OBJ (with texture coords) from 3ds Max and it won't crash on the iPhone.

thanks I'll try tomorrow  :good:

another question

I did a test using polyvector.

I use a TYPE to create multiple sprites on the screen.

I use one sprite 115x63 png 24 bit (whit trasparency) but the result has been slow.

- with 10 Polyvector sprite -> 28 frames
- between 10 and 20 Polyvector sprite -> 23 frames
- over 20 Polyvector sprite -> 18 frames


Whit  multiple parrallax (3 Polyvector) whit scroll texture  ->30 frame
Whit  multiple parrallax (3 Polyvector) whit scroll texture  and 1 Polyvector sprite ->24 frame
Whit  multiple parrallax (3 Polyvector) whit scroll texture  and 5 Polyvector sprite ->20 frame
Whit  multiple parrallax (3 Polyvector) whit scroll texture  and 10 Polyvector sprite ->17 frame

The polys parallax dimension: Width 480 - Height 320 (and also the texture)

I use this code to handle the parallax:
Code (glbasic) Select
TYPE tsfondo
x%
y%
r
g
b
active%

ENDTYPE
GLOBAL sfondo[] AS tsfondo
DIM sfondo[3]



I use this code to handle the polyvector sprite:
Code (glbasic) Select
TYPE tpolys
x%
y%
r
g
b
active%
ruota
pivot
ENDTYPE
GLOBAL polys[] AS tpolys
DIM polys[101]


Update the parallax
Code (glbasic) Select
PukeSprite(200,200, 0, 0, 0,240, 160, 0,0,1,255,255,255,0,0)
PukeSprite(201,201, 0, 0, 0,240, 160, 0,0,1,255,255,255,scrolltext,0)
PukeSprite(202,202, 0, 0, 0,240, 160, 0,0,1,255,255,255,scrolltext1,0)


Update Polyvector sprite:
Code (glbasic) Select
FOR i=1 TO max_sprite
polys[i].ruota = polys[i].ruota + 1
IF polys[i].ruota >= 360 THEN polys[i].ruota = 0

PukeSprite(0,0, 0, 0, polys[i].ruota, polys[i].x, polys[i].y,0,polys[i].pivot,1,polys[i].r,polys[i].g,polys[i].b,0,0)
NEXT


The function for update parallax and polyvector sprite:

Code (glbasic) Select

//img1 - number sprite or parallax
//img2 - disable
//rotx - rotate the sprite X
//roty - rotate the sprite y
//rozx - rotate the sprite z
//x - move in x position on the screen
//y - move in y position on the screen
//piv_x - move the pivot in x position on the polyvector to change rotation
//piv_y - move the pivot in y position on the polyvector to change rotation
// scalex - scale the polivector size (zoom effect)
//r - red color
//g - green color
//b- blue color
// scrolltx - scroll the texture in xpos
// scrollty - scroll the texture in ypos

FUNCTION PukeSprite: img1, img2, rotX, rotY, rotZ, x,y, piv_x,piv_y,scalex,r,g,b,scrolltx,scrollty
LOCAL w, h, phi, swap, tx, ty
LOCAL s, c, cl, px, py
GETSPRITESIZE img1, w,h
tx=w
ty=h

phi = MOD(ABS(rotY), 360)
IF phi < 90 OR phi>270
swap = img1
img1=img2
img2=swap
ENDIF
w = w * COS(phi)

phi = MOD(ABS(rotX), 360)
IF phi < 90 OR phi>270
swap = img1
img1=img2
img2=swap
ENDIF
h = h * COS(phi)

s=SIN(rotZ)
c=COS(rotZ)
w=(w/2)  *scalex
h=(h/2) *scalex

cl=RGB(255,255,255)

STARTPOLY img1
px=-w-piv_y; py=-h-piv_x; POLYVECTOR x+px*c+py*s, y-px*s+py*c,  0+scrolltx, 0+scrollty,RGB(r,g,b)
px=-w-piv_y; py= h-piv_x; POLYVECTOR x+px*c+py*s, y-px*s+py*c,  0+scrolltx,ty+scrollty,RGB(r,g,b)
px= w-piv_y; py= h-piv_x; POLYVECTOR x+px*c+py*s, y-px*s+py*c, tx+scrolltx,ty+scrollty,RGB(r,g,b)
px= w-piv_y; py=-h-piv_x; POLYVECTOR x+px*c+py*s, y-px*s+py*c, tx+scrolltx, 0+scrollty,RGB(r,g,b)
// and back for back face culling
//px= w-piv_y; py= h-piv_x; POLYVECTOR x+px*c+py*s, y-px*s+py*c, tx,ty,RGB(r,g,b)
//px=-w-piv_y; py= h-piv_x; POLYVECTOR x+px*c+py*s, y-px*s+py*c,  0,ty,RGB(r,g,b)
//px=-w-piv_y; py=-h-piv_x; POLYVECTOR x+px*c+py*s, y-px*s+py*c,  0, 0,RGB(r,g,b)
ENDPOLY
ENDFUNCTION


can speed up the code????

It's possible to create shoot'm'up with glbasic for iPhone?

Kitty Hello

First, the fill rate of the iPhone is not very decent.
If you try to fill the screen twice with pixels (simple drawrect) you will start to get to the end of the possible.

Second, the number of glDrawArrays is limted. If you call many STARTPOLY, it will be slower than trying to get one big batch of POLYVECTOR. See the new triangel strips and the POLY_NEW_STRIP command (or so...)

Thirs, you use SIN/COS a lot in your code. Try to store these values once in an "update sprite" function. Also, don't call RGB function all the time. Store the result in an integer variable before using it.
HTH.

Kyo


another question

I use 32x32 image size

if i use :
GETSPRITESIZE img1, w,h

the POLYVECTOR  work fine

if i use:
w= 32
h=32

the POLYVECTOR not draw..

Kitty Hello

Paste a sample code?