{"id":132,"date":"2007-05-12T14:57:25","date_gmt":"2007-05-12T12:57:25","guid":{"rendered":" http:\/\/www.nsonic.de\/blog\/2007\/05\/texture-mapping-walls-only\/"},"modified":"2007-05-12T14:57:26","modified_gmt":"2007-05-12T12:57:26","slug":"texture-mapping-walls-only","status":"publish","type":"post","link":"https:\/\/www.nsonic.de\/blog\/2007\/05\/texture-mapping-walls-only\/","title":{"rendered":"TEXTURE MAPPING (Walls only)"},"content":{"rendered":"<p>TEXTURE MAPPING   (Walls only)<\/p>\n<p>I have been testing and trying to do<br \/>\ntexture mapping and I finaly found out<br \/>\nthe basics and got it to work.   So I<br \/>\nhave first written down the matimatical<br \/>\nbasics and then a easy to understand<br \/>\nbasic code.   Hope you find it useful<br \/>\nAnd if you do then please write me<br \/>\na note and dont forget to give me some<br \/>\ncredit in your production&#8230;<br \/>\nFirst you got your picture in memory,<br \/>\nwich I describe like this:<br \/>\n<!--more--><br \/>\n[code lang=&#8221;delphi&#8221;]<br \/>\n            Xm<br \/>\n        +&#8212;&#8212;&#8211;+<br \/>\n        |        |<br \/>\n        |        | Ym<br \/>\n        |        |<br \/>\n        +&#8212;&#8212;&#8211;+<br \/>\n[\/code]<\/p>\n<p>And this picture shall be putted out<br \/>\nin this polygone:<br \/>\n[code lang=&#8221;delphi&#8221;]<br \/>\n  X1,Y1<br \/>\n    +&#8212;___ x2,y2<br \/>\n    |      &#8212;+<br \/>\n    |         |<br \/>\n    |         |<br \/>\n    |   ___&#8212;+<br \/>\n    +&#8212;    X3,Y3<br \/>\n  X4,Y4          <\/p>\n<p>[\/code]<br \/>\nNow you only got to do this procedure<br \/>\nevery pixel in the polygone:<\/p>\n<p>PLOT X, Y, POINT(Xp, Yp)<\/p>\n<p>Well what is Xp and Yp then?<br \/>\nWell you only got to use theese two<br \/>\nformulas:<\/p>\n<p>[code lang=&#8221;delphi&#8221;]<br \/>\n      Xm*(X-X1)<br \/>\nXp = &#8212;&#8212;&#8212;&#8212;<br \/>\n        X2 -x1<\/p>\n<p>              (Y2-Y1)*(X-X1)<br \/>\n       Ym*(y-\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4)<br \/>\n                  X2 -x1<br \/>\nYp = \u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4<br \/>\n              X*(Y3-Y2-Y4+Y1)<br \/>\n       Y4-Y2+\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4\u00c4<br \/>\n                   X2 -x1<\/p>\n<p>[\/code]<br \/>\nAs a little hint I could say that you<br \/>\nbetter do this in assembler and that<br \/>\nyoy draw the polygone in columns not<br \/>\nby lines.   And make some kind of<br \/>\ndelta values and just add in the inner<br \/>\nloops.<\/p>\n<p>Well I maybe shall help you started<br \/>\nwith a little test in Basic.  You maybe<br \/>\ndont recognise the formula but if you<br \/>\ndont then you better dont try to code<br \/>\nany Texture mapping at all!!!<\/p>\n<p>[code lang=&#8221;basic&#8221;]FOR X = x1 TO X2<br \/>\n  Xp = (Xm * (X &#8211; x1)) \/ (X2 &#8211; x1)<br \/>\n  Ys = Y1 + ((y2 &#8211; Y1) \/ (X2 &#8211; x1) * (X &#8211; x1))<br \/>\n  Ye = Y4 + ((Y3 &#8211; Y4) \/ (X2 &#8211; x1) * (X &#8211; x1))<br \/>\n    FOR Y = Ys TO Ye<br \/>\n      Yp = (Ym * (Y &#8211; Y1)) \/ (Ye &#8211; Ys)<br \/>\n      PLOT X, Y, POINT(Xp, Yp)<br \/>\n    NEXT Y<br \/>\nNEXT X<br \/>\n[\/code]<br \/>\nSome more hints is to make the original<br \/>\npicture in a length and width of 32, 64<br \/>\n128 or something equaly easy to ROL<br \/>\ninstead of MULU.<\/p>\n<p>Then I in my own code (On ST) got one<br \/>\nseperate precalculated code for every<br \/>\ncolour to plot,   and one extra for<br \/>\ntransparent picture.  (Windows)   And<br \/>\nthe transparent cod is one line long<br \/>\nand includes a RTS so guess what P-time<br \/>\nthat one takes!?!<\/p>\n<p>Well thats it,   good luck from<br \/>\nPeyloW of T.O.Y.S.<\/p>\n<p>Greetz goes to:<br \/>\nTaM,  Thanx for all but coding<br \/>\nMe,  Say helo to Josefin.<br \/>\nAIO (Pseudo),   Thanx for all muzix.<br \/>\nHydrogen,  Hey there.<br \/>\nEagle,  Havent seen you for a long&#8230;<br \/>\nOB,   I look forward to SUB STAION.<br \/>\nMF,  Min sladd tack !!!<br \/>\nAnd to all others&#8230;<\/p>\n<p>My address if you need it ?!?<\/p>\n<p>PeyloW of T.O.Y.S.<br \/>\nGreby<br \/>\n59042 Horn<br \/>\nSweden<\/p>\n<p>And phone #:<br \/>\n0494-30404<br \/>\n(I love a long chat but only 18-21)<\/p>\n<p>See ya&#8230;<\/p>\n<p>[tags]Delphi, Graphic[\/tags]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>TEXTURE MAPPING (Walls only) I have been testing and trying to do texture mapping and I finaly found out the basics and got&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[11],"tags":[75,101],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p71Tml-28","_links":{"self":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/132"}],"collection":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/comments?post=132"}],"version-history":[{"count":0,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/132\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/media?parent=132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/categories?post=132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/tags?post=132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}