DSiWare Forum

Topic: Rotating points around the origin in Petit Computer

Showing 1 to 2 of 2

AuthorMessage
Avatar

furrysalamander

1. Posted:

I am currently working on a 3D model viewer for petit computer. As of right now, I have very basic wireframe support working, and am now working on the code for rotation. However, I am having quite a bit of difficulty rotating the model, and was wondering if I could get some help with the required code. Here's what I need the code to do.

There will be three subroutines, and each one will be nearly identical, but will be for rotating the model around different axes.

When called, the code will go through all points in the array POINTA, and rotate them by DEGREES about an axis. Following this, it will save that data back into the array, and return.

The coordinates for my program are stored in DATA fields initially, to allow me to import .ply files from the computer, in the following format:
DATA X,Y,Z,X2,Y2,Z2,X3,Y3,Z3
Each row of data is one face on the 3D model. This information is then pulled and saved into the already mentioned array, POINTA, where it will need to be pulled out and rotated.

furrysalamander

AuthorMessage
Avatar

furrysalamander

2. Posted:

Untitled

Code, just in case anyone wants it.


'CLEARS EVERYTHING
CLS
GCLS
CLEAR

'DEFINES SOME CONSTANTS
POLYGONSIZE = 9
DEGREES = 10
RESTORE @DATALABEL

'READS 3D MODEL INFO
@DATPARSE
READ POINTP
'CHECKS FOR END OF DATA
IF POINTP != 999 THEN POINTC = POINTC+1 : GOTO @DATPARSE ELSE RESTORE @DATALABEL : READ POINTP
'CREATES ARRAY FOR DATA
DIM POINTA(POLYGONSIZE+1,POINTC/POLYGONSIZE+1)

RESTORE @DATALABEL

'LOADS DATA INTO ARRAY
FOR I = 0 TO POINTC/(POLYGONSIZE+1)
FOR I2 = 0 TO POLYGONSIZE-1
READ POINTP
POINTA(I2,I)=POINTP
NEXT
NEXT

'MAIN LOOP
'RENDERS WIREFRAME
@DISPLAY
FOR I = 0 TO POINTC/(POLYGONSIZE+1) STEP 1
X = POINTA(0,I)
Y = POINTA(1,I)
Z = POINTA(2,I)
X2 = POINTA(3,I)
Y2 = POINTA(4,I)
Z2 = POINTA(5,I)
X3 = POINTA(6,I)
Y3 = POINTA(7,I)
Z3 = POINTA(8,I)
GLINE 127.5*X*0.5/Z+127.5,95.5*Y*0.5/Z+95.5,127.5*X2*0.5/Z2+127.5,95.5*Y2*0.5/Z2+95.5,9
GLINE 127.5*X2*0.5/Z2+127.5,95.5*Y2*0.5/Z2+95.5,127.5*X3*0.5/Z3+127.5,95.5*Y3*0.5/Z3+95.5,9
GLINE 127.5*X3*0.5/Z3+127.5,95.5*Y3*0.5/Z3+95.5,127.5*X*0.5/Z+127.5,95.5*Y*0.5/Z+95.5,9

NEXT
'GOSUB @ROTATEZ
GOTO @DISPLAY

'EMPTY ROTATE SUBROUTINES
@ROTATEZ
RETURN

@ROTATEY
RETURN

@ROTATEX
RETURN

'FOR DEBUGGING
@PRINTDATA
FOR I = 0 TO POINTC/(POLYGONSIZE+1) STEP 1
VAL$ = ""
FOR I2 = 0 TO POLYGONSIZE-1 STEP 1
VAL$ = VAL$ + " " + STR$(POINTA(I2,I))
WAIT 1
NEXT
PRINT VAL$
NEXT

'3D MODEL
@DATALABEL
DATA 0,1,1,-1,-1,1,1,-1,1
DATA -1,-1,1,0,1,1,0,0,2
DATA 0,1,1,1,-1,1,0,0,2
DATA 1,-1,1,-1,-1,1,0,0,2

DATA 999

furrysalamander