BlitzCoder Essentials
•
Home Page
•
About BlitzCoder
•
Contributors
•
Terms of Use
•
Email Us
Main Areas
•
BlitzCoder Chat
•
Discussions
•
Articles/Tutorials
•
Code Database
•
Link Database
•
Showcase Area
•
Worklogs
•
Competitions
Special Areas
•
Undocumented
Other Blitz Sites
•
Blitz Basic Home
•
Blitz Showcase
•
BlitzPlay Library
Forum Login
Username:
Password:
•
Register Now!
BlitzCoder Code Archives Page
Main Codes Page
"Example - Adjusting UV Co-ords on simple quad meshes"
, by snarkbait
An example of how to adjust the UV texture coords on a simple, 2-poly quad mesh. Use any square image to test.
Code
; Adjusting UV coords on a 2-poly quad mesh ; Instead of using 'postiontexture' and 'scaletexture' ; since those commands will affect all of the instances of that texture ; If you have lots of wall/floor/ceiling sections, you will need to adjust ; them individually ; by Snarkbait Graphics3D 800,600 SetBuffer BackBuffer() ;Include "quad.bb" ;(I have all my create quad functions in an include file, but not here) ;ftex = LoadAnimTexture("walls2.png",1,64,64,0,30) ; texture should be square walltex = LoadTexture("wall1.png") Color 0,255,0 cam = CreateCamera() cx# = 0:cy# = 0:cz# = -4 PositionEntity cam,cx,cy,cz Global base = 2 ; use this for the 'base' size for a texture to be i.e. 2 x 2 in world coords Global top_x# = -1 ; change these values Global top_y# = 1 ; for different size quad Global bot_x# = 1 ; going from top left to bottom right Global bot_y# = -1 ; Global quad_z = 0 ; keep this the same quad = create_xy_quad(top_x,top_y,bot_x,bot_y,quad_z) ; send coords to function surf = GetSurface(quad,1) ;I know there's only 1 surface, so no need For CountSurfaces cv = CountVertices(surf) ; get the verts ;EntityTexture quad,ftex,19 EntityTexture quad,walltex While Not KeyHit(1) Cls If KeyHit(2) ; move texture left For a = 0 To cv - 1 vu# = VertexU#(surf,a) vv# = VertexV#(surf,a) vu = vu + 0.1 VertexTexCoords surf,a,vu,vv Next EndIf If KeyHit(3) ; move texture right For a = 0 To cv - 1 vu# = VertexU#(surf,a) vv# = VertexV#(surf,a) vu = vu - 0.1 VertexTexCoords surf,a,vu,vv Next EndIf If KeyHit(4) ; move texture up For a = 0 To cv - 1 vu# = VertexU#(surf,a) vv# = VertexV#(surf,a) vv = vv + 0.1 VertexTexCoords surf,a,vu,vv Next EndIf If KeyHit(5) ; move texture down For a = 0 To cv - 1 vu# = VertexU#(surf,a) vv# = VertexV#(surf,a) vv = vv - 0.1 VertexTexCoords surf,a,vu,vv Next EndIf If KeyHit(6) ;scale down For a = 0 To cv-1 vu# = VertexU#(surf,a) vv# = VertexV#(surf,a) vu = vu / .8 vv = vv / .8 VertexTexCoords surf,a,vu,vv Next EndIf If KeyHit(7) ;scale up For a = 0 To cv - 1 vu# = VertexU#(surf,a) vv# = VertexV#(surf,a) vu = vu * .8 vv = vv * .8 VertexTexCoords surf,a,vu,vv Next EndIf If KeyHit(8) ; resets position/scaling and unlocks tex size VertexTexCoords surf,0,0,0 ; (stretch to fit quad) VertexTexCoords surf,1,1,0 VertexTexCoords surf,2,0,1 VertexTexCoords surf,3,1,1 VertexTexCoords surf,4,0,1 VertexTexCoords surf,5,1,0 EndIf If KeyHit(9) ; resets pos/scaling and locks tex size to 'base' vx# = MeshWidth(quad)/base ; yes, all your base are belong to us vy# = MeshHeight(quad)/base VertexTexCoords surf,0,0,0 VertexTexCoords surf,1,vx,0 VertexTexCoords surf,2,0,vy VertexTexCoords surf,3,vx,vy VertexTexCoords surf,4,0,vy VertexTexCoords surf,5,vx,0 EndIf If KeyHit(10) ; scales quad up, not texture, X-axis ScaleMesh quad,1.1,1,1 EndIf If KeyHit(11) ; scales quad down, not texture, X-axis ScaleMesh quad,0.9,1,1 EndIf If KeyHit(12) ; scales quad up, not texture, Y-axis ScaleMesh quad,1,1.1,1 EndIf If KeyHit(13) ; scales quad down, not texture, Y-axis ScaleMesh quad,1,0.9,1 EndIf UpdateWorld RenderWorld ; Text 0,0,"VU=" + vu + "VV=" + vv Text 0,0,"[1] Move texture right [2] Move texture left [3] Move texture up" Text 0,16,"[4] Move texture down [5] Scale texture down [6] Scale texture up" Text 0,32,"[7] Reset/unlock size [8] Reset, lock size [9] Scale quad up, X-axis" Text 0,48,"[10] Scale quad down X [-] Scale quad up, Y [=] Scale quad down, Y" Flip Wend End Function create_xy_quad(x1#,y1#,x2#,y2#,z#) u# = 0 vx# = (x2 - x1)/base ; sets v factor for locking texture size on x-axis vy# = (y1 - y2)/base ; sets v factor for locking texture size on y-axis mesh = CreateMesh() surf = CreateSurface(mesh) v0 = AddVertex(surf,x1,y1,z,u,u) ; top left vertex v1 = AddVertex(surf,x2,y1,z,vx,u) ; top right vert v2 = AddVertex(surf,x1,y2,z,u,vy) ; bottom left tri1 = AddTriangle(surf,v0,v1,v2) ; Make first poly v3 = AddVertex(surf,x2,y2,z,vx,vy) ; bottom right v4 = AddVertex(surf,x1,y2,z,u,vy) ; bottom left v5 = AddVertex(surf,x2,y1,z,vx,u) ; top right tri2 = AddTriangle(surf,v3,v4,v5) ; Make second poly ; UpdateNormals mesh ; add this command when used with lighting ; EntityPickMode mesh,2 ; this was for my own purposes Return mesh
Copyright(c) 2000-2004, BlitzCoder. All Rights Reserved.
Code software created by Krylar's Kreations