Transform.Rotate



Transform.Rorate(Vector3 eulerAngles)

ex)

void Update(){

this.Transform.Rotate(new vector3(0,10,0));

}

//y축을 10도씩 회전한다. 


Transform.Rorate(Vector3 eulerAngles,Space relativeTo)

ex)

void Update(){

this.Transform.Rotate(new vector3(0,10,0),Space.World); //Space.Self

}

//Space.World 또는 Space.Self 인자를 통하여 

//월드축을 기준으로 할지 로컬축을 기준으로 할지 정할수있다.

//만약 오브젝트가 회전한 상태일지라도 위와 같은 코드에서는 월드의 y축을

//기준으로 회전하는것을 볼 수 있다.


※덧셈과 곱셈의 결합법칙 및 덧셈의 교환법칙을 만족시키지만 곱셈의 교환법칙은 성립하지 않는다.

※3D 그래픽에서 회전행렬 대신 사용시 짐벌락(gimbal lock)현상을 을 피할수있다.

※행렬연산에 비해 빠르다.



1. 사원수(Quaternion : 쿼터니언)란?


- 3차원 그래픽에서 회전을 표현할 때, 행렬 대신 사용하는 수학적 개념으로 4개의 값으로 이루어진 복소수(Complex Number) 체계이다.

아래 글에선 사원수와 쿼터니언을 번갈아가며 썼다.


(잠깐! 복소수란 현재 교육과정 중 가장 큰 범위의 수로 실수부와 허수부의 합으로 구성된 수이다.)


그렇다면, 사원수를 사용하는 이유는 무엇일까?


 



- 사원수는 행렬에 비해 연산 속도가 빠르고, 차지하는 메모리의 양도 적으며, 결과의 질에 있어 오류가 날 확률이 적다.


3개의 축에 대한 회전 연산을 동시에 적용하는 경우에 행렬을 사용하면 한 축이 소실되는 김벌락 현상이 발행할 수 있는데, 사원수를 사용하면 이 현상을 막을 수 있다. (미리 말해두지만, 사실 이것도 완벽하기 막지는 못한다.)



2. 사원수의 정의


- 사원수는 4차원 복소수 공간(Complex Space)의 벡터로서 다음과 같이 나타낸다.





- 사원수를 q = s + v 형태로 쓰기도 하는데, 여기서 s 는 q의 w 성분에 해당하는 스칼라(Scalar) 값이고, v는 q의 x, y, z 성분에 해당하는 벡터(Vector) 부분이다.





3. 사원수의 특징


- 사원수의 곱은 일반적인 분배법칙을 따르며 허수 성분인 i, j, k는 다음과 같은 특징을 갖는다.



(필자의 생각)

여기서 i, j, k 는 각각 x, y, z축에 대비된다고 할 수 있다. 정확히 그 축을 말하는 것이 아니라 어떠한 물체의 3축이라는 것이다. 따라서 서로 직교 하므로 ij와 ji는 교환법칙이 성립하지 않고, 역수 관계인 것이다.

또한, 서로 외적하면 다른 축을 가리킨다. 때문에 각각의 축에 대비된다고 할 수 있다.











- 사원수는 곱셈의 교환법칙이 성립하지 않는다.



위와 같은 두 사원수 q1,q2가 있을 때, 두 사원수의 곱q1q2는 다음과 같다. 




사원수를 스칼라, 벡터 형태로 표기할 때, 


 이렇게 표현할 수 있고, 두 사원수의 곱은 다음과 같다.




이는 앞에서 나온 q1,q2의 곱의 부호를 제외하고 곱했을 때 나온 값과 같다.




- 사원수는 켤레(Conjugate)를 갖는다.




- 사원수의 역수  



그리고 아래와 같은 특징을 갖는다.




- 단위 쿼터니언을 갖는다.


q = [1, (0, 0, 0)]




단위 쿼터니언은 3D 공간에서 오일러, Axis 대신 방향을 표현한다.


쿼터니언으로 방향을 표현하려면 쿼터니언을 행렬로 변환하거나, 행렬을 쿼터니언으로 변환하는 방법이 필요하다.



3. 사원수의 회전

- 축 A에 대한 각도 Θ 만큼의 회전을 사원수로 나타내면,이다.


(이것에 대한 증명 과정은 추후 업로드 할까말까...ㅠㅜ)


이 사원수로 점 P를 회전하려면 qPq-1을 하면된다.


최종적으로 얻어진 사원수를 행렬로 변환하면, 아래와 같다.






4. 사원수의 보간


보간(interpolation)이란 처음과 끝의 값을 가지고 중간에 잇는 값을 계산해 내는 것이다.

물체의 애니메이션을 수행할 때, 보간을 통해 계산된 키프레임 사이의 중간 방향을 생성한다.


가장 간단한 보간은 선형보간(linear interpolation)으로 두 개의 값을 점으로 생각하고 두 개의 점을 이어주는 직선의 방정식으로부터 값을 얻어내는 방법이다.

두 사원수 q1,q2에 대해, 선형 보간된 사원수 q(t)는 다음과 같다.



이런 사원수는 정규화 해줘야 한다. 이 함수 q(t)는 q1과 q2사이의 호를 따라간다.



그림은 2차원 단면이나, 실제로는 4차원 단위 초구면 상의 경로를 따라간다.


이러한 선형 보간은 간단하고, 효과적이나 호를 일정한 비율로 추적하지 않는다는 문제가 있다.


여기에서 구면 선형보간(spherical linear interpolation : slerp)이 나타났다.


일단 유도과정은 생략하고 보면 다음과 같다.









Ex

특정 RectTransform 안에 있는 오브젝트를 마우스위치로 이동시키고자할때

 if (RectTransformUtility.ScreenPointToLocalPointInRectangle(

            this.transform.parent.GetComponent<RectTransform>(),

            new Vector2(Input.mousePosition.x, Input.mousePosition.y),

            parentCanvase.worldCamera,

            out pos))

        {

            this.transform.localPosition = pos;


        }else

        {


        }



RectTransformUtility.ScreenPointToLocalPointInRectangle

public static bool ScreenPointToLocalPointInRectangle(RectTransform rectVector2 screenPointCamera cam, outVector2 localPoint);

Parameters

rectThe RectTransform to find a point inside.
camThe camera associated with the screen space position.
screenPointScreen space position.
localPointPoint in local space of the rect transform.

Returns

bool Returns true if the plane of the RectTransform is hit, regardless of whether the point is inside the rectangle.

Description

Transform a screen space point to a position in the local space of a RectTransform that is on the plane of its rectangle.

The cam parameter should be the camera associated with the screen point. For a RectTransform in a Canvas set to Screen Space - Overlay mode, the cam parameter should be null.

When ScreenPointToLocalPointInRectangle is used from within an event handler that provides a PointerEventData object, the correct camera can be obtained by using PointerEventData.enterEventData (for hover functionality) orPointerEventData.pressEventCamera (for click functionality). This will automatically use the correct camera (or null) for the given event.

출처:

http://docs.unity3d.com/ScriptReference/RectTransformUtility.ScreenPointToLocalPointInRectangle.html

public void writeStringToFile( string str, string filename )
{
#if !WEB_BUILD
string path = pathForDocumentsFile( filename );
FileStream file = new FileStream (path, FileMode.Create, FileAccess.Write);

StreamWriter sw = new StreamWriter( file );
sw.WriteLine( str );

sw.Close();
file.Close();
#endif 
}


public string readStringFromFile( string filename)//, int lineIndex )
{
#if !WEB_BUILD
string path = pathForDocumentsFile( filename );

if (File.Exists(path))
{
FileStream file = new FileStream (path, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader( file );

string str = null;
str = sr.ReadLine ();

sr.Close();
file.Close();

return str;
}

else
{
return null;
}
#else
return null;
#endif 
}

public string pathForDocumentsFile( string filename ) 

if (Application.platform == RuntimePlatform.IPhonePlayer)
{
string path = Application.dataPath.Substring( 0, Application.dataPath.Length - 5 );
path = path.Substring( 0, path.LastIndexOf( '/' ) );
return Path.Combine( Path.Combine( path, "Documents" ), filename );
}

else if(Application.platform == RuntimePlatform.Android)
{
string path = Application.persistentDataPath; 
path = path.Substring(0, path.LastIndexOf( '/' ) ); 
return Path.Combine (path, filename);


else 
{
string path = Application.dataPath; 
path = path.Substring(0, path.LastIndexOf( '/' ) );
return Path.Combine (path, filename);
}
}


출처::http://blog.naver.com/nameisljk/110157303742


SetBkMode(hdc, TRANSPARENT);  //

TextOut ...... 

이런식으로 먼저 하면 된다.


TRANSPARENT 대신에  OPAQUE  사용하면  (OPAQUE 가 디폴트)

SetBkColor 로 선택한 색상이 배경으로 나온다.


출처:http://soen.kr/lecture/win32api/reference/Function/SetBkMode.htm

'부스러기 > WINAPI' 카테고리의 다른 글

더블버퍼링  (0) 2015.05.19

      HCD  hdc = BeginPaint(hWnd, &ps);

HDC backMemDC, MemDC;

static HBITMAP backBitmap = NULL;

HBITMAP  hMyBitmap, hOldBitmap;

RECT crt;

GetClientRect(hWnd, &crt);


MemDC = CreateCompatibleDC(hdc);

hMyBitmap = CreateCompatibleBitmap(hdc, crt.right, crt.bottom);

hOldBitmap = (HBITMAP)SelectObject(MemDC, hMyBitmap);

FillRect(MemDC, &crt, (HBRUSH)GetStockObject(WHITE_BRUSH));


///// 화면 처리작업을 전부 MemDC 쪽으로 한다.

this->render(MemDC);


BitBlt(hdc, 0, 0, crt.right, crt.bottom, MemDC, 0, 0, SRCCOPY);

DeleteObject(SelectObject(MemDC, hOldBitmap));

DeleteDC(MemDC);

EndPaint(hWnd, &ps);




!!! 화면 지우는 작업을 못 해게 해준다. !!

case WM_ERASEBKGND:

return 0;


'부스러기 > WINAPI' 카테고리의 다른 글

TextOut 사용시 배경색없애는 방법  (0) 2015.05.19

Dex Loader] Unable to execute dex: GC overhead limit exceeded


이클립스 내에  eclipse.ini 파일을 열어서 밑에와 같이 수정해보자.

openFile
--launcher.XXMaxPermSize
512M
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
512m
--launcher.defaultAction
openFile
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms512m
-Xmx1024m

출처:http://stackoverflow.com/questions/9471194/unable-to-execute-dex-gc-overhead-limit-exceeded

'부스러기 > Java' 카테고리의 다른 글

java dom 파서로 xml 파싱 중 #text 처리  (0) 2019.04.01
Static 키워드  (0) 2017.06.12
JAVA mysql 사용  (0) 2013.07.12


리눅스 기반의 다양한 프로젝트를 동시에 진행하는데있어 관리가 쉽고 간편한 방법으로 가상머신을 사용하는 것이다. 특히 기초적인 필수프로그램을 설치해 놓은 이미지를 보관하고 있으면 다른 프로젝트를 쉽게 생성해낼 수 있다. 파티션에 할당된 크기가 아닌 실제로 저장된 파일만으로 가상 이미지의 크기가 결정되기 떄문에 백업에 대한 부담이 전혀 없다. 그래서 개인적으로 좋아하는 fedora를 설치해 놓고 이를 파일로 저장한다. - fedora_init.vdi로. 


이를 사용하려면 가상머신을 새로 만들고, 기존 이미지를 불러와서 사용하면 된다. 하지만 바로 백업파일을 불러오면 위와같은 오류가 발생하게 된다. 


하드 디스크 D:\VMs\fedora\fedora_back.vdi을(를) 여는 데 실패했습니다.


Cannot register the hard disk 'D:\VMs\fedora\fedora_back.vdi' {47f2a95a-6e91-4e7b-bfab-39b4a4728f3f} because a hard disk 'D:\VMs\fedora\fedora.vdi' with UUID {47f2a95a-6e91-4e7b-bfab-39b4a4728f3f} already exists.


결과 코드: E_INVALIDARG (0x80070057)

구성 요소: VirtualBox

인터페이스: IVirtualBox {3b2f08eb-b810-4715-bee0-bb06b9880ad2}

호출자 RC: VBOX_E_OBJECT_NOT_FOUND (0x80BB0001)

VirtualBox – Cannot Register the Hard Drive Because a Hard Drive with UUID Already Exists 라는 글에서 답을 찾을 수 있었는데, 간단히 하자면 명령 프롴프트 창(cmd)에서 아래 명령을 입력하면 된다. 

VBOXMANAGE.EXE internalcommands sethduuid <PathOfNewVHD>


예를 들어. fedora_back.vdi라는 파일이 있을 경우 다음과 같은 경우를 생각해볼 수 있다.

"C:\Program Files\Oracle\VirtualBox\VBOXMANAGE.EXE" internalcommands sethduuid D:\VMs\fedora\fedora_back.vdi

명령 실행 후 몇초 후면 'UUID changed to: 595dcc05-3800-4b3a-bfbe-9451b733b76c'라는 식의 메시지가 나오게 될것이다. 



만약, 아래와 같은 오류메시지가 출력될때를 위해,

VBoxManage.exe: error: Failed to create the VirtualBox object!

VBoxManage.exe: error: Code CO_E_SERVER_EXEC_FAILURE (0x80080005) - Server execution failed (extended info not available)

VBoxManage.exe: error: Most likely, the VirtualBox COM server is not running or failed to start.


'VirtuaBox 공유폴더 사용시 Read-only file system 해결하기' 페이지에서 기록했던 부분을 인용해본다.


그리고 여기서 끝나지 않았을 경우가 있다! 위 과정을 마치고 프로그램을 실행시키려고 하면 'Failed to create the VirtualBox COM object. The application will now terminate.' 오류가 발생할 수 있다. 아무래도 관리자 권한으로 실행하는 경우 기존 계정과 설정상에 충돌이 일어나는듯 한데(추측) 이 역시 간단하게 해결할 수 있다. 기존 계정의 .VirtualBox 폴더를 제거하면 이 폴더가 다시 생성되면서 오류가 해결된다. 즉, 윈7에서 USER라는 계정을 사용한다면 C:\Users\USER\.VirtualBox 에서 이 폴더를 찾아 제거하면 된다. 이떄의 문제는 VirtualBox상에서 설정했던 사항들(언어 설정이나 가상장치 기록등)이 사라질 수 있다는것인데 뭐 그것쯤은...


출처:http://frontjang.info/516





TableLayout 속성에
 android:stretchcolumns="0,1,2"

를 추가시킵니다
위 내용은 첫번째,두번째, 세번째 칼럼에 남는 여분의 사이즈를 준다는 의미 

 
하지만, 여기서 컬럼이 아니라 Row(세로)의 크기를 똑같이 주고자 할경우

TableRow 속성에 각각
android:layout_weight = "1" 

주세요. 

위 내용은 만약 TableRow가 5개 있을 경우
전체 TableLayout의 전체 높이에 1/5을 사용한다는 말입니다.


1. 키보드 감추기

EditText editText = (EditText) findViewById(R.id.myEdit);
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);

2. 키보드 보여주기
EditText editText = (EditText) findViewById(R.id.myEdit);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED);

위 코드로 안보이는 경우 아래코드도 시도해보세요
- imm.showSoftInputFromInputMethod (editText .getApplicationWindowToken(),InputMethodManager.SHOW_FORCED);

onCreate등에서 제대로 동작하지 않는다면 
Handler로 post를 해서 위 코드를 실행시켜보세요.

3. 키보드 토글 - 위 두가지 방법으로 안되는 경우 다음과 같은 코드로 동작하는 경우가 있습니다.
imm.toggleSoftInputFromWindow(editText.getApplicationWindowToken(),  InputMethodManager.SHOW_FORCED, 0); 

4. 액티비티 시작시 자동으로 키보드 보여주기
AndroidManifest.xml의 activity 태그의 속성에 android:windowSoftInputMode="stateVisible" 혹은 "stateAlwaysVisible"삽입

5. 액티비티 시작시 자동으로 키보드 보여주지 않기
AndroidManifest.xml의 activity 태그의 속성에 android:windowSoftInputMode="stateHidden" 혹은 "stateAlwaysHidden" 삽입

6. 에디트 텍스트 선택해도 키보드 안뜨게 하기
EditText xml 속성에서 inputType 을 0으로 주면 안뜹니다.

+ Recent posts