LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

Engine Help

Root / Programming Questions / [.]

GhomaghityCreated:
(Sorry for the early post! I'm too used to using tab!) Key: ABBXV33V So, I am currently working on a 3d engine that is (supposed to be) lightweight and easy to add new models to. There are some problems, mainly an odd rendering bug that I have been trying, and failing, to fix. I was wondering if anyone could help me with this, as I feel I can't do anything to fix this. The main problem is reverse(?) rendering. For some reason, looking in certain directions causes all objects to render behind you in reverse. I don't really know how to fix this, as I have tried but I hope I'm just missing something simple. Another problem is random Out of range errors. I have no way to fix this since I can rarely recreate it, so if you happen to stumble upon it then please tell me where you were when it happened and where you were looking. Here's the code below. I can't post this right now since my 3ds is having trouble connecting to my WIFI, so please bear with me! Before doing this, please note that this will not work on the original 3ds. If it doesn't work, tell me what line the error is and i'll fix it. This was harder to type than I thought it would be.
 
'Initializing everything
ACLS
OPTION STRICT
BGMSTOP -1
SYSBEEP=TRUE
XSCREEN 2,400,1
IF HARDWARE==1 THEN XON EXPAD
SAVE"PRG1:MODEL_DATA"
LOAD"PRG1:MODEL_DATA",FALSE
'Loading block info (don't mind how sloppy it is, I have yet to clean it up)
VAR INIT:VAR I:VAR II:VAR III:VAR HOLD
USE 1
RESTORE "1:@GENERAL"
READ INIT
FOR I=0 TO INIT-1
  RESTORE "1:BLOCK_"+STR$(INIT-1)
  READ HOLD
  DIM BLOCKPOINTS[INIT,HOLD,3]
  READ HOLD
  DIM BFS[INIT,HOLD,3]
  READ HOLD
  DIM WIREFRAMES[INIT,HOLD,3]
NEXT
DIM FACECOLOR[6,3]
FOR II=0 TO 7
  FOR I=0 TO 2
    READ BLOCKPOINT[INIT-1,II,I]
  NEXT
NEXT
FOR II=0 TO 5
  FOR I=0 TO 3
    READ BFS[INIT-1,II,I]
  NEXT
NEXT
FOR II=0 TO 11
  FOR I=0 TO 1
    READ WIREFRAMES[INIT-1,II,I]
  NEXT
NEXT
FOR II=0 TO 5
  FOR I=0 TO 2
    READ FACECOLOR[II,I]
  NEXT
NEXT
VAR FOV=150,FPS,FPST
VAR STX,STY,STEX,STEY
VAR X,Y,Z
VAR A,B,SI,CO
DIM POS[2,3]
DIM CP[8,2]
'Main rendering code incoming
DEF ROTATE2D POS1,POS2,RADI OUT OPOS1,OPOS2
  SI=SIN(RADI):CO=COS(RADI)
  A=POS1:B=POS2
  OPOS1=A*CO-B*SI:OPOS2=B*CO+A*SI
END
'This is it below
DEF RENDERBLOCK TYPE,XI,YI,ZI
  FOR II=0 TO 7
    X=BLOCKPOINT[0,I,0]+XI*2-POS[0,0]
    Y=BLOCKPOINT[0,I,0]+-YI*2+POS[0,1]
    Z=BLOCKPOINT[0,I,0]+ZI*2-POS[0,2]
  ROTATE2D X,Z,POS[1,1] OUT X,Z
  ROTATE2D Y,Z,POS[1,0] OUT Y,Z
    IF Z!=0 THEN
      CP[I,0]=X*(FOV/Z)+200
      CP[I,1]=-Y*(FOV/Z)+120
    ENDIF
  NEXT
  FOR II=0 TO 2
    GTRI CP[BFS[TYPE,II,0]-1,0],CP[BFS[TYPE,II,0]-1,1],CP[BFS[TYPE,II,1]-1,0],CP[BFS[TYPE,II,1]-1,1],CP[BFS[TYPE,II,0]-1,2],CP[BFS[TYPE,II,2]-1,1],RGB(FACECOLOR[II,0],FACECOLOR[II,1],FACECOLOR[II,2])
    GTRI CP[BFS[TYPE,II,0]-1,0],CP[BFS[TYPE,II,0]-1,1],CP[BFS[TYPE,II,2]-1,0],CP[BFS[TYPE,II,2]-1,1],CP[BFS[TYPE,II,0]-1,3],CP[BFS[TYPE,II,3]-1,1],RGB(FACECOLOR[II,0],FACECOLOR[II,1],FACECOLOR[II,2])
  NEXT
END
VAR SEN=0.06,SPEED=0.1,XP,YP
@LOOP
GCLS
CLS
FPS=ROUND(1000/(MILLISEC-FPST))
FPST=MILLISEC
IF BUTTON(0) AND 64 THEN INC POS[0,1],SPEED
IF BUTTON(0) AND 32 THEN INC POS[0,1],-SPEED
STICKEX OUT STEX,STEY
  INC POS[1,0],STEY*SEN
  INC POS[1,1],STEX*SEN
  IF POS[1,0]>1.5 THEN POS[1,0]=1.5
  IF POS[1,0]<-1.5 THEN POS[1,0]=1.5
STICK OUT STX,STY
XP=SPEED*SIN(POS[1,1]):YP=SPEED*-COS(POS[1,1])
  INC POS[0,0],(STY*-XP)-STX*-YP
  INC POS[0,2],(STX*YP)-STX*-XP
  'Put a block wherever you want, I haven't added terrain generation yet due to said issues above
  RENDERBLOCK 0,0,0,0
  RENDERBLOCK 0,1,0,0
  RENDERBLOCK 0,0,0,1
  RENDERBLOCK 0,0,1,0
  'Debug data
?FPS:?POS[0,0]:?POS[0,1]:?POS[0,2]:?POS[1,0]:?POS[1,1]
WAIT 'I use wait because VSYNC causes flickering
GOTO@LOOP
And here is MODEL_DATA. Make sure you enter this in PRG1, then run the progam and click save.
@GENERAL
DATA 1

@BLOCK_0
DATA 8,6,12
'Points
DATA -1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,1,-1,1,-1,-1,1
'Faces
DATA 1,2,3,4,2,6,7,3,6,5,8,7,5,1,4,8,1,2,6,5,7,8,4,3
'Wireframe
DATA 1,2,2,3,3,4,4,1,2,6,6,7,7,3,6,5,5,8,8,7,1,5,4,8
'Color data
DATA 255,255,255,0,240,31,255,31,0,255,224,0,0,63,240,0,191,255

Ok give me a bit to copy down this code.

Oops! I forgot the end of the initial project! Without it, it does 1 frame then stops :p But I triple checked the code and everything seems fine now.

Oops! I forgot the end of the initial project! Without it, it does 1 frame then stops :p But I triple checked the code and everything seems fine now.
i give up too much code to copy my hand hurts

Give a key, perhaps?

Give a key, perhaps?
Like I said, my 3ds is having trouble connecting to our WIFI. I'll try my best to connect up if you don't want to copy the code. Just hang tight for about an hour ;)

Alright cool

Alright, I think I uploaded it. Key is ABBXV33V. And when asked to save, press no for the first time.