diff --git a/Diya/Array2D.extension.st b/Diya/Array2D.extension.st deleted file mode 100644 index 3459e56..0000000 --- a/Diya/Array2D.extension.st +++ /dev/null @@ -1,41 +0,0 @@ -Extension { #name : #Array2D } - -{ #category : #'*Diya' } -Array2D >> asGLBuffer [ - |buffer i| - i := 1. - buffer := FFIExternalArray externalNewType: #float size: self size. - self asArray do:[:e| - buffer at:i put:e. - i := i+1 - ]. - buffer autoRelease. - ^buffer -] - -{ #category : #'*Diya' } -Array2D class >> rotationMatrix2D: rotation [ - ^Array2D rows: 3 columns: 3 contents:{ - rotation cos. (rotation sin) negated. 0.0. - rotation sin. rotation cos. 0.0. - 0.0. 0.0. 1.0 - } -] - -{ #category : #'*Diya' } -Array2D class >> scaleMatrix2D: scale [ - ^Array2D rows: 3 columns: 3 contents:{ - scale x. 0.0. 0.0. - 0.0. scale y. 0.0. - 0.0. 0.0. 1.0 - } -] - -{ #category : #'*Diya' } -Array2D class >> translateMatrix2D: translation [ - ^Array2D rows: 3 columns: 3 contents: { - 1.0. 0.0. translation x. - 0.0. 1.0. translation y. - 0.0. 0.0. 1.0 - } -] diff --git a/Diya/Diya2DNode.class.st b/Diya/Diya2DNode.class.st index 7e001ca..d9b3026 100644 --- a/Diya/Diya2DNode.class.st +++ b/Diya/Diya2DNode.class.st @@ -40,7 +40,7 @@ Diya2DNode >> initialize [ translation := 0@0. scale := 1@1. rotation := 0. - tf := Array2D identity: 3. + tf := MatrixTransform2x3 identity . shader := Diya2DShader uniqueInstance. vbuffer := nil. ] @@ -75,18 +75,15 @@ Diya2DNode >> recFromBuffer [ { #category : #accessing } Diya2DNode >> updateTF [ - tf := Array2D identity:3. + tf := MatrixTransform2x3 identity. "translation" - translation = (0@0) ifFalse:[ - tf := tf +* (Array2D translateMatrix2D: translation)]. + tf setOffset: translation. "rotation" - rotation = 0 ifFalse:[ - tf := tf +* (Array2D rotationMatrix2D: rotation )]. + rotation = 0 ifFalse:[tf setAngle: rotation ]. "scale" - scale = (1@1) ifFalse:[ - tf := tf +* (Array2D scaleMatrix2D: scale)]. + tf setScale: scale. self parent ifNil: [ ^self ]. - self parent isRoot ifFalse: [tf := self parent tf +* tf ]. + self parent isRoot ifFalse: [tf := self parent tf composedWithLocal: tf ]. children ifNotNil: [children do:[:c| c updateTF ]]. ] diff --git a/Diya/DiyaExampleApp.class.st b/Diya/DiyaExampleApp.class.st index 9a3392e..b6afc7e 100644 --- a/Diya/DiyaExampleApp.class.st +++ b/Diya/DiyaExampleApp.class.st @@ -67,8 +67,8 @@ DiyaExampleApp >> main [ { #category : #accessing } DiyaExampleApp >> setup [ - |node node1 img ell label icon button| - + |node node1 img ell label icon button texture| + texture := DiyaImageTex new. "DiyaRendererContext uniqueInstance assets addAsset: ((Form fromDisplay: ( Rectangle origin: 0@0 corner: 300@300 )) asDiyaTexture: 'display')." @@ -79,8 +79,8 @@ DiyaExampleApp >> setup [ label icon: 16rF254. node1 := root addNode: (DiyaRectangle size:100@150 shader: DiyaExampleShader uniqueInstance) at: 300 @ 40. - "node1 rotation: (Float pi / 8.0)." - node1 scale: 1.2@1.2. + node1 rotation: 45. + node1 scale: 2.0@2.0. node1 on: #(mousebuttondown fingerdown) do:[:e| label txt: 'Mouse ', (node1 local: e mapped worldPosition) asIntegerPoint asString]. @@ -93,7 +93,7 @@ DiyaExampleApp >> setup [ p := e mapped worldPosition. label txt: 'Mouse ', p asIntegerPoint asString. DiyaRendererContext uniqueInstance assets - addAsset:(DiyaImageTex fromDisplay: (Rectangle origin: ((p x - 100) @ (p y - 100)) extent: 200@200 ) as: 'capture'). + addAsset:(texture fromDisplay: (Rectangle origin: ((p x - 100) @ (p y - 100)) extent: 200@200 ) as: 'capture'). img textureNamed: 'capture'. ]. @@ -111,7 +111,7 @@ DiyaExampleApp >> setup [ node styleName: #line_view. ell := root addNode: (DiyaEllipse rx:100 ry: 70) at: 100@300. - ell rotation: Float pi / 6.0. + ell rotation: 30. ell styleName: #ell_view. "node rotation: Float pi / 2.0." ell textureNamed:'mrsang.png'. diff --git a/Diya/DiyaNode.class.st b/Diya/DiyaNode.class.st index 5c3c6e5..770ade9 100644 --- a/Diya/DiyaNode.class.st +++ b/Diya/DiyaNode.class.st @@ -116,7 +116,7 @@ DiyaNode >> initialize [ styleName := nil. style := nil. root := nil. - id := Random new nextInt: 1e6 + id := self className,'#',(Random new nextInt: 1e6) asString. ] { #category : #accessing } diff --git a/Diya/Point.extension.st b/Diya/Point.extension.st index e378a73..c15bc71 100644 --- a/Diya/Point.extension.st +++ b/Diya/Point.extension.st @@ -2,7 +2,7 @@ Extension { #name : #Point } { #category : #'*Diya' } Point >> applyTf: tf [ - ^(tf +* (self asArray3F)) asPoint + ^ tf localPointToGlobal: self ] { #category : #'*Diya' } @@ -14,18 +14,3 @@ Point >> asArray3F [ Point >> asArray3F: z [ ^ { self x. self y. z } ] - -{ #category : #'*Diya' } -Point >> asGLCoord [ - |res| - res := DiyaRendererContext uniqueInstance resolution. - ^(self / ( res / 2.0)) + (-1.0@ -1.0). -] - -{ #category : #'*Diya' } -Point >> glNormalise [ - |res p| - res := DiyaRendererContext uniqueInstance resolution. - p := self / (res/ 2). - ^ (p x asFloat) @ (p y asFloat) -] diff --git a/Diya/Rectangle.extension.st b/Diya/Rectangle.extension.st index 81563d8..37ac68b 100644 --- a/Diya/Rectangle.extension.st +++ b/Diya/Rectangle.extension.st @@ -2,7 +2,5 @@ Extension { #name : #Rectangle } { #category : #'*Diya' } Rectangle >> applyTf: tf [ - ^ Rectangle - origin: (self origin applyTf: tf) - corner: (self corner applyTf: tf) + ^ tf localBoundsToGlobal: self ]