Ooops
October 28, 2021, 11:46:31

Author Topic: [bb] Quad functions by Beaker [ 1+ years ago ]  (Read 811 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Quad functions by Beaker [ 1+ years ago ]
« on: June 29, 2017, 00:28:38 »
Title : Quad functions
Author : Beaker
Posted : 1+ years ago

Description : Lets you handle meshes built of quads (4 sides/vertices) instead of triangles (3 sides/vertices).  Replicates all the standard commands you have for handling triangles:
AddQuad()
CountQuads()
QuadVertex()
PickedQuad()

NB. Meshes must be basically built of quads, luckily most of the surfaces in Blitz3Ds standard primitives are.  Your loaded meshes might not.

Try the sample to work out what everything does.  Also, includes a PickedVertex() function.


Code :
Code: BlitzBasic
  1. Graphics3D 640,480,0,2
  2.  
  3. cam = CreateCamera()
  4. MoveEntity cam,0,0,-6
  5.  
  6. lit = CreateLight()
  7. TurnEntity lit,30,45,0
  8.  
  9. ball = CreateSphere(10)
  10. PositionEntity ball,3,0,0
  11. EntityPickMode ball,2
  12.  
  13. cube = CreateCube()
  14. EntityPickMode cube,2
  15.  
  16. cone = CreateCylinder(14)
  17. PositionEntity cone,-3,0,0
  18. EntityPickMode cone,2
  19.  
  20. Local tfx#[4]
  21. Local tfy#[4]
  22. Local tfz#[4]
  23.  
  24. cursor = CreateMesh()
  25. cursorsurf = CreateSurface(cursor)
  26. EntityColor cursor,255,0,0
  27. EntityOrder cursor,-9
  28.  
  29. While Not KeyDown(1)
  30.  
  31.         RenderWorld
  32.         If PickedEntity()
  33.                 Text 5,5,"picked quad = "+PickedQuad()+"/"+CountQuads(PickedSurface())
  34.                 Text 5,35,"quad verts:"
  35.                 Text 15,50,QuadVertex(PickedSurface(),PickedQuad(),0)
  36.                 Text 15,65,QuadVertex(PickedSurface(),PickedQuad(),1)
  37.                 Text 15,80,QuadVertex(PickedSurface(),PickedQuad(),2)
  38.                 Text 15,95,QuadVertex(PickedSurface(),PickedQuad(),3)
  39.         EndIf
  40.  
  41.         Text 320,440,"Use mouse to click on objects",True
  42.  
  43.         Flip
  44.        
  45.         If MouseDown(1)
  46.                 CameraPick cam,MouseX(),MouseY()
  47.                 If PickedEntity()
  48.                         surf = PickedSurface()
  49.                
  50.                         For f = 0 To 3
  51.                                 qv = QuadVertex(surf,PickedQuad(),f)
  52.                                 TFormPoint VertexX(surf,qv),VertexY(surf,qv),VertexZ(surf,qv),PickedEntity(),0
  53.                                 tfx[f] = TFormedX()
  54.                                 tfy[f] = TFormedY()
  55.                                 tfz[f] = TFormedZ()
  56.                         Next
  57.                        
  58.                         ClearSurface cursorsurf
  59.                         AddQuad2(cursorsurf, tfx[0],tfy[0],tfz[0], tfx[1],tfy[1],tfz[1], tfx[2],tfy[2],tfz[2], tfx[3],tfy[3],tfz[3])
  60.                         UpdateNormals cursor
  61.  
  62.                 EndIf
  63.         Else
  64.                 ClearSurface cursorsurf
  65.         EndIf
  66.        
  67.         TurnEntity cube,0.3,0.4,0
  68. Wend
  69. End
  70.  
  71.  
  72. Function AddQuad(surf,v0,v1,v2,v3)      ; similar to AddTriangle()
  73.         Local tri = AddTriangle(surf,v0,v1,v2)
  74.         AddTriangle(surf,v0,v2,v3)
  75.         Return tri / 2
  76. End Function
  77.  
  78. Function AddQuad2(surf, x0#,y0#,z0#, x1#,y1#,z1#, x2#,y2#,z2#, x3#,y3#,z3#)     ; alternative to above func
  79.         Local v0 = AddVertex(surf,x0,y0,z0, 0,0)
  80.         Local v1 = AddVertex(surf,x1,y1,z1, 1,0)
  81.         Local v2 = AddVertex(surf,x2,y2,z2, 1,1)
  82.         Local v3 = AddVertex(surf,x3,y3,z3, 0,1)
  83.         Local tri = AddTriangle(surf,v0,v1,v2)
  84.         AddTriangle(surf,v0,v2,v3)
  85.         Return tri / 2
  86. End Function
  87.  
  88.  
  89. Function CountQuads(surf)       ; similar to CountTriangles()
  90.         Return CountTriangles(surf) / 2
  91. End Function
  92.  
  93. Function QuadVertex(surf,index,vertex) ; similar to TriangleVertex()
  94.         If vertex < 3
  95.                 Return TriangleVertex(surf,index*2,vertex)
  96.         EndIf
  97.         Return TriangleVertex(surf,index*2+1,2)
  98. End Function
  99.  
  100.  
  101. Function PickedQuad()   ; similar to PickedTriangle()
  102.         Return PickedTriangle() / 2
  103. End Function
  104.  
  105.  
  106.  
  107. Function PickedVertex() ; similar to PickedTriangle()/PickedSurface() etc
  108.         Local f, pv
  109.         Local dx#,dy#,dz#
  110.         Local vert, dist#, nearest# = -1.0
  111.         Local surf = PickedSurface()
  112.        
  113.         TFormPoint PickedX(),PickedY(),PickedZ(),0,PickedEntity()
  114.         For f = 0 To 2
  115.                 vert = TriangleVertex(surf,PickedTriangle(),f)
  116.                 dx = TFormedX()-VertexX(surf,vert)
  117.                 dy = TFormedY()-VertexY(surf,vert)
  118.                 dz = TFormedZ()-VertexZ(surf,vert)
  119.                 dist = dx*dx + dy*dy + dz*dz
  120.                 If dist < nearest Or nearest < 0.0
  121.                         pv = vert
  122.                         nearest = dist
  123.                 EndIf
  124.         Next
  125.         Return pv
  126. End Function


Comments :


RiverRatt(Posted 1+ years ago)

 Thank you very much, this just might help me with a little project of mine. Just what I needed.


ShadowTurtle(Posted 1+ years ago)

 this use realy quaT math
Code: [Select]
Code removed


Beaker(Posted 1+ years ago)

 quat <> quad.quad = quadrangle = 2 triangles making a square.


ShadowTurtle(Posted 1+ years ago)

 ui.. sorry.. this was a long day for me -.- [/i]

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal