Entry
BBCBASIC: Windows: Graphics: Microsoft: DirectX: Triangle: Translate: 3D: How to view N triangles?
Feb 5th, 2006 10:14
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 05 February 2006 - 00:06 am -------------------
BBCBASIC: Windows: Graphics: Microsoft: DirectX: Triangle: Translate:
3D: How to view N triangles?
---
Divide your figure in triangles.
Put the 3 points of each triangle,
together with a possible color,
in DATA
To quickly create a 3D effect, draw your figure
in 2D, and translate this figure
(that comes down to adding e.g. z=0
then repeating that dataset and adding z=1
===
Steps: Overview:
1. -Create a file containing the vertices of your figure in DATA
1. -This can by design only be triangles
2. -Run this file
===
Steps: Worked out:
1. -Create the following file
1. Put the information about triangles in your figure (one after
the other) in the DATA below
--- cut here: begin --------------------------------------------------
MODE 8
:
INSTALL @lib$ + "D3DLIB"
:
triangleTotalI% = 2 : REM total amount of triangles in your figure
:
filename$ = "TRIANGLEN.B3D" : REM the file containing the data for
this triangles (in binary format)
:
dataB% = TRUE : REM set to true if you want to generate the binary
output file containing the data (should only be done once the first
time)
:
dimB% = TRUE : REM set to true if you want to dimension arrays
(should only be done once the first time)
:
IF dataB% THEN PROCGraphicsViewTriangleDataN( triangleTotalI%,
filename$ )
:
IF dimB% THEN PROCGraphicsViewTriangleDimN( triangleTotalI% )
:
IF HIMEM < PAGE + 9999 THEN HIMEM = PAGE + 4200
:
ON CLOSE PROCcleanup : QUIT
:
ON ERROR PROCcleanup : PRINT REPORT$ : END
:
d% = FN_initd3d( @hwnd%, 1, 0 )
IF d% = 0 THEN ERROR 100, "Can not initialise Direct3D"
b%(0) = FN_load3d( d%, @dir$ + filename$, n%( 0 ), f%( 0 ), s%( 0 ) )
IF b%( 0 ) = 0 ERROR 100, "Can not load" + filename$
e() = 0, 0, -6
a() = 0, 0, 0
REPEAT
p() = TIME / 100
r() = TIME / 40
X() = SIN( TIME / 200 )
PROC_render( d%, &FF7F7F7F, 0, l%(), 2, m%(), t%(), b%(), n%(), f%
(), s%(), y(), p(), r(), X(), Y(), Z(), e(), a(), PI/4, 5/4, 1, 1000 )
UNTIL INKEY( 1 ) = 0
END
:
:
:
DEF PROCGraphicsViewTriangleDataN( triangleTotalI%, filename$ )
LOCAL F%
:
LOCAL triangleI%
LOCAL triangleMinI%
LOCAL triangleMaxI%
:
LOCAL pointI%
LOCAL pointMinI%
LOCAL pointMaxI%
:
LOCAL xR
LOCAL yR
LOCAL zR
LOCAL colorR
:
triangleMinI% = 1
triangleMaxI% = triangleTotalI%
pointMinI% = 1
pointMaxI% = 3
F% = OPENOUT filename$
PROC4( triangleTotalI% * 3 ) : REM for each triangle exactly 3
points, thus totally N . 3 points
PROC4( &100042 ) : REM vertex size &10 and format &42 (possibly
change this)
FOR triangleI% = triangleMinI% TO triangleMaxI%
FOR pointI% = pointMinI% TO pointMaxI%
READ xR, yR, zR, colorR
PROC4( FN_f4( xR ) ) : PROC4( FN_f4( yR ) ) : PROC4( FN_f4(
zR ) ) : PROC4( colorR )
NEXT pointI%
NEXT triangleI%
CLOSE #F%
ENDPROC
:
DEF PROC4( A% )
BPUT# F%,A%
BPUT# F%, A% >> 8
BPUT# F%, A% >> 16
BPUT# F%, A% >> 24
ENDPROC
:
DEF PROCcleanup
t%(1) += 0 : IF t%(1) PROC_release(t%(1))
b%(0) += 0 : IF b%(0) PROC_release(b%(0))
b%(1) += 0 : IF b%(1) PROC_release(b%(1))
d% += 0 : IF d% PROC_release(d%)
ENDPROC
:
DEF PROCGraphicsViewTriangleDimN( triangleTotalI% )
DIM l%(0)
DIM b%(1)
DIM n%(1)
DIM f%(1)
DIM s%(1)
DIM m%(1)
DIM t%(1)
DIM y(1)
DIM p(1)
DIM r(1)
DIM X(1)
DIM Y(1)
DIM Z(1)
DIM e(2)
DIM a(2)
ENDPROC
:
REM put here your N triangles
:
REM The format is:
REM DATA <x of point 1>, <y of point 1>, <z of point 1>, <color of
point 1>
REM DATA <x of point 2>, <y of point 2>, <z of point 2>, <color of
point 2>
REM DATA <x of point 3>, <y of point 3>, <z of point 3>, <color of
point 3>
:
REM triangle 1 (totally 3 points per triangle)
DATA 1.0, 0.0, 0.0, &FF0000FF
DATA 0.0, 1.0, 0.0, &FF00FF00
DATA -1.0, 0.0, 0.0, &FFFF0000
:
REM triangle 1 translated over distance 1 (totally 3 points per
triangle)
DATA 1.0, 0.0, 1.0, &FF0000FF
DATA 0.0, 1.0, 1.0, &FF00FF00
DATA -1.0, 0.0, 1.0, &FFFF0000
:
--- cut here: end ----------------------------------------------------
2. -Save this file as
triangleN.bbc
3. -Run this file
7. -That will show N rotating 3D triangles
===
File: see also:
[file: 'pyramid.bbc' in the 'BBC BASIC for Windows' directory]
===
Help: see also:
[help: program: BBCBASIC for Windows v5.00a or higher: search
for 'DirectX']
===
Internet: see also:
---
Computer: Graphics: Object: 3D: Operation: Create: Simple: How to
quickly create 3D data?
http://www.faqts.com/knowledge_base/view.phtml/aid/39497/fid/818
---
BBCBASIC: Windows: Graphics: Microsoft: DirectX: Link: Overview: Can
you give an overview of links?
http://www.faqts.com/knowledge_base/view.phtml/aid/39482/fid/768
----------------------------------------------------------------------