Code archives/3D Graphics - Mesh/The Open Source Single Surface Quad Library
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
The Open Source Single Surface Quad Library Add your own functions to this thread and I'll add them to the source for download. | |||||
;================================================================== ;The Open Source 3D Quad Library ;================================================================== Function QuadAdd%(s%,width#,height#) Local o%,v% v=AddVertex(s,-width#,-height#,0 ,0.0,1.0) AddVertex s,width#,-height#,0 , 1.0,1.0 AddVertex s,-width#,height#,0 , 0.0,0.0 AddVertex s,width#,height#,0 , 1.0,0.0 AddTriangle s,v+0,v+2,v+1 AddTriangle s,v+1,v+2,v+3 For o=0 To 3 VertexNormal s,v+o,0,0,-1 Next Return v End Function Function QuadColor(s%,i%,r%,g%,b%,a#=1.0) Local o% For o=0 To 3 VertexColor s,i+o,r,g,b,a Next End Function Function QuadPosition(s%,i%,x#,y#,z#=0.0) Local dx#,dy#,dz# , o% dx=x-VertexX(s,i) dy=y-VertexY(s,i) dz=z-VertexZ(s,i) For o=0 To 3 VertexCoords s,i+o,VertexX(s,i+o)+dx,VertexY(s,i+o)+dy,VertexZ(s,i+o)+dz Next End Function Function QuadRotate(s,i,x#,y#,z#) For v% = i To i+3 VertexCoords(s,v,(Cos (z#) * VertexX(s,v)) - (Sin (z#) * VertexY(s,v%)),(Sin (z#) * VertexX(s,v)) + (Cos (z#) * VertexY(s,v%)),VertexZ(s,v%)) VertexCoords(s,v,(Cos (y#) * VertexX(s,v)) + (Sin (y#) * VertexZ(s,v%)),VertexY(s,v%),-(Sin (y#) * VertexX(s,v)) + (Cos (y#) * VertexZ(s,v%))) VertexCoords(s,v,VertexX(s,v%),(Cos (x#) * VertexY(s,v%)) - (Sin (x#) * VertexZ(s,v%)) ,(Sin (x#) * VertexY(s,v%)) + (Cos (x#) * VertexZ(s,v%))) Next End Function ;================================================================== ;DEMO ;================================================================== Graphics3D 640,480,0,2 SetBuffer BackBuffer() HidePointer cam=CreateCamera() MoveEntity cam,0,0,-6.5 MoveMouse 320,240 ; container for quads container=CreateMesh() surface=CreateSurface(container) EntityFX container,1+2+32 quad=QuadAdd(surface,1,1) While Not KeyDown(1) If KeyHit(17) ;[W] w=Not w WireFrame w EndIf If KeyDown(57) ; [SPACE] QuadRotate(surface,quad,0,0,1.5) EndIf mx#=mx#+Float(MouseXSpeed())/16.0 my#=my#-Float(MouseYSpeed())/16.0 MoveMouse 320,240 QuadPosition(surface,quad,mx,my,0) RenderWorld Color 100,100,100 Text 20,40,"[MOUSE] = move main quad" Text 20,60,"[SPACE] = rotate main quad" Text 20,80,"[W] = Wireframe" Text 80,130,"Angle# = "+ang# ; reference box Color 200,0,0 Rect 320,140,100,100,0 Flip Wend End |
Comments
| ||
Confusing "o" and zero.Function QuadAdd%(s%,width#,height#) Local o%,v% v=AddVertex(s,-width#,-height#,0 ,0.0,1.0) AddVertex s,width#,-height#,0 , 1.0,1.0 AddVertex s,-width#,height#,0 , 0.0,0.0 AddVertex s,width#,height#,0 , 1.0,0.0 AddTriangle s,v+0,v+2,v+1 AddTriangle s,v+1,v+2,v+3 For o=0 To 3 VertexNormal s,v+o,0,0,-1 Next Return v End Function |
| ||
I will be significantly modifying and expanding this library in the near future. The goal is to ultimately develop a FREE Quad/Mesh-based GUI System. The GUI System will support Pixel Perfect Single Surface and Independent Surface Sprites and Meshes gadgets. Dev Goals 1. Create a 3D command set to replace Blitz3D Image and Graphics Drawing Functions. This may include Collision Functions too. 2. Create Simple 2D GUI featuring only HotSpot, Button, Viewport (Frame) Gadgets. 3. Expand 2D GUI with Animation. 4. Create 3D Gadget Command Set 5. Create 2D and 3D GUI Editors |
| ||
Well I loaded it and it does nothing in B3d 1.9... Just sits there. No rotation no movement... |
| ||
Same for me, nothing... :( |
| ||
search for : quad=QuadAdd(surface,0,0) and replace it by : quad=QuadAdd(surface,1,1) and it works ! |
Code Archives Forum