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.
|
translation := 0@0.
|
||||||
scale := 1@1.
|
scale := 1@1.
|
||||||
rotation := 0.
|
rotation := 0.
|
||||||
tf := Array2D identity: 3.
|
tf := MatrixTransform2x3 identity .
|
||||||
shader := Diya2DShader uniqueInstance.
|
shader := Diya2DShader uniqueInstance.
|
||||||
vbuffer := nil.
|
vbuffer := nil.
|
||||||
]
|
]
|
||||||
@ -75,18 +75,15 @@ Diya2DNode >> recFromBuffer [
|
|||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
Diya2DNode >> updateTF [
|
Diya2DNode >> updateTF [
|
||||||
tf := Array2D identity:3.
|
tf := MatrixTransform2x3 identity.
|
||||||
"translation"
|
"translation"
|
||||||
translation = (0@0) ifFalse:[
|
tf setOffset: translation.
|
||||||
tf := tf +* (Array2D translateMatrix2D: translation)].
|
|
||||||
"rotation"
|
"rotation"
|
||||||
rotation = 0 ifFalse:[
|
rotation = 0 ifFalse:[tf setAngle: rotation ].
|
||||||
tf := tf +* (Array2D rotationMatrix2D: rotation )].
|
|
||||||
"scale"
|
"scale"
|
||||||
scale = (1@1) ifFalse:[
|
tf setScale: scale.
|
||||||
tf := tf +* (Array2D scaleMatrix2D: scale)].
|
|
||||||
self parent ifNil: [ ^self ].
|
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 ]].
|
children ifNotNil: [children do:[:c| c updateTF ]].
|
||||||
|
|
||||||
]
|
]
|
||||||
|
@ -67,8 +67,8 @@ DiyaExampleApp >> main [
|
|||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
DiyaExampleApp >> setup [
|
DiyaExampleApp >> setup [
|
||||||
|node node1 img ell label icon button|
|
|node node1 img ell label icon button texture|
|
||||||
|
texture := DiyaImageTex new.
|
||||||
"DiyaRendererContext uniqueInstance assets
|
"DiyaRendererContext uniqueInstance assets
|
||||||
addAsset:
|
addAsset:
|
||||||
((Form fromDisplay: ( Rectangle origin: 0@0 corner: 300@300 )) asDiyaTexture: 'display')."
|
((Form fromDisplay: ( Rectangle origin: 0@0 corner: 300@300 )) asDiyaTexture: 'display')."
|
||||||
@ -79,8 +79,8 @@ DiyaExampleApp >> setup [
|
|||||||
label icon: 16rF254.
|
label icon: 16rF254.
|
||||||
|
|
||||||
node1 := root addNode: (DiyaRectangle size:100@150 shader: DiyaExampleShader uniqueInstance) at: 300 @ 40.
|
node1 := root addNode: (DiyaRectangle size:100@150 shader: DiyaExampleShader uniqueInstance) at: 300 @ 40.
|
||||||
"node1 rotation: (Float pi / 8.0)."
|
node1 rotation: 45.
|
||||||
node1 scale: 1.2@1.2.
|
node1 scale: 2.0@2.0.
|
||||||
node1 on: #(mousebuttondown fingerdown) do:[:e|
|
node1 on: #(mousebuttondown fingerdown) do:[:e|
|
||||||
label txt: 'Mouse ', (node1 local: e mapped worldPosition) asIntegerPoint asString].
|
label txt: 'Mouse ', (node1 local: e mapped worldPosition) asIntegerPoint asString].
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ DiyaExampleApp >> setup [
|
|||||||
p := e mapped worldPosition.
|
p := e mapped worldPosition.
|
||||||
label txt: 'Mouse ', p asIntegerPoint asString.
|
label txt: 'Mouse ', p asIntegerPoint asString.
|
||||||
DiyaRendererContext uniqueInstance assets
|
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'.
|
img textureNamed: 'capture'.
|
||||||
|
|
||||||
].
|
].
|
||||||
@ -111,7 +111,7 @@ DiyaExampleApp >> setup [
|
|||||||
node styleName: #line_view.
|
node styleName: #line_view.
|
||||||
|
|
||||||
ell := root addNode: (DiyaEllipse rx:100 ry: 70) at: 100@300.
|
ell := root addNode: (DiyaEllipse rx:100 ry: 70) at: 100@300.
|
||||||
ell rotation: Float pi / 6.0.
|
ell rotation: 30.
|
||||||
ell styleName: #ell_view.
|
ell styleName: #ell_view.
|
||||||
"node rotation: Float pi / 2.0."
|
"node rotation: Float pi / 2.0."
|
||||||
ell textureNamed:'mrsang.png'.
|
ell textureNamed:'mrsang.png'.
|
||||||
|
@ -116,7 +116,7 @@ DiyaNode >> initialize [
|
|||||||
styleName := nil.
|
styleName := nil.
|
||||||
style := nil.
|
style := nil.
|
||||||
root := nil.
|
root := nil.
|
||||||
id := Random new nextInt: 1e6
|
id := self className,'#',(Random new nextInt: 1e6) asString.
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #accessing }
|
{ #category : #accessing }
|
||||||
|
@ -2,7 +2,7 @@ Extension { #name : #Point }
|
|||||||
|
|
||||||
{ #category : #'*Diya' }
|
{ #category : #'*Diya' }
|
||||||
Point >> applyTf: tf [
|
Point >> applyTf: tf [
|
||||||
^(tf +* (self asArray3F)) asPoint
|
^ tf localPointToGlobal: self
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #'*Diya' }
|
{ #category : #'*Diya' }
|
||||||
@ -14,18 +14,3 @@ Point >> asArray3F [
|
|||||||
Point >> asArray3F: z [
|
Point >> asArray3F: z [
|
||||||
^ { self x. self y. 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' }
|
{ #category : #'*Diya' }
|
||||||
Rectangle >> applyTf: tf [
|
Rectangle >> applyTf: tf [
|
||||||
^ Rectangle
|
^ tf localBoundsToGlobal: self
|
||||||
origin: (self origin applyTf: tf)
|
|
||||||
corner: (self corner applyTf: tf)
|
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user