mirror of
https://github.com/lxsang/Diya-API.git
synced 2024-12-26 19:38:22 +01:00
Refactor code + use primitive for 2D matrix transformation
This commit is contained in:
parent
9442050825
commit
664e2169f3
@ -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
|
||||
}
|
||||
]
|
@ -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 ]].
|
||||
|
||||
]
|
||||
|
@ -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'.
|
||||
|
@ -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 }
|
||||
|
@ -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)
|
||||
]
|
||||
|
@ -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
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user