'Transform LookAt'에 해당되는 글 1건

  1. 2012.02.09 Script Controller - Transform으로 LookAt 만들기


Script Controller - LookAt 만들기

rotation.controller = Script Controller

self = 자신
tagObj = LooKAt Target
Box = UpAxis Object

-- Z축의 vector를 받아옴
upAxis = box.transform.row3

-- Target을 바라볼 축의 기본 vector
xAxis = normalize ( tagObj.pos - self.pos)

-- upAxis 와 xAxis를 외적해 새로운 축 vector를 만든다.(일종의 Dummy 축을 생성한다.)
yAxis = normalize (cross upAxis xAxis)  -- upAxis에 Scale이 들어있어서 normalize를 해야함.

-- xAxis(Target을 보는 축)과 yAxis를 이용하여 필요한 Up축을 생성한다.
zAxis = cross xAxis yAxis

-- x, y, zAxis를 이용해 Matrix를 생성한다.
-- 이 때, [xAxis.x, yAxis.x, zAxis.x] ..... 형태로 생성하고, 이것은 Local Axis->World Axis로 간다.
-- Matrix이므로, 그것의 inverse를 차용하여 World Axis->Local Axis로 가는 Matrix를 얻고, 이는 다음과 같다.
-- Transform은 방향 vector 3개와 Position(world)으로 이루어 진다.
matrix3 [xAxis.x, xAxis.y, xAxis.z] [yAxis.x, yAxis.y, yAxis.z] [zAxis .x, zAxis .y, zAxis .z] self.pos

 

Posted by Hwanggoon
,