반응형
블로그 이미지
개발자로서 현장에서 일하면서 새로 접하는 기술들이나 알게된 정보 등을 정리하기 위한 블로그입니다. 운 좋게 미국에서 큰 회사들의 프로젝트에서 컬설턴트로 일하고 있어서 새로운 기술들을 접할 기회가 많이 있습니다. 미국의 IT 프로젝트에서 사용되는 툴들에 대해 많은 분들과 정보를 공유하고 싶습니다.
솔웅

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리

Pinch Zoom Rotate 구현하기 - 7/11 -

2013. 2. 12. 10:32 | Posted by 솔웅


반응형
Posted on . Written by



이전 글 까지만 해도 이 코드는 유용합니다. 하지만 좀 더 다듬어야 하죠. 작은 파란 사각형을 하나 이상의 손가락으로 움직일 수 있습니다. multitouch input device의 장점은 virtual 상황에서 real world 의 느낌을 주는데 있습니다. 이 코드에 rotation 과 scaling 효과를 주면 훨씬 더 실감나게 움직이곘죠.



Relative Motion


이 작업을 하기 전에 이전 코드(6번)를 실행 시킨 후 한 손가락을 이용했을 때 사각형이 어떻게 움직이는지 한번 보세요. touch point 로 사각형의 중심이 이동한 다음에 움직이죠. 이렇게 사각형의 중심이 이동하지 않고 그냥 touch point 와 그냥 relative 하게 움직이도록 할 겁니다. 이 작업을 하기 위해 moved와 ended phases 에 코드를 추가 할 겁니다.



sample7.lua

function rect:touch(e)
local target = e.target -- get the object which received the touch event
-- handle began phase of the touch event life cycle...
if (e.phase == "began") then
print( e.phase, e.x, e.y )
local dot = newTrackDot(e) -- create a tracking dot
rect.dots[ #rect.dots+1 ] = dot -- add the new dot to the list
-- pre-store the centre position of all touch points
rect.prevCentre = calcAvgCentre( rect.dots )
return true -- we handled the began phase
elseif (e.parent == rect) then
if (e.phase == "moved") then
print( e.phase, e.x, e.y )
-- calculate the centre position of all touch points
local centre = calcAvgCentre( rect.dots )
rect.x = rect.x + (centre.x - rect.prevCentre.x) -- update the X position of rect
rect.y = rect.y + (centre.y - rect.prevCentre.y) -- update the Y position of rect
rect.prevCentre = centre -- store the centre of all touch points
else -- ‘ended’ and ‘cancelled’ phases
print( e.phase, e.x, e.y )
if (isDevice or e.numTaps == 2) then -- remove the tracking dot from the list
local index = table.indexOf( rect.dots, e.target ) -- get index of dot to be removed
table.remove( rect.dots, index ) -- remove dot from list
e.target:removeSelf() -- remove tracking dot from the screen
-- store the new centre of all touch points
rect.prevCentre = calcAvgCentre( rect.dots )
end
end
return true
end
return false -- if the target is not responsible for this touch event return false
end

main.lua

sample7.lua


여기서 수정한 부분은 아래와 같습니다.

    모든 touch 들의 center 를 계산하고 began phase 안에서 참고하기 위해 그 값을 저장한다.
    moved phase 에서 사각형의 x,y 값에 이전 touch 와 현재의 touch center 사이의 차이점을 추가적용한다.
    ended phase 에 터치들의 저장된 터치들의 중심값을 업데이트한다. 그래서 손가락을 떼더라도 다음 moved phase 에서 사각형이 필요없이 이동하지 않도록 한다.

이제 사용자는 사각형 위에 여러 손가락을 얹어도 이상하게 움직이지 않을 겁니다. 그 손가락들을 바꾸고 움직이고 해도 어색하지 않게 움직입니다. 이제 사각형이 손가락 움직임에 따라 회전하면 더 자연스럽겠네요.




반응형

Pinch Zoom Rotate 구현하기 - 6/11 -

2013. 2. 12. 09:50 | Posted by 솔웅


반응형
Posted on . Written by


multitouch display object 들을 위한 시뮬레이터 디버거를 사용하실 수 있습니다. tracking dot 중의 하나에서 touch 를 release 했을 때 이 dot 이 사라지지 않는걸 보셨을 겁니다. 이게 디버깅하기 아주 좋은 조건이거든요. 왜냐하면 touch 를 뗐어도 여러 touch point 가 있는 것처럼 데이터가 저장돼 있을 거거든요. 디버깅에는 좋지만 실제 앱을 이렇게 만드는 건 별로 유용하지는 않을 거에요. 계속 하얀 원이 쌓일 테니까요.


이 문제를 해결하시려면 rect:touch() function 의 ended phase 에서 해당 tracking dot들을 없애주면 됩니다. 일단 device 에서 running 하는지 여부를 코드의 시작 부분에서 변수에 저장해 두는 것에서부터 시작해야 되겠네요.


-- which environment are we running on?
local isDevice = (system.getInfo("environment") == "device")


The isDevice variable will be true if the code is running on a real, physical device and it can be used to automatically remove the tracking dot when the user lifts their finger.
isDevice 변수는 이 앱이 실제 디바이스에서 구동될 경우 true 가 될 겁니다. 그러면 이 값이 true 일 경우에만 손가락이 떼어질 때 해당 tracking dot 을 없애버리면 되겠죠.





sample6.lua


if (e.phase == "moved") then
print( e.phase, e.x, e.y )
 
else -- ‘ended’ and ‘cancelled’ phases
 
print( e.phase, e.x, e.y )
if ( isDevice or e.numTaps == 2 ) then -- remove the tracking dot from the list
local index = table.indexOf( rect.dots, e.target ) -- get index of dot to be removed
table.remove( rect.dots, index ) -- remove dot from list
e.target:removeSelf() -- remove tracking dot from the screen
end
end
return true
 

isDevice or e.numTaps == 2 가 있죠? 이렇게 함으로서 이미 rect:touch() function를 call 한 tap lisener 를 가지는 tracking dot을 가능하게 합니다. 그러면 시뮬레이터에서는 double tap 으로 tracking dot 을 remove 할 수 있도록 구현할 수 있습니다.

그 tap listener 는 이 코드가 시뮬레이터에서 돌아갈 때에만 동작하도록 해야합니다. 그래서 이 때 isDevice 변수를 다시 사용할 겁니다. 이 tap listener 는 tracking dot들을 생성하는 newTrackDot() 함수 안에 추가 됐습니다.


-- listen for a tap when running in the Simulator
function circle:tap(e)
if (e.numTaps == 2) then
e.parent = rect -- set the parent
rect:touch(e) -- call touch to remove the tracking dot
end
return true
end
-- only attach tap listener in the simulator
if (not isDevice) then
circle:addEventListener("tap")
end

main.lua

sample6.lua


Note that we also:
    우리는 두개의 tap 을 체크해서 double tap 일 경우에만 tracking dot을 remove 할 겁니다.
    그리고 touch 함수안에 했던 대로 .parent property를 세팅합니다.
    이 코드가 시뮬레이터에서 동작할 경우에만 해당 tap listener를 attach 합니다.



반응형


반응형

그동안 개발한 모바일 웹을 블랙베리용 WebWorks 어플리케이션으로 개발을 해야 합니다. 그래서 블랙베리 웹웍스에 대한 공부를 시작했습니다.



What's a WebWorks application?


BlackBerry WebWorks application은 블랙베리 스마트폰이나 태블릿에 설치할 수 있는 standalone web application 입니다.



What's the big deal?


첫번째로 BlackBerry WebWorks application이 standalone application 이라는 것은 원격에 있는 웹페이지나 어플리케이션을 로드하기 위해 그 주소를 일일이 타이핑할 필요가 없다는 겁니다. 이렇게 하려면 그 어플리케이션은 블랙베리 디바이스 내에 있어야 하겠죠. 그 어플리케이션은 따로 handle 할 필요가 없는 브라우저(WebKit engine container)로 볼 수 있는 앱이 되어야 합니다. 즉 컨테이너에 패키지로 들어있는 웹 asset들의 bundle 이라는 얘기죠. 


두번째로 어플리케이션을 빌드하기 위해  CSS와 HTML5 그리고 자바스크립트 같은 표준 웹 기술의 장점을 사용할 수 있다는 겁니다. 그리고 센차(Sencha), 폰갭(PhoneGap), jQuery 나 Dojo 같은 많이 사용되는 모바일 웹 프레임워크들을 사용할 수 있다는 겁니다. 표준 웹 기술을 사용함으로서 여러분이 가지고 있는 웹 개발 경험이나 웹 assets들을 활용할수 있기 때문에 어플리케이션을 빠르게 개발할 수 있는 장점을 갖게 됩니다.


세번째로는 가중 중요한 건데요. BlackBerry WebWorks platform을 사용함으로서 HTML5 어플리케이션에 native 기능을 사용하도록 만들 수 있다는 겁니다. 여러분은 자바스크립트 wrapper를 사용한 platform APIs 들을 사용하실 수 있습니다. 이를 이용해 블랙베리의 여러 기능들을 사용하실 수 있습니다. (BBM, PIM, media, hardware). 이렇게 함으로서 여러분 앱을 사용하는 유저들에게 integrated experience 를 전달할 수 있습니다. 이 모든 것들은 오픈 소스입니다. BlackBerry WebWorks 는 GitHub 에 있는 open source project 중 하나 입니다.



What tools do I need?


개발을 위한 에디터로는 여러분들이 사용하고 계시는 에디터를 그냥 사용하시면 됩니다.


BlackBerry WebWorks application을 테스트 하는 것은 여러분이 예상하시는 것 보다 훨씬 간단합니다. Ripple emulator 를 사용하세요. 그리고 여러분의 BlackBerry WebWorks application 이 작동하는 웹사이트 (로컬이든지 remote server 든지)를 point 해 주시면 됩니다. 그러면 완전히  BlackBerry WebWorks SDK 환경에서 emulating 하실 수 있습니다. 코드를 컴파일 하거나 시뮬레이터를 실행시키실 필요가 없습니다. Ripple emulator 를 사용하시면 일반 데스크탑 브라우저 개발하는 것과 비슷하게 개발하실 수 있습니다. 그러니까 소스를 고치고 싶으실 때도 그냥 에디터에서 곧바로 소스를 고치시면 됩니다. 그런 다음에 Ripple emulator 를 refresh 하시면 바뀐 소스의 결과를 보실 수 있습니다.


Ripple emulator 를 가지고 소스를 패키지화 하고 여러분 앱을 sign 하실 수도 있습니다. 여러분 앱을 패키지화하고 sign 을 하시려면 우선 BlackBerry WebWorks SDK를 인스톨 하셔야 합니다. 그리고 나서 Ripple emulator에 있는 packaging settings 를 configure 하시면 됩니다.


여러분의 어플리케이션을 블랙베리 스마트폰이나 태블릿에 deploy 하시려면 BlackBerry WebWorks SDK 을 사용하시면 됩니다.




아래 내용은 좀 더 high-level process 와 관련한 detail 들 입니다.


  1. Create your application web files (for example, HTML, CSS, and JavaScript).
  2. Test and debug your application with the Ripple emulator. For more information, see Getting started with the Ripple emulator.
  3. Create a BlackBerry WebWorks configuration document (config.xml) that contains details about your application. For more information, see Creating a configuration document.
  4. Package your application using the Ripple emulator (make sure that you install the BlackBerry WebWorks SDK first). For more information, see Packaging your app in Ripple.
  5. Deploy your application to a BlackBerry device or simulator. For BlackBerry 10 OS or BlackBerry PlayBook OS applications, you deploy a .bar file. For BlackBerry 7 (or earlier versions of the BlackBerry Device Software), you deploy a .cod file. For more information on deploying apps, see the testing section.



How do I distribute my application?


BlackBerry WebWorks application은 native BlackBerry smartphone 이나  tablet applications 과 마찬가지로 패키지화 하시면 됩니다. 블랙베리 7 용 이나 그 이전 버전 으로 개발된 스마트폰 앱들은 BlackBerry Desktop Manager 나 the BlackBerry App World storefront 같은 웹사이트를 통해서 distribute 될 수 있습니다. BlackBerry PlayBook OS 용 어플리케이션들은BlackBerry App World를 통해서면 distribute 될 수 있습니다.


앱을 distribute 하는것과 관련한 좀 더 자세한 정보를 원하시면 Distributing your application를 보세요.



What's next?

To get started, visit the following resources for developing web applications for the BlackBerry Application Platform:






반응형