Author : Grant Smith
Page : << Previous 19 Next >>
by it's
equivalent, SHL DX,8
[Note: If you are running on a 286, this last set of optimizations
actually makes the routine slower! On a 286, an "SHL" takes 5 ticks
plus the number you are moving by. For example: an "SHL AX,6" would
take 11 clock ticks (5 ticks for SHL and 6 clock ticks for the "6"
part of the expression.]
Procedure Putpixel (X,Y : Integer; Col : Byte; where:word); assembler;
BEGIN -clock ticks-
asm 8088 286 386 486
mov ax,[where] 8 5 4 1
mov es,ax 2 2 2 3
mov bx,[X] 8 5 4 1
mov dx,[Y] 8 5 4 1
mov di,bx 2 2 2 3
mov bx, dx 2 2 2 1
shl dx, 8 8 13 3 2
shl bx, 6 8 11 3 2
add dx, bx 3 2 2 1
add di, dx 3 2 2 1
mov al, [Col] 8 5 4 1
stosb 11 3 4 5
end; ----------------
71 57 36 22 Total ticks
As you can see, we have brought the clock ticks down from 153-52 (8088-486)
ticks to 71-22 (8088-486) ticks ... quite an improvement. (The current
ASPHYXIA putpixel takes 48 clock ticks) . As you can see, by going through
your routines a few times, you can spot and remove unnecessary instructions,
thereby greatly increasing the speed of your program.
Defining a 3-D object
Drawing an object in 3-D is not that easy. Sitting down and plotting a
list of X,Y and Z points can be a time consuming business. So, let us
first look at the three axes you are drawing them on :
Y Z
/|\ /
| /
X<-----|----->
|
\|/
X is the horisontal axis, from left to right. Y is the vertical axis,
from top to bottom. Z is the depth, going straight into the screen.
In this trainer, we are using lines, so we define 2 X,Y and Z
coordinates, one for each end of the line. A line from far away, in the
upper left of the X and Y axes, to close up in the bottom right of the
X and Y axes, would look like this :
{ x1 y1 z1 x2 y2 z2 }
( (-10,10,-10),(10,-10,10) )
Rotating a point with matrixes
NOTE : I thought that more then one matix are matrisese (sp), but my
spellchecker insists it is matrixes, so I let it have it's way
;-)
Having a 3-D object is useless unless you can rotate it some way. For
demonstration purposes, I will begin by working in two dimensions, X and
Y.
Let us say you have a point, A,B, on a graph.
Y
| /O1 (Cos (a)*A-Sin (a)*B , Sin (a)*A+Cos (a)*B)
|/ (A,B)
X<-----|------O-->
|
|
Now, let us say we rotate this point by 45 degrees anti-clockwise. The
new A,B can be easily be calculated using sin and cos, by an adaption of
our circle algorithm, ie.
A2:=Cos (45)*A - Sin (45)*B
B2:=Sin (45)*A + Cos (45)*B
I recall that in standard 8 and 9, we went rather heavily into this in
maths. If you have troubles, fine a 8/9/10 maths book and have a look;
it will go through the proofs etc.
Anyway, we have now rotated an object in two dimensions, AROUND THE Z
AXIS. In matrix form, the equation looks like this :
[ Cos (a) -Sin (a) 0 0 ] [ x ]
[ Sin (a) Cos (a) 0 0 ] . [ y ]
[ 0 0 1 0 ] [ z ]
[ 0 0 0 1 ] [ 1 ]
I will not go to deeply into
Page : << Previous 19 Next >>