Skip to content

Instantly share code, notes, and snippets.

View easylogic's full-sized avatar
😀
happy coding

jinho park easylogic

😀
happy coding
View GitHub Profile
@easylogic
easylogic / sending-message.md
Last active August 30, 2021 15:13
messaging rule

create or insert

{ type: "create", id: "", attrs: { id  포함한 생성된 전체 데이타 보내기} } 

update

@easylogic
easylogic / zoomingViewport.js
Created February 7, 2021 16:17
zoomingViewport
zoom (zoomFactor) {
const oldScale = this.scale;
const newScale = oldScale * zoomFactor
this.setScale(newScale)
const newZoomFactor = this.scale / oldScale;
this.zoomFactor = newZoomFactor;
@easylogic
easylogic / resizeViewport.js
Last active February 7, 2021 15:53
resizeViewport
// 새로운 canvas 사이즈 설정
this.canvasSize = {
x: rect.x ,
y: rect.y ,
width: rect.width,
height: rect.height
}
// viewport verties 설정
this.cachedViewport = rectToVerties(0, 0, this.canvasSize.width, this.canvasSize.height)
@easylogic
easylogic / viewportPratice.js
Created February 7, 2021 15:36
viewportPratice
// mouse point 로 viewport 위치 조회
this.initMousePoint = this.$viewport.createWorldPosition(e.clientX, e.clientY);
// 드래그 한 mouse point 로 처음 위치와의 차이를 viewport 기준으로 구하기
const targetMousePoint = this.$viewport.createWorldPosition(e.clientX, e.clientY);
const distVector = vec3.subtract([], targetMousePoint, this.initMousePoint);
// 특정 Vertex 좌표를 viewport 좌표로 적용
const localSourceVertext = this.$viewport.applyVerties([source])[0];
@easylogic
easylogic / resetViewportMatrix.js
Created February 7, 2021 12:17
resetViewportMatrix
/**
* 2가지 기본 matrix 를 설정한다.
*
* 1. world matrix
* 2. scale matrix - 이동 간격을 계산할 때 주로 사용
*
*/
resetWorldMatrix () {
// world matrix
@easylogic
easylogic / initializeViewport.js
Created February 7, 2021 12:09
initialize viewport
this.canvasSize = {
x: rect.x,
y: rect.y,
width: rect.width,
height: rect.height
}
this.cachedViewport = rectToVerties(0, 0, this.canvasSize.width, this.canvasSize.height)
this.setTransformOrigin([ this.canvasSize.width/2, this.canvasSize.height/2,0])
@easylogic
easylogic / newLocalMatrixWithNewTranslate.js
Created February 7, 2021 11:35
newLocalMatrixWithNewTranslate
const list = Transform.parseStyle(newChildItemTransform);
const width = childItem.screenWidth.value;
const height = childItem.screenHeight.value;
const newTransformMatrix = Transform.createTransformMatrix(list, width, height);
const [x, y, z] = mat4.getTranslation([], calculateMatrix(
matrix,
calculateMatrixInverse(
childItem.getTransformOriginMatrix(),
newTransformMatrix,
childItem.getTransformOriginMatrixInverse(),
@easylogic
easylogic / newLocalMatrixWithRotateAndScale.js
Last active February 7, 2021 11:30
newLocalMatrixWithRotateAndScale
// scale 구하기
const newScaleTransform = Transform.fromScale(
mat4.getScaling([], matrix).map(it => round(it, 1000))
);
// 회전 영역 먼저 구하기
const q = mat4.getRotation([], matrix);
const axis = []
const rad = quat.getAxisAngle(axis, q)
@easylogic
easylogic / newLocalMatrix.js
Created February 7, 2021 11:24
newLocalMatrix
const matrix = calculateMatrix(
this.getAccumulatedMatrixInverse(),
childItem.getAccumulatedMatrix(),
)
@easylogic
easylogic / realWidthHeight.js
Last active February 7, 2021 10:59
realWidthHeight
let [realDx, realDy] = this.calculateRealDist(item, 2, distVector)
// 변형되는 넓이 높이 구하기
const newWidth = item.width + realDx;
const newHeight = item.height + realDy;