×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • 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.

Students Click Here

Help with Qbasic Polygon Texture Mapping.

Help with Qbasic Polygon Texture Mapping.

Help with Qbasic Polygon Texture Mapping.

(OP)
I really need help with texture mapping.

Heres the scenario:

3 co-ordinates for a triangle on the screen. (the screen poly)

3 mapping co-ordinates that pertain to a 100 x 100 2d array.

A texture is stored in the 2d array.


I am trying to get the texture information in the mapped polygon to be transfered to the screen polygon.

My problem is, that this screen polygon can be any orientation as can the mapped one.

(This is an ISOMETRIC simulation)

I have tried to keep the example of the situation simple.  Ive spent a good deal of time trying to build this code and came close numerous times.

Is there a piece of code or a library that can do this?
HOW?

Lol thanks for any help you might be able to provide.


RE: Help with Qbasic Polygon Texture Mapping.

I'm not quite sure what you need
You need to be able to rotate it and skew it, is that right?

RE: Help with Qbasic Polygon Texture Mapping.

(OP)
The idea is... im trying to transform the picture that falls within the mapped polygon into a completely different polygon on the screen.

I am using triangular polys, and either triangle can have any orientation.

Ive been working on this for a while but I always get something wrong.

Here is a rough code ive been working with:

DECLARE SUB mvconvert (xsratio#, ysratio#, trianglenum!)
DECLARE SUB texload (file$)
DECLARE SUB pal ()
DECLARE SUB drawTRIANGLE (trianglenum!)
DECLARE SUB getSLOPES (trianglenum!)

DIM SHARED texturedim           'texture array dimension

DIM SHARED texture(a, a) AS INTEGER    'texture array

DIM SHARED vx(100)              'vertice arrays
DIM SHARED vy(100)
DIM SHARED vz(100)

DIM SHARED mx(100) AS INTEGER   'mapped vertice arrays
DIM SHARED my(100) AS INTEGER
DIM SHARED mz(100) AS INTEGER

DIM SHARED t1(100) AS INTEGER   'triangle point index arrays
DIM SHARED t2(100) AS INTEGER
DIM SHARED t3(100) AS INTEGER

DIM SHARED rslopeAB AS DOUBLE   'real side slopes
DIM SHARED rslopeAC AS DOUBLE
DIM SHARED rslopeBC AS DOUBLE

DIM SHARED mslopeAB AS DOUBLE   'mapped side slopes
DIM SHARED mslopeAC AS DOUBLE
DIM SHARED mslopeBC AS DOUBLE

DIM SHARED rdistAB AS DOUBLE    'vertical distance between points
DIM SHARED rdistBC AS DOUBLE
DIM SHARED rdistAC AS DOUBLE
DIM SHARED rdistDC AS DOUBLE

DIM SHARED mdistAB AS DOUBLE    'vertical distance between points
DIM SHARED mdistBC AS DOUBLE
DIM SHARED mdistAC AS DOUBLE
DIM SHARED MdistDC AS DOUBLE
DIM SHARED mipcolor

DIM SHARED root$

SCREEN 13
root$ = "d:\docume~1\aliasn~1\mydocu~1\myfile~1\qb\game\"
CALL pal
CALL texload("2.2d")

'****************  Temp test values
t1(0) = 0
t2(0) = 1
t3(0) = 2

vx(0) = 50
vy(0) = 50

vx(1) = 100
vy(1) = 50

vx(2) = 75
vy(2) = 95

mx(0) = 20
my(0) = 20

mx(1) = 80
my(1) = 20

mx(2) = 50
my(2) = 80



DO
f$ = INKEY$
'LINE (vx(0), vy(0))-(vx(1), vy(1))
'LINE (vx(2), vy(2))-(vx(1), vy(1))
'LINE (vx(0), vy(0))-(vx(2), vy(2))
                            
'LINE (150 + mx(0), my(0))-(150 + mx(1), my(1))
'LINE (150 + mx(2), my(2))-(150 + mx(1), my(1))
'LINE (150 + mx(0), my(0))-(150 + mx(2), my(2))

CALL getSLOPES(0)

LOCATE 1, 1
PRINT "AB", rslopeAB
PRINT "BC", rslopeBC
PRINT "AC", rslopeAC


CALL drawTRIANGLE(0)


IF RIGHT$(f$, 1) = "H" THEN vy(2) = vy(2) - 5
IF RIGHT$(f$, 1) = "P" THEN vy(2) = vy(2) + 5
IF RIGHT$(f$, 1) = "K" THEN vx(2) = vx(2) - 5
IF RIGHT$(f$, 1) = "M" THEN vx(2) = vx(2) + 5

IF NOT f$ = "" THEN
        CLS
        LOCATE 10, 10
        PRINT mslopeAC
        PRINT mslopeAB
        PRINT mslopeBC





END IF

LOOP


SUB drawTRIANGLE (trianglenum)

'point of origin is point number one.  ix iy are relative to this point.
'
'yside = y value on the side of the triangle
'xside = x value on the side of the triangle
'
'yside2 = y value on the side of the triangle relative to point 2
'xside2 = x value on the side of the triangle relative to point 2
'
'
'rdistAB
'rdistBC

DIM xside AS DOUBLE
DIM xside2 AS DOUBLE
DIM yside AS DOUBLE
DIM yside2 AS DOUBLE
DIM rxpnt AS DOUBLE
DIM rypnt AS DOUBLE
DIM xsratio AS DOUBLE       'transfered variables to map variable converter.
DIM ysratio AS DOUBLE




ix = vx(t1(trianglenum))   'sets relative points to starting origin.
iy = vy(t1(trianglenum))

'IF rdistAC = 0 THEN rdistAC = .1

IF NOT rdistDC = 0 THEN   'if statements that prevent triangle from being drawn

 FOR yside = 0 TO rdistAC STEP rdistAC / rdistDC * .5
  
  xside = yside / rdistAC
  xside = yside / rslopeAC
  xside2 = vx(t2(trianglenum)) - vx(t1(trianglenum)) + (rdistBC * (yside / -rdistAC) / rslopeBC) 'xside.... other side of triangle relative to origin
  yside2 = vy(t2(trianglenum)) - vy(t1(trianglenum)) + (rdistBC * (yside / -rdistAC))  'yside.... other side of triangle relative to origin


  FOR rxpnt = xside TO xside2 STEP .5 '**************mirror trouble here
   rypnt = ABS(rxpnt - xside) * rslopeAB
   '*** get mapping variables ready

   IF NOT (xside2 - xside) = 0 THEN
   
    PSET (vx(t1(0)) + rxpnt, vx(t1(0)) + yside), 31
    xsratio = rxpnt / ABS(xside2 - xside)
    ysratio = yside / (rdistAC)
  
   END IF
 
 
  CALL mvconvert(ABS(xsratio), ABS(ysratio), trianglenum)

   'PSET (rxpnt + ix, rypnt + yside + iy), 31' mipcolor


  NEXT rxpnt

  PSET (ix + xside2, iy + yside2), 4
  PSET (ix + xside, iy + yside), 4

 'SLEEP
 NEXT yside


END IF



END SUB


SUB getSLOPES (trianglenum)

IF NOT (vx(t2(trianglenum)) - vx(t1(trianglenum))) = 0 THEN
 rslopeAB = (vy(t2(trianglenum)) - vy(t1(trianglenum))) / (vx(t2(trianglenum)) - vx(t1(trianglenum)))
ELSE
 rslopeAB = 32000
END IF


IF NOT (vx(t2(trianglenum)) - vx(t3(trianglenum))) = 0 THEN
 rslopeBC = (vy(t2(trianglenum)) - vy(t3(trianglenum))) / (vx(t2(trianglenum)) - vx(t3(trianglenum)))
ELSE
 rslopeBC = 32000
END IF

IF NOT (vx(t3(trianglenum)) - vx(t1(trianglenum))) = 0 THEN
 rslopeAC = (vy(t3(trianglenum)) - vy(t1(trianglenum))) / (vx(t3(trianglenum)) - vx(t1(trianglenum)))
ELSE
 rslopeAC = 32000
END IF

IF rslopeAB = 0 THEN rslopeAB = .000001
IF rslopeBC = 0 THEN rslopeBC = .000001
IF rslopeAC = 0 THEN rslopeAC = .000001



mslopeAB = (my(t2(trianglenum)) - my(t1(trianglenum))) / (mx(t2(trianglenum)) - mx(t1(trianglenum)))
mslopeBC = (my(t3(trianglenum)) - my(t2(trianglenum))) / (mx(t3(trianglenum)) - mx(t2(trianglenum)))
mslopeAC = (my(t3(trianglenum)) - my(t1(trianglenum))) / (mx(t3(trianglenum)) - mx(t1(trianglenum)))

rdistAB = (vy(t2(trianglenum)) - vy(t1(trianglenum)))
rdistBC = (vy(t2(trianglenum)) - vy(t3(trianglenum)))
rdistAC = (vy(t3(trianglenum)) - vy(t1(trianglenum)))

mdistAB = (my(t2(trianglenum)) - my(t1(trianglenum)))
mdistBC = (my(t2(trianglenum)) - my(t3(trianglenum)))
mdistAC = (my(t3(trianglenum)) - my(t1(trianglenum)))

IF rdistAB = 0 THEN rdistAB = .000001
IF rdistBC = 0 THEN rdistBC = .000001
IF rdistAC = 0 THEN rdistAC = .000001



dy = (((vy(t2(trianglenum)) - vy(t1(trianglenum))) / 2)) + vy(t1(trianglenum))
dx = (((vx(t2(trianglenum)) - vx(t1(trianglenum))) / 2)) + vx(t1(trianglenum))

rdistDC = SQR((vy(t3(trianglenum)) - dy) ^ 2 + (vx(t3(trianglenum)) - dx) ^ 2)
            
'rslopeDC = (vy(t3(trianglenum)) - dy) / (vx(t3(trianglenum)) - dx)



PSET (dx, dy), 5

END SUB

SUB mvconvert (xsratio#, ysratio#, trianglenum)

DIM myside AS DOUBLE
DIM mxside AS DOUBLE

'origin is mapped point 1

myside = ysratio# * mdistAC
mxside = myside / mslopeAC

 mxside2 = mx(t2(trianglenum)) - mx(t1(trianglenum)) + (mdistBC * (myside / -mdistAC) / mslopeBC) 'xside.... other side of triangle relative to origin
 myside2 = -(my(t2(trianglenum)) - my(t1(trianglenum)) + (mdistBC * (myside / mdistAC)))'yside.... other side of triangle relative to origin



mxpt = ABS(mxside2 - mxside) * xsratio# '+ mxside
mypt = ABS(mxpt - mxside) * mslopeAB


'mipcolor = texture(mxpt + mxside + mx(t1(trianglenum)), mypt + my(t1(trianglenum)))

'LOCATE 10, 20
'PRINT mslopeAC
'PRINT myside
'PRINT myside'mx(t1(trianglenum))
'SLEEP

'COLOR RND * 100
'PSET (220 + mxpt, 120 + myside)' + mypt)
PSET (200 + mxpt + mx(t1(trianglenum)), 100 + mypt + myside + my(t1(trianglenum)))
'LINE (200, 100)-(200 + mx(t3(0)), 100 + my(t3(0))), 4


END SUB

SUB pal
 CLOSE #1
 OPEN root$ + "qb.pal" FOR INPUT AS #1

INPUT #1, a$
INPUT #1, a$
INPUT #1, a$

FOR i = 0 TO 255

 INPUT #1, r, g, B

intmod = 0
IF choice = 2 THEN intmod = 60

  red = (r \ 4) - intmod
  green = (g \ 4) - intmod
  blue = (B \ 4) - intmod

  IF blue <= 0 THEN blue = 0
  IF green <= 0 THEN green = 0
  IF red <= 0 THEN red = 0

  IF blue >= 63 THEN blue = 63
  IF green >= 63 THEN green = 63
  IF red >= 63 THEN red = 63

man = 65536 * blue + 256 * green + red

 PALETTE i, man

NEXT i
CLOSE #1


END SUB

SUB texload (file$)
zoom = 1
peffect = 0

'file$ = "0"

IF file$ = "" THEN GOSUB picdisplayend
'file$ = file$ + ".2d"

file$ = root$ + file$
      
      
        OPEN file$ FOR INPUT AS #1

        rec = 1
        INPUT #1, texboundx
        INPUT #1, texboundy
        REDIM texture(texboundx, texboundy) AS INTEGER

        header = 3
 
 
         FOR ii = 0 TO texboundy - 1
          FOR i = 0 TO texboundx - 1
      
           rec = (i + (ii * texboundy)) + header

           INPUT #1, texture(i, ii)
           PSET (i + 200, 100 + ii), texture(i, ii)

          NEXT i
         NEXT ii

        CLOSE #1


picdisplayend:
REDIM picarray(0, 0) AS INTEGER

END SUB

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.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

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:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close