@@ -78,12 +78,13 @@ interface SquareProps {
7878 depth : number ,
7979 branchLong : number
8080}
81+
8182export const squareByCoordinates = ( props : SquareProps ) : Square => {
82- const { x, y, size, branchLong } = props
83- const p1 = { x : x - size / 2 , y : y - ( size * branchLong ) / 2 }
84- const p2 = { x : x + size / 2 , y : y - ( size * branchLong ) / 2 }
85- const p3 = { x : x + size / 2 , y : y + ( size * branchLong ) / 2 }
86- const p4 = { x : x - size / 2 , y : y + ( size * branchLong ) / 2 }
83+ const { x, y, size, branchLong} = props
84+ const p1 = { x : x - size / 2 , y : y - ( size * branchLong ) / 2 }
85+ const p2 = { x : x + size / 2 , y : y - ( size * branchLong ) / 2 }
86+ const p3 = { x : x + size / 2 , y : y + ( size * branchLong ) / 2 }
87+ const p4 = { x : x - size / 2 , y : y + ( size * branchLong ) / 2 }
8788
8889 return { points : [ p1 , p2 , p3 , p4 ] , number : 1 }
8990}
@@ -99,6 +100,7 @@ interface DrawTreeProps {
99100 nauting : number ,
100101 scale : number ,
101102 offset : Point
103+ resol : [ number , number ]
102104}
103105
104106function prepareBuffers ( gl : WebGLRenderingContext , program : WebGLProgram ) {
@@ -135,15 +137,15 @@ export function drawTree(props: DrawTreeProps) {
135137 if ( ! program ) return
136138
137139 prepareBuffers ( gl , program ) ;
138- putVertexUniform ( Math . exp ( props . scale - 1 ) , props . offset , gl , program )
140+ putVertexUniform ( Math . exp ( props . scale - 1 ) , props . offset , props . resol , gl , program )
139141
140142 function drawSquares ( gl : WebGLRenderingContext , blob : PolygonBlob ) {
141143 gl . bufferData ( gl . ARRAY_BUFFER , blob . vertexBuffer , gl . STATIC_DRAW )
142144
143145 for ( let i = 0 ; i < blob . last ; i ++ ) {
144146 const c = color ( blob . buffer [ i ] , props . n )
145147 putColor ( gl , program as WebGLProgram , c )
146- gl . drawArrays ( gl . TRIANGLE_FAN , i * 4 , 4 )
148+ gl . drawArrays ( gl . TRIANGLE_FAN , i * 4 , 4 )
147149 }
148150
149151 }
@@ -168,7 +170,7 @@ export function drawTree(props: DrawTreeProps) {
168170function prepareProgram ( gl : WebGLRenderingContext ) : WebGLProgram | null {
169171 const vertexShader = gl . createShader ( gl . VERTEX_SHADER )
170172 if ( ! vertexShader ) return null
171- const fragmentShader = gl . createShader ( gl . FRAGMENT_SHADER )
173+ const fragmentShader = gl . createShader ( gl . FRAGMENT_SHADER )
172174 if ( ! fragmentShader ) return null ;
173175
174176 gl . shaderSource ( vertexShader , TreeVert )
@@ -208,16 +210,38 @@ function putColor(gl: WebGLRenderingContext, program: WebGLProgram, color: RGB)
208210 if ( ! colorLoc ) return
209211 gl . uniform3fv ( colorLoc , new Float32Array ( color . map ( c => c / 255 ) ) )
210212}
211- function putVertexUniform ( scale : number , offset : Point , gl : WebGLRenderingContext , program : WebGLProgram ) {
213+
214+ function putVertexUniform ( scale : number , offset : Point , resol : [ number , number ] , gl : WebGLRenderingContext , program : WebGLProgram ) {
212215 const tLoc = gl . getUniformLocation ( program , "u_transform" )
213216 if ( ! tLoc ) {
214217 console . error ( "unable to find transform matrix uniform" )
215218 return
216219 }
217220 gl . uniformMatrix3fv ( tLoc , false , new Float32Array ( [
218- scale , 0 , offset . x ,
219- 0 , scale , offset . y ,
220- 0 , 0 , 0
221+ scale , 0 , 0 ,
222+ 0 , scale , 0 ,
223+ 0 , 0 , 1
221224 ] ) )
225+ // const scaleId = gl.getUniformLocation(program, "scale")
226+ // if (!scaleId) {
227+ // console.error("unable to find scale uniform")
228+ // return
229+ // }
230+ // console.log(scale)
231+ // gl.uniform1f(scaleId, scale)
232+
233+ const positionId = gl . getUniformLocation ( program , "position" )
234+ if ( ! positionId ) {
235+ console . error ( "unable to find offset uniform" )
236+ return
237+ }
238+ gl . uniform2f ( positionId , offset . x , offset . y )
222239
240+ const resolId = gl . getUniformLocation ( program , "resol" )
241+ if ( ! resolId ) {
242+ console . error ( "unable to find offset uniform" )
243+ return
244+ }
245+ console . log ( resol )
246+ gl . uniform2f ( resolId , resol [ 0 ] , resol [ 1 ] )
223247}
0 commit comments