×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# texutre mapping and/ polygon filling

## texutre mapping and/ polygon filling

(OP)
Hi, I have been slowly introducing myslef into the 3d programming through qbaisc and I have been having trouble on the subject of texutre mapping and/ poly filling.  I created my own routine to do texture mapping within a quadratic, but it is extremely slow and is only for a 30 by 30 image.  Could any body show give me a useful tutorial on the subject in qbaisc.  Or help me in this forum?

### RE: texutre mapping and/ polygon filling

I've never done texture mapping on a polygon before, but I am fairly skilled with 3-d graphics.  Why not instead of using polygons, using a voxel engine.
Voxels have decent speed and can show any shape.

'$DYNAMIC DEFINT A-Z SCREEN 13 DIM vox (30,30,30) FOR x = 1 TO 60 FOR y = 1 TO 60 FOR z = 1 TO 30 IF vox (x\2,y\2,z) THEN PSET (x,y),vox(x\2,y\2,z) EXIT FOR END IF NEXT NEXT NEXT This is an extremely simple example of a voxel engine, it does not do anything like angles, or focal points or anything like that, but you get the idea. You'd have to fill in the vox() array with some number for you to see how it would work. If a man says something in the forest and no woman hears it is he still wrong? ### RE: texutre mapping and/ polygon filling voxel engines normally also shade, the further away an object gets the darker it normally is If a man says something in the forest and no woman hears it is he still wrong? ### RE: texutre mapping and/ polygon filling (OP) I tried the program out and it seems to work nicely. Thank you for the info. I will look into this voxel engine more closely, but I would still like help on the texture mapping subject. Again thank you for the information on the voxel engine. I am sure I can get it work for a transformed set of coordinates. ### RE: texutre mapping and/ polygon filling Wow, that is truly impressive. (innocent bystander) Doug ### RE: texutre mapping and/ polygon filling Hey Instinct! I didn't know anyone was doing 3D stuff in Qbasic. I won't waste your time. I would like a copy of your quadratic routine after telling the method I would use for texture mapping. It would allow any shape to be t-mapped! Send me a reply if your wit it it. this is just to let you know i'm no fool: this is actually part of a 3d engine i created from the ground up. i also have my own z buffer routine. i'm just curious about "other" methods. x=_ : y=_ xs=x*sin(a+90) xc=x*cos(a+90) ys=y*sin(a):yc=y*cos(a) x=xs+ys:y=xc+yc i don't have 3d collision detection,lighting algorithms know anyone that does or knows a good source? ### RE: texutre mapping and/ polygon filling I have good 3d collision detection and lighting algorithms. To do 3d collision detection simple use: FUNCTION collision%(x,y,z,x2,y2,z2) xydis = SQR(((x2-x)^2)+((y2-y)^2)) xyzdis = SQR((xydis^2)+((z2-z)^2)) IF xyzdis < 1 THEN collision% = TRUE END FUNTION ### RE: texutre mapping and/ polygon filling qbasicking: You had me going for a second there. I'm a pretty decent 3D programmer and for a second I was thinking "No way, you could have 3D collision with that little code!" But then I didn't know you weren't talking about POLYGON collision :) (denggit) Also, I see some nice ideas but with no idea why they work. :-\ Does anyone think they could write a tutorial on texture mapping and this voxel engine i see? I have no idea how to incorporate that into a complete engine as of yet. ~PlystirE~ ### RE: texutre mapping and/ polygon filling My mistake, the code that I posted simply returns if two 3d points have collided, not polygons, but the idea would be the same. If your collisions don't have to be totally accurate you could simply find the centre of gravity of the polygons and see if they come close to each other. I'll try to write a tutorial on voxel engines, but I am fairly busy, not texture mapping though, I have done a great deal of texturing in 3d environments, but that was a simple raycaster, not polygons. ### RE: texutre mapping and/ polygon filling I found this program on Toshi's webpage '=========================================================================== ' Subject: 3D TEXTURED POLYGON ENGINE V2.0 Date: 12-24-97 (15:25) ' Author: Sami Kyostila Code: QB, QBasic, PDS ' Origin: hiteck@freenet.hut.fi Packet: GRAPHICS.ABC '=========================================================================== 'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ' 3D Polygon Engine v2.0 (C) Sami Ky”stil„ 1997 'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ' Comments & questions can be sent to hiteck@freenet.hut.fi 'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ' ' Here's a new version of my previous 3d engine. Actually it's almost a ' complete rewrite, with tons of new features. Currently there are 4 ' drawing modes: ' ' + Z-Shaded Wireframe ' + Z-Gouraud shaded and filled ' + Z-Shaded Flat, ASM-Filled ' + Z-Gouraud shaded and texturemapped ' ' These drawing modes can be selected with the F1-F4 keys. In addition ' there are also 4 animated textures: ' ' + Fire - Looks very kewl ' + BumpMap - Nice and fast bumpmap ' + Panning textures - Looks like flowing green ooze ' + Sinus plasma - An animated plasma ' ' These can be toggled on/off with the F9-F12 keys. NOTE: After you have ' selected an animated texture, you must press that same key again to ' disable it. ' ' The object is rotated with the arrow keys and the plus/minus keys. Zoom ' in/out with the A/Z keys. The object can be panned with the J/K/L/I keys. ' 5 stops movement, and 0 resets the object to the starting position. ' You can also rotate the object with the mouse by pressing the left mouse ' button. ' ' All of the drawing modes are shaded, and the ambient lighting level can ' be varied with the F5/F6 keys. F7 toggles point number display on/off ' F9 toggles FPS display on/off (this slows the engine down a bit, you can ' also see the FPS in the exit screen) ' ' If the texture mapping seems too slow, you can adjust the texture size ' by changing the TSize-constant below. ' ' See the end of the program to find out how to make your own objects ' If you want to save you objects to a file, insert the following ' statement to the SUB TheEnd: ' ' SaveObject "filename.dat" ' ' When you press ESC, the object is saved. To load a saved object, use the ' SUB LoadObject ' 'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ' You may use any of this code freely in you own programs, as long as you ' mention my name somewhere in you program. 'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ DEFINT A-Z '$DYNAMIC
DECLARE SUB HiiriLue (vasen%, oikea%, keski%, x%, y%)
DECLARE SUB Hiiriajuri (ax%, bx%, cx%, dx%)
DECLARE FUNCTION Hiiritarkista% ()
DECLARE SUB LoadObject (File$) DECLARE SUB SaveObject (File$)
DECLARE SUB HandleKeys ()
DECLARE SUB TheEnd ()
DECLARE SUB RotatePoints ()
DECLARE SUB ColPrint (Text$) DECLARE FUNCTION ShadeName$ (Model%)
DECLARE SUB Separator (Col&, Char$) DECLARE SUB MakePalette () DECLARE SUB MakeFirePalette (MaxColors%) DECLARE SUB MakeTexture () DECLARE SUB Switch (Var%, Value1%, Value2%) DECLARE SUB MakeLight () DECLARE SUB Fillchar (segment%, offset%, value%, bytes%) DECLARE SUB Memcopy (fromseg%, fromoffset%, toseg%, tooffset%, bytes%) DECLARE SUB t3d2d (x%, y%, z%, SX%, SY%) DECLARE SUB RotatePoint (x%, y%, z%, Rx%, Ry%, Rz%, Nx%, Ny%, Nz%) DECLARE SUB DrawPoly (x%, y%, x2%, y2%, x3%, y3%, P1%, P2%, P3%, Num) DECLARE SUB DrawLine (x%, y%, x2%, y2%, Col1%, Col2%, Tx1, Ty1, Tx2, Ty2) DEFINT A-Z TYPE Filltype 'Buffer to hold polygon data x1 AS INTEGER x2 AS INTEGER Col1 AS INTEGER Col2 AS INTEGER Tx AS INTEGER Ty AS INTEGER Tx2 AS INTEGER Ty2 AS INTEGER END TYPE TYPE PointType x3 AS INTEGER 'Original X y3 AS INTEGER 'Original Y z3 AS INTEGER 'Original Z x AS INTEGER 'Screen X y AS INTEGER 'Screen Y Nx AS INTEGER 'New X Ny AS INTEGER 'New Y Nz AS INTEGER 'New Z Shade AS INTEGER 'Shade END TYPE TYPE Polygontype P1 AS INTEGER 'Point 1 P2 AS INTEGER 'Point 2 P3 AS INTEGER 'Point 3 Col AS INTEGER 'Color Culled AS INTEGER 'Culled/Not Culled AvgZ AS INTEGER END TYPE '---------------------------------------------------------------------------- ' Constants '---------------------------------------------------------------------------- CONST True = 0 CONST False = NOT True CONST PI = 22 / 7 CONST TSize = 40 CONST LSize = TSize \ 2 DIM SHARED Polygons, Points DIM SHARED Sine(360) AS INTEGER 'SIN table DIM SHARED Cosine(360) AS INTEGER 'COS table DIM SHARED Fill(199) AS Filltype 'Polygon data buffer DIM SHARED Upper AS INTEGER DIM SHARED Lower AS INTEGER DIM SHARED SrX AS INTEGER DIM SHARED SrY AS INTEGER DIM SHARED Zoom AS INTEGER DIM SHARED Buffer(319, 199) AS STRING * 1 DIM SHARED ShadingModel AS INTEGER DIM SHARED Ambient AS INTEGER DIM SHARED Mx, My DIM SHARED Fire AS INTEGER DIM SHARED Anim AS INTEGER DIM SHARED AnimType AS INTEGER DIM SHARED l(0 TO LSize, 0 TO LSize) AS INTEGER DIM SHARED MaxPoints, MaxPolygons DIM SHARED Xr AS INTEGER DIM SHARED Yr AS INTEGER DIM SHARED Zr AS INTEGER DIM SHARED Vx, Vy, Vz DIM SHARED FDisp, PDisp DIM SHARED FPS& DIM SHARED WaveSide1, WaveSide2, WaveSide3 DIM SHARED R1, R2, R3 FOR i = 0 TO 360 Sine(i) = SIN(i * PI / 180) * 1024 Cosine(i) = COS(i * PI / 180) * 1024 NEXT SrX = 320 \ 2 'Screen center SrY = 200 \ 2 Zoom = 700 'Initial values Xr = 200 Yr = 315 Zr = 100 Mx = 0 My = 0 Ambient = 10 PDisp = False FDisp = False Fire = False ShadingModel = 2 SCREEN 0: CLS WIDTH 80, 25 COLOR 15, 4 LOCATE 1, 1 PRINT STRING$(80, " ")
LOCATE 1, 1
PRINT "             3D Polygon Engine v2.0 by Sami Ky”stil„ 1997"
COLOR 3, 0
PRINT

RESTORE ObjectData
DIM SHARED Pnt(1 TO MaxPoints) AS PointType
DIM SHARED Poly(1 TO MaxPolygons) AS Polygontype
DIM SHARED Pointer(1 TO MaxPolygons)
DIM SHARED Txt(-1 TO TSize + 1, -1 TO TSize + 1) AS INTEGER
DIM SHARED ASMMemCopy$DIM SHARED ASMFillChar$

asm$= "" asm$ = asm$+ CHR$(85)
asm$= asm$ + CHR$(137) + CHR$(229)
asm$= asm$ + CHR$(30) asm$ = asm$+ CHR$(139) + CHR$(70) + CHR$(10)
asm$= asm$ + CHR$(142) + CHR$(192)
asm$= asm$ + CHR$(139) + CHR$(70) + CHR$(14) asm$ = asm$+ CHR$(142) + CHR$(216) asm$ = asm$+ CHR$(139) + CHR$(118) + CHR$(8)
asm$= asm$ + CHR$(139) + CHR$(126) + CHR$(12) asm$ = asm$+ CHR$(139) + CHR$(78) + CHR$(6)
asm$= asm$ + CHR$(243) asm$ = asm$+ CHR$(164)
asm$= asm$ + CHR$(31) asm$ = asm$+ CHR$(93)
asm$= asm$ + CHR$(203) ASMMemCopy$ = asm$asm$ = ""
asm$= asm$ + CHR$(85) asm$ = asm$+ CHR$(137) + CHR$(229) asm$ = asm$+ CHR$(139) + CHR$(78) + CHR$(6)
asm$= asm$ + CHR$(139) + CHR$(86) + CHR$(8) asm$ = asm$+ CHR$(139) + CHR$(70) + CHR$(12)
asm$= asm$ + CHR$(30) asm$ = asm$+ CHR$(142) + CHR$(216) asm$ = asm$+ CHR$(139) + CHR$(94) + CHR$(10)
asm$= asm$ + CHR$(136) + CHR$(23)
asm$= asm$ + CHR$(67) asm$ = asm$+ CHR$(226) + CHR$(251) asm$ = asm$+ CHR$(31)
asm$= asm$ + CHR$(93) asm$ = asm$+ CHR$(203)
ASMFillChar$= asm$

PRINT "Number of points:", , MaxPoints
PRINT "Number of polygons:", , MaxPolygons
PRINT "Starting position (XYZ)", , Xr; Yr; Zr
PRINT "Texture size: ", , TSize; "x"; TSize
PRINT "Initial shading model:", , " "; ShadeName$(ShadingModel) PRINT "Ambient lighting level:", , Ambient Separator 1, "Ä" COLOR 7 PRINT " þ Reading points..."; FOR i = 1 TO MaxPoints READ Pnt(i).x3 READ Pnt(i).y3 READ Pnt(i).z3 NEXT PRINT "Done" PRINT " þ Reading polygons..."; FOR i = 1 TO MaxPolygons READ Poly(i).P1 READ Poly(i).P2 READ Poly(i).P3 READ Poly(i).Col Poly(i).Col = Poly(i).Col * 64 NEXT PRINT "Done" PRINT " þ Generating texture..."; MakeTexture PRINT "Done" PRINT " þ Initializing mouse..."; RESTORE MouseData DIM SHARED hiiri$
hiiri$= SPACE$(57)
FOR i% = 1 TO 57
READ a$h$ = CHR$(VAL("&H" + a$))
MID$(hiiri$, i%, 1) = h$NEXT i% napit% = Hiiritarkista% IF (napit% = 0) THEN PRINT "Mouse not found!" MouseNotFound = 1 ELSE PRINT "Done (Press left MButton to rotate)" END IF PRINT Separator 3, "Ä" ColPrint " &FF1&7 - Wireframe &FF2&7 - Z-Gouraud &FF3&7 - Z-Flat &FF4&7 - Textured" PRINT ColPrint " &FArrows/-/+&7 - Rotate &FA/Z&7 - Zoom In/Out &FJ/K/L/I&7 - Pan &F5&7 - Stop &F0&7 - Reset" PRINT ColPrint " &FF5&7/&FF6&7 - Adjust ambient lighting level " PRINT ColPrint " &FF7&7 - Point display toggle" PRINT ColPrint " &FF8&7 - Frame rate toggle" PRINT ColPrint " &FF9&7 - Animated texture 1 - &EFire" PRINT ColPrint " &FF10&7 - Animated texture 2 - &EBumpmap" PRINT ColPrint " &FF11&7 - Animated texture 3 - &ETexture panning" PRINT ColPrint " &FF12&7 - Animated texture 4 - &EPlasma" MakeLight DO: LOOP UNTIL INKEY$ <> ""

SCREEN 13: CLS
MakePalette

COLOR 255

DIM Temp(0 TO TSize, 0 TO TSize) AS INTEGER

FOR y& = 0 TO TSize
FOR x& = 0 TO TSize
Temp(x&, y&) = Txt(x&, y&)
NEXT
NEXT

DIM Cosinus(160) AS INTEGER
DIM Rand(255) AS INTEGER

FOR c = 0 TO 160
Cosinus(c) = COS(c * 2 * PI / 80) * 16 + 16
NEXT

FOR c = 0 TO 255
Rand(c) = INT(RND * 4) + 1
NEXT

Anim = False

DO
RotatePoints

FOR i& = 1 TO MaxPolygons
Poly(i&).AvgZ = (Pnt(Poly(i&).P1).Nz + Pnt(Poly(i&).P2).Nz + Pnt(Poly(i&).P3).Nz) \ 3
Pointer(i&) = i&
Poly(i&).Culled = False
NEXT

FOR i& = 1 TO MaxPolygons
coord1 = Poly(i&).P1
coord2 = Poly(i&).P2
coord3 = Poly(i&).P3

z1& = Pnt(coord1).Nz
z2& = Pnt(coord2).Nz
z3& = Pnt(coord3).Nz

x1& = Pnt(coord1).Nx
x2& = Pnt(coord2).Nx
x3& = Pnt(coord3).Nx

y1& = Pnt(coord1).Ny
y2& = Pnt(coord2).Ny
y3& = Pnt(coord3).Ny

IF (x1& - x2&) * (y3& - y2&) - (y1& - y2&) * (x3& - x2&) < 0 THEN Poly(i&).Culled = True
NEXT

FOR i& = 1 TO MaxPolygons
FOR ii& = 1 TO MaxPolygons - 1
IF Poly(Pointer(ii&)).AvgZ > Poly(Pointer(ii& + 1)).AvgZ THEN SWAP Pointer(ii&), Pointer(ii& + 1)
NEXT
NEXT

FOR ii& = 1 TO MaxPolygons
i& = Pointer(ii&)
IF NOT Poly(i&).Culled = True THEN
DrawPoly Pnt(Poly(i&).P1).x + SrX, Pnt(Poly(i&).P1).y + SrY, Pnt(Poly(i&).P2).x + SrX, Pnt(Poly(i&).P2).y + SrY, Pnt(Poly(i&).P3).x + SrX, Pnt(Poly(i&).P3).y + SrY, Pnt(Poly(i&).P1).Shade + Poly(i&).Col, Pnt(Poly(i&).P2).Shade + Poly(i&).Col,  _
END IF
NEXT
Memcopy VARSEG(Buffer(0, 0)), VARPTR(Buffer(0, 0)), &HA000, 0, &HFA00
Fillchar VARSEG(Buffer(0, 0)), VARPTR(Buffer(0, 0)), 0, &HFA00

'Print Point numbers
IF PDisp = True THEN
FOR i = 1 TO MaxPoints
Ty = (Pnt(i).y + SrY) \ 8 + 1
Tx = (Pnt(i).x + SrX) \ 8 + 1
IF Ty > 23 THEN Ty = 23
IF Ty < 1 THEN Ty = 1
IF Tx < 1 THEN Tx = 1
IF Tx > 40 THEN Tx = 40
LOCATE Ty, Tx
PRINT LTRIM$(RTRIM$(STR$((i)))) NEXT END IF HandleKeys SELECT CASE AnimType CASE 1 ShadingModel = 4 FOR y = 0 TO TSize - 1 FOR x = 0 TO TSize Txt(x, y + 1) = (Txt(x - 1, y - 1) + Txt(x, y - 1) + Txt(x + 1, y - 1) + Txt(x + 1, y) + Txt(x + 1, y + 1) + Txt(x, y + 1) + Txt(x - 1, y + 1) + Txt(x - 1, y)) \ 8 - 1 NEXT NEXT FOR i = 0 TO TSize \ 4 XPos = RND * TSize Temp = RND * 63 Txt(XPos, -1) = RND * Temp Txt(XPos, 0) = RND * Temp NEXT CASE 2 ShadingModel = 4 Lx& = Lx& + XAdd& Ly& = Ly& + YAdd& FOR y& = 0 TO TSize FOR x& = 0 TO TSize Txt(x&, y&) = Temp(x&, y&) NEXT NEXT FOR y& = 0 TO LSize FOR x& = 0 TO LSize Txt((x& + Lx&) MOD TSize, (y& + Ly&) MOD TSize) = Txt((x& + Lx&) MOD TSize, (y& + Ly&) MOD TSize) + l(x&, y&) NEXT NEXT Lx& = Lx& + XAdd& Ly& = Ly& + YAdd& IF Lx& = TSize THEN XAdd& = -XAdd& IF Lx& = 0 THEN XAdd& = -XAdd& IF Ly& = TSize - 2 THEN YAdd& = -YAdd& IF Ly& = 0 THEN YAdd& = -YAdd& CASE 3 ShadingModel = 4 FOR y = 1 TO TSize - 1 FOR x = 0 TO TSize Txt(x, y - 1) = Txt(x, y) NEXT NEXT FOR i = 0 TO TSize Txt(i, TSize - 1) = Txt(i, 0) NEXT CASE 4 ShadingModel = 4 WAVE1 = WAVE1 + WaveSide1 IF WAVE1 >= 80 THEN WAVE1 = 0 R1 = (R1 + 1) AND 255 WaveSide1 = Rand(R1) END IF WAVE2 = WAVE2 + WaveSide2 IF WAVE2 >= 80 THEN WAVE2 = 0 R2 = (R2 + 2) AND 255 WaveSide2 = Rand(R2) END IF WAVE3 = WAVE3 + WaveSide3 IF WAVE3 >= 80 THEN WAVE3 = 0 R3 = (R3 + 2) AND 255 WaveSide3 = Rand(R3) END IF FOR y& = 0 TO TSize E = Cosinus(y& + WAVE1) FOR x& = 0 TO TSize Col = Cosinus(x& + WAVE2) + E + Cosinus(x& + WAVE3) + Cosinus(x& + y&) IF Col > 127 THEN Col = 127 Txt(x&, y&) = Col NEXT NEXT END SELECT '---------------------------------------------------------------------------- ' Update rotation velocities '---------------------------------------------------------------------------- Xr = Xr + Vx Yr = Yr + Vy Zr = Zr + Vz IF Xr < 0 THEN Xr = 360 + Xr IF Yr < 0 THEN Yr = 360 + Yr IF Zr < 0 THEN Zr = 360 + Zr Xr = Xr MOD 361 Yr = Yr MOD 361 Zr = Zr MOD 361 IF TIMER >= start& + 2 THEN FPS& = INT(Frame / 2) Frame = 0 start& = INT(TIMER) END IF Frame = Frame + 1 IF FDisp = True THEN COLOR 255 LOCATE 1, 1: PRINT FPS&; "fps " END IF IF MouseNotFound = 0 THEN HiiriLue B1, B2, B3, MouseX, MouseY IF B1 = -1 THEN Xr = MouseX Zr = MouseY END IF END IF LOOP 'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ' Object data 'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ObjectData: ' Number of points DATA 5 ' Number of polygons DATA 6 ' Point data ' ' X Y Z DATA -100, 0, 100 DATA -100, 0, -100 DATA 100, 0, -100 DATA 100, 0, 100 DATA 0, -190, 0 ' Polygon data ' ' Pnt1 Pnt2 Pnt3 Color (1-4) DATA 5, 1, 4, 1 DATA 5, 4, 3, 2 DATA 5, 2, 1, 3 DATA 5, 3, 2, 4 DATA 4, 1, 2, 1 DATA 4, 2, 3, 1 MouseData: DATA 55, 89, E5, 8B, 5E, 0C, 8B, 07, 50, 8B, 5E, 0A, 8B, 07, 50, 8B DATA 5E, 08, 8B, 0F, 8B, 5E, 06, 8B, 17, 5B, 58, 1E, 07, CD, 33, 53 DATA 8B, 5E, 0C, 89, 07, 58, 8B, 5E, 0A, 89, 07, 8B, 5E, 08, 89, 0F DATA 8B, 5E, 06, 89, 17, 5D, CA, 08, 00 REM$STATIC
SUB ColPrint (Text$) '---------------------------------------------------------------------------- ' SúYúSúTúEúM '---------------------------------------------------------------------------- '---------------------------------------------------------------------------- ' Prints color-coded text '---------------------------------------------------------------------------- ' Color codes: ' ' & followed by a color value between 0-15 (in hex) ' ' Example: ' ' This text is &Cred '---------------------------------------------------------------------------- FOR i = 1 TO LEN(Text$)
Done = 0
DO
IF MID$(Text$, i, 1) = "&" AND INSTR("0123456789ABCDEF", MID$(Text$, i + 1, 1)) AND i < LEN(Text$) THEN COLOR VAL("&H" + MID$(Text$, i + 1, 1)) i = i + 2 ELSE Done = 1 END IF LOOP UNTIL Done PRINT MID$(Text$, i, 1); NEXT END SUB SUB DrawLine (x, y, x2, y2, Col1, Col2, Tx1, Ty1, Tx2, Ty2) '---------------------------------------------------------------------------- ' Calculate the points of a polygon into the buffer '---------------------------------------------------------------------------- IF y < Upper THEN Upper = y IF y > Lower THEN Lower = y IF Upper < 0 THEN Upper = 0 IF Lower > 199 THEN Lower = 199 'Calculate deltas and scale by 1024 Steps = SQR((x2 - x) ^ 2 + ((y2 - y) ^ 2)) IF Steps > 0 THEN XStep& = ((x2 - x) / Steps) * 1024 YStep& = ((y2 - y) / Steps) * 1024 ColStep& = ((Col2 - Col1) / Steps) * 1024 ELSE EXIT SUB END IF Tempxx& = x Tempyy& = y xxx& = Tempxx& * 1024 yyy& = Tempyy& * 1024 Col& = CLNG(Col1) * 1024 IF ShadingModel = 4 THEN Tx& = CLNG(Tx1) * 1024 Ty& = CLNG(Ty1) * 1024 TxDelta& = ((Tx2 - Tx1) / Steps) * 1024 TyDelta& = ((Ty2 - Ty1) / Steps) * 1024 FOR i& = 1 TO Steps IF yyy& >= 0 AND yyy& < 204800 THEN IF xxx& \ 1024 < Fill(yyy& \ 1024).x1 THEN Fill(yyy& \ 1024).x1 = xxx& \ 1024 Fill(yyy& \ 1024).Tx = Tx& \ 1024 Fill(yyy& \ 1024).Ty = Ty& \ 1024 Fill(yyy& \ 1024).Col1 = Col& \ 1024 END IF IF xxx& \ 1024 > Fill(yyy& \ 1024).x2 THEN Fill(yyy& \ 1024).x2 = xxx& \ 1024 Fill(yyy& \ 1024).Tx2 = Tx& \ 1024 Fill(yyy& \ 1024).Ty2 = Ty& \ 1024 Fill(yyy& \ 1024).Col2 = Col& \ 1024 END IF END IF xxx& = xxx& + XStep& yyy& = yyy& + YStep& Tx& = Tx& + TxDelta& Ty& = Ty& + TyDelta& Col& = Col& + ColStep& NEXT ELSE FOR i& = 1 TO Steps IF yyy& >= 0 AND yyy& < 204800 THEN IF xxx& \ 1024 < Fill(yyy& \ 1024).x1 THEN Fill(yyy& \ 1024).x1 = xxx& \ 1024 Fill(yyy& \ 1024).Col1 = Col& \ 1024 END IF IF xxx& \ 1024 > Fill(yyy& \ 1024).x2 THEN Fill(yyy& \ 1024).x2 = xxx& \ 1024 Fill(yyy& \ 1024).Col2 = Col& \ 1024 END IF END IF xxx& = xxx& + XStep& yyy& = yyy& + YStep& Col& = Col& + ColStep& NEXT END IF END SUB SUB DrawPoly (x, y, x2, y2, x3, y3, P1, P2, P3, Num) FOR i2 = 1 TO 199 Fill(i2).x1 = 321 Fill(i2).x2 = -1 Fill(i2 - 1).x1 = 321 Fill(i2 - 1).x2 = -1 Fill(i2).Col1 = 0 Fill(i2).Col2 = 0 Fill(i2 - 1).Col1 = 0 Fill(i2 - 1).Col2 = 0 NEXT DrawLine x, y, x2, y2, P1, P2, TSize \ 2, TSize, TSize, 0 DrawLine x3, y3, x, y, P3, P1, 0, 0, TSize \ 2, TSize DrawLine x2, y2, x3, y3, P2, P3, TSize, 0, 0, 0 SELECT CASE ShadingModel CASE 1 OldPos1 = 321 OldPos2 = 321 FOR yy& = Upper TO Lower - 1 XLen = Fill(yy&).x2 - Fill(yy&).x1 IF XLen > 0 AND Fill(yy&).x1 > 0 AND Fill(yy&).x2 < 319 AND Fill(yy&).x1 < 319 AND Fill(yy&).x2 > 0 THEN IF OldPos1 < 320 AND OldPos1 > 0 THEN IF OldPos1 > Fill(yy&).x1 THEN FOR xx& = OldPos1 - 1 TO Fill(yy&).x1 STEP -1 Buffer(xx&, yy&) = CHR$(Fill(yy&).Col1 MOD 255)
NEXT
ELSE
FOR xx& = OldPos1 + 1 TO Fill(yy&).x1
Buffer(xx&, yy&) = CHR$(Fill(yy&).Col1 MOD 255) NEXT END IF ELSE Buffer(Fill(yy&).x1, yy&) = CHR$(Fill(yy&).Col1 MOD 255)
END IF

IF OldPos2 < 320 AND OldPos2 > 0 THEN
IF OldPos2 > Fill(yy&).x2 THEN
FOR xx& = OldPos2 TO Fill(yy&).x2 STEP -1
Buffer(xx&, yy&) = CHR$(Fill(yy&).Col2 MOD 255) NEXT ELSE FOR xx& = OldPos2 TO Fill(yy&).x2 Buffer(xx&, yy&) = CHR$(Fill(yy&).Col2 MOD 255)
NEXT
END IF
ELSE
Buffer(Fill(yy&).x2, yy&) = CHR\$(Fill(yy&).Col2 MOD 255)
END IF
END IF
OldPos1 = Fill(yy&).x1
OldPos2 = Fill(yy&).x2
NEXT
CASE 2
FOR yy& = Upper TO Lower - 1
XLen = Fill(yy&).x2 - Fill(yy&).x1
IF XLen > 0 THEN
ColDelta& = (Fill(yy&).Col2 - Fill(yy&).Col1) / XLen * 1024
Col& = C

### RE: texutre mapping and/ polygon filling

(OP)
It's been awhile since I have been to this site, mainly because I foregot my password, but that looks long and I will try looking through it.  I have done some math and wrote algorithms for texture mapping and an algorithm that rotates around all 3 axies instead of the ones you find that only rotate around 2 for 3d rotation.  I plan on sharing them soon.

### RE: texutre mapping and/ polygon filling

whoah!  talk about reviving an old topic!

geez, i feel so left out with all this 3d talk... ;)

anyways, i tried (and miserably failed) to learn 3d before my time. (my explanation why i couldn't understand most of it)  i found some good tuts and stuff on the net though.

www.qb45.net - i found lots and lots of stuff here.  in graphics demos or utilities.

deltacode.cjb.net - the best place to look for raytracers or whatever, not what your looking for but may be useful...

www.qbasic.com - has a few useful 3d things...

http://members.aol.com/mkwebsite/index.html - i found a few useful things on this site

dunno if any have texture mapping on the sites though.

### RE: texutre mapping and/ polygon filling

whoah!  www.qb45.net is down right now, so you'll have to go to...

www.qb45.com

trust me, this is the site you want to go to.

### RE: texutre mapping and/ polygon filling

oh, can't forget this site!  here, this site has some good stuff.  i also saw texturemapping in there somewhere :D

http://lithium.zext.net/mf.html

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!