Entry
BBCBASIC:Windows: Graphics: Microsoft:DirectX: Create: Figure: Triangle: 2: How to view 2 triangles?
Feb 4th, 2006 13:45
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 04 February 2021 - 08:13 pm -------------------
BBCBASIC:Windows: Graphics: Microsoft:DirectX: Create: Figure:
Triangle: 2: How to view 2 triangles?
---
You create 2 files,
one containing the points of your triangles,
and one showing this content.
===
Steps: Overview:
1. -Create a file with the vertices of your figure
1. -This can by design only be triangles
1. To get the coordinates,
for example, draw your 2 triangles in 2D
and give it (to keep it simple) a z-coordinate
of 0
1. -In 2D
x (0,1)
/ \
/ \
/ \
/ \
(-1,0) x---------x (1,0)
\ /
\ /
\ /
\ /
x
(0,-1)
2. -To get a possible 3D representation,
just add a zero ',0' for z
x (0,1,0)
/ \
/ \
/ \
/ \
(-1,0,0) x---------x (1,0,0)
\ /
\ /
\ /
\ /
x
(0,-1,0)
1. -This becomes thus here the 6 points
(you should see each triangle as
independent of the other. Thus
you have to give exactly 3 coordinates
for each triangle)
----------
X Y Z
----------
1 0 0 triangle 1
0 1 0
-1 0 0
----------
1 0 0 triangle 2
-1 0 0
0 -1 0
----------
1. -So you must describe your figures' vertices
using a concatenation of triangles only
1. -You call this 'triangulation'
2. -For first to last triangle of your figure
1. -For each of the 3 points of that triangle
1. -Write the x-coordinate of that triangle to a file
2. -Write the y-coordinate of that triangle to a file
3. -Write the z-coordinate of that triangle to a file
4. -Write the reflection color at that point to a file
2. -Endfor
3. -Endfor
2. -Use the render file
1. -Make sure that both files (your file containing the points of
your figure and the render file) are in the same directory, or
other wise adapt the path to your triangle source file
3. -Run the render file
===
Steps: Worked out:
1. -Create a file with the vertices of your figure
--- cut here: begin --------------------------------------------------
REM first create the file containing the N vertices of your wireframe
INSTALL @lib$+"D3DLIB"
F% = OPENOUT "TRIANGLE2.B3D"
PROC4( 2 * 3 ) : REM 6 vertices in the format (x, y, z), for 2
triangles
PROC4( &100042 ) : REM vertex size &10 and format &42
REM The 2 . 3 or 6 points of 2 triangles, together with the color
REM ----------
REM X Y Z
REM ----------
REM 1 0 0 triangle 1
REM 0 1 0
REM -1 0 0
REM ----------
REM 1 0 0 triangle 2
REM -1 0 0
REM 0 -1 0
REM ----------
REM
REM X Y
Z COLOR
REM triangle 1
PROC4( FN_f4( 1.0 ) ) : PROC4( FN_f4( 0.0 ) ) : PROC4( FN_f4(
0.0 ) ) : PROC4( &FF0000FF )
PROC4( FN_f4( 0.0 ) ) : PROC4( FN_f4( 1.0 ) ) : PROC4( FN_f4(
0.0 ) ) : PROC4( &FF00FF00 )
PROC4( FN_f4( -1.0 ) ) : PROC4( FN_f4( 0.0 ) ) : PROC4( FN_f4(
0.0 ) ) : PROC4( &FFFF0000 )
REM triangle 2
PROC4( FN_f4( 1.0 ) ) : PROC4( FN_f4( 0.0 ) ) : PROC4( FN_f4(
0.0 ) ) : PROC4( &FFFF0000 )
PROC4( FN_f4( -1.0 ) ) : PROC4( FN_f4( 0.0 ) ) : PROC4( FN_f4(
0.0 ) ) : PROC4( &FFFF0000 )
PROC4( FN_f4( 0.0 ) ) : PROC4( FN_f4( -1.0 ) ) : PROC4( FN_f4(
0.0 ) ) : PROC4( &FFFF0000 )
CLOSE #F%
END
:
DEF PROC4( A% )
BPUT#F%,A%
BPUT#F%,A%>>8
BPUT#F%,A%>>16
BPUT#F%,A%>>24
ENDPROC
--- cut here: end ----------------------------------------------------
2. -Save this file as
triangle2_create.bbc
3. -Run this file
4. -Create the render file
--- cut here: begin --------------------------------------------------
REM. Program to demonstrate use of Direct3D in BBC BASIC for Windows
MODE 8
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)
IF HIMEM < PAGE + 9999 THEN HIMEM = PAGE + 4200
INSTALL @lib$+"D3DLIB"
ON CLOSE PROCcleanup : QUIT
ON ERROR PROCcleanup : PRINT REPORT$ : END
d% = FN_initd3d( @hwnd%, 1, 0 )
IF d% = 0 THEN ERROR 100, "Can't initialise Direct3D"
b%(0) = FN_load3d( d%, @dir$ + "TRIANGLE2.B3D", n%( 0 ), f%( 0 ), s%(
0 ) )
IF b%( 0 ) = 0 ERROR 100, "Can't load TRIANGLE2.B3D"
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 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
:
--- cut here: end ----------------------------------------------------
5. -Save this file as
triangle2_run.bbc
6. -Run this render file
7. -That will show 2 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:
---
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
----------------------------------------------------------------------