undefined

8๊ฐ• ์นด๋ฉ”๋ผ

 

์นด๋ฉ”๋ผ๋Š” Camera ํด๋ž˜์Šค๋ฅผ ์ƒ์†๋ฐ›๋Š”๋‹ค. ๋‘ ๊ฐ€์ง€ ์ข…๋ฅ˜๊ฐ€ ์žˆ๋‹ค.

  • PerspectiveCamera: ์›๊ทผ๊ฐ(๊ฑฐ๋ฆฌ๊ฐ)์„ ํ‘œํ˜„ํ•œ๋‹ค.
    • ๊ฐ€๊นŒ์ด ์žˆ๋Š” ๋ฌผ์ฒด๊ฐ€ ๋ฉ€๋ฆฌ ์žˆ๋Š” ๋ฌผ์ฒด๋ณด๋‹ค ์ƒ๋Œ€์ ์œผ๋กœ ํฌ๊ฒŒ ๋ณด์ด๋„๋ก ๋ Œ๋”๋ง
  • OrthographicCamera: ์›๊ทผ๊ฐ(๊ฑฐ๋ฆฌ๊ฐ) ์—†์ด ํ‘œํ˜„ํ•œ๋‹ค.
    • ๋ฌผ์ฒด์˜ ์›๋ž˜ ํฌ๊ธฐ๋Œ€๋กœ ๋ Œ๋”๋ง๋œ๋‹ค.

์ด ๋‘๊ฐ€์ง€ ์นด๋ฉ”๋ผ์˜ ์ฐจ์ด์ ์„ ์•Œ์•„๋ณด์ž


PerspectiveCamera

์นด๋ฉ”๋ผ๋ฅผ ์ •์˜ํ•˜๊ธฐ ์œ„ํ•ด์„œ 4๊ฐœ์˜ ์ธ์ž๊ฐ’์ด ํ•„์š”

**์ ˆ๋‘์ฒด: 4๊ฐœ์˜ ๊ฐ’์„ ํ†ตํ•ด ๊ตฌ์„ฑ๋œ (์•„๋ž˜ ๊ทธ๋ฆผ์˜ ์—ฐ๋‘์ƒ‰) ์œก๋ฉด์ฒด

์ด ์ ˆ๋‘์ฒด ์•ˆ์— ์กด์žฌํ•˜๋Š” ๋ฌผ์ฒด๊ฐ€ ์นด๋ฉ”๋ผ๋ฅผ ํ†ตํ•ด ๋ณด์—ฌ์ง€๊ณ  ํ™”๋ฉด์— ๋ Œ๋”๋ง๋œ๋‹ค.

  • fovy: ์ ˆ๋‘์ฒด ๋†’์ด ๋ฐฉํ–ฅ์˜ ๊ฐ๋„ (๋‹จ์œ„: degree)
  • aspect: ์ ˆ๋‘์ฒด ๊ฐ€๋กœ ๊ธธ์ด๋ฅผ ์„ธ๋กœ ๊ธธ์ด๋กœ ๋‚˜๋ˆˆ ๋น„์œจ
  • zNear, zFar: ์นด๋ฉ”๋ผ๋กœ๋ถ€ํ„ฐ์˜ ๊ฑฐ๋ฆฌ
    • ๊ฑฐ๋ฆฌ ์‚ฌ์ด์— ์กด์žฌํ•˜๋Š” ๋ฌผ์ฒด์˜ ์ผ๋ถ€๋งŒ ๋ Œ๋”๋ง๋˜๊ณ  ์ด ์˜์—ญ์„ ๋ฒ—์–ด๋‚˜๋ฉด ๋ Œ๋”๋ง๋˜์ง€ ์•Š๋Š”๋‹ค.
const camera = new THREE.PerspectiveCamera(75, width / height, 0.1, 100);
camera.position.set(7, 7, 20); //์นด๋ฉ”๋ผ์˜ ์œ„์น˜ ์ง€์ •
camera.lookAt(0, 0, 0); // ์นด๋ฉ”๋ผ๊ฐ€ ๋ฐ”๋ผ๋ณด๋Š” ์œ„์น˜ ์ง€์ •
  • fovy๊ฐ’์€ 75๋„
  • aspect๋Š” 3์ฐจ์› ์žฅ๋ฉด์ด ๋ Œ๋”๋ง๋˜๋Š” DOM ์š”์†Œ์˜ ๊ฐ€๋กœ ์„ธ๋กœ ๋น„์œจ
      resize() {
        const width = this._divContainer.clientWidth;
        const height = this._divContainer.clientHeight;
    
        this._camera.aspect = width / height;
        this._camera.updateProjectionMatrix();
    
        this._renderer.setSize(width, height);
      }
  • ⇒ DOM ์š”์†Œ์˜ ํฌ๊ธฐ๊ฐ€ ๋ณ€๊ฒฝ๋  ๊ฒฝ์šฐ์— aspect๊ฐ’๋„ ๊ทธ ๋น„์œจ์— ๋งž๊ฒŒ ๋‹ค์‹œ ์ง€์ •ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.
  • zNear์™€ zFar ๊ฑฐ๋ฆฌ ์‚ฌ์ด์˜ ์˜์—ญ์— ์žฅ๋ฉด์˜ ๋ฌผ์ฒด๊ฐ€ ๋ชจ๋‘ ๋“ค์–ด์˜ค๊ฒŒ ์ง€์ •ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.

 

OrthographicCamera

(์•„๋ž˜ ๊ทธ๋ฆผ์—์„œ ํŒŒ๋ž€์ƒ‰) ์ •์œก๋ฉด์ฒด์ธ ์ ˆ๋‘์ฒด๋ฅผ ๊ตฌ์„ฑํ•˜๊ธฐ ์œ„ํ•ด 6๊ฐœ์˜ ๊ฐ’์ด ํ•„์š”

  • xLeft, xRight: ์œ„ ๊ทธ๋ฆผ์—์„œ ๊ฒ€์ •์ƒ‰ ์ ์„ ์›์ ์œผ๋กœ ํ–ˆ์„ ๋•Œ ์ˆ˜ํ‰์ถ•์— ๋Œ€ํ•œ ์ขŒํ‘œ๊ฐ’
  • yTop, yBottom: ๊ฒ€์ •์ƒ‰ ์ ์„ ์›์ ์œผ๋กœ ํ–ˆ์„ ๋•Œ ์ˆ˜์ง์ถ•์— ๋Œ€ํ•œ ์ขŒํ‘œ๊ฐ’
  • zNear, zFar: PerspectiveCamera์˜ ๊ฐ’๊ณผ ๋™์ผํ•œ ๊ฐ’
const aspect = window.innerWidth / window.innerHeight;
const camera = new THREE.OrthographicCamera(
  -10 * aspect, 10 * aspect,  // xLeft, xRight
  10, -10,  // yTop, yBottom
  0.1, 100  // zNear, zFar
);
camera.zoom = 10; // ํฌ๊ธฐ ์กฐ์ •
  • xLeft์™€ xRight์— aspect๋ฅผ ๊ณฑํ•˜๋Š” ์ด์œ : DOM ์š”์†Œ ํฌ๊ธฐ์— ๋Œ€ํ•œ ์ข…ํšก๋น„๋ฅผ ์ ์šฉ์‹œ์ผœ ์ž์—ฐ์Šค๋Ÿฌ์šด ๊ฒฐ๊ณผ๋ฅผ ์–ป๊ธฐ ์œ„ํ•จ
  • ⇒ PerspectiveCamera์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ DOM ์š”์†Œ์˜ ํฌ๊ธฐ๊ฐ€ ๋ณ€๊ฒฝ๋  ๊ฒฝ์šฐ์— xLeft, xRight๋ฅผ ๋‹ค์‹œ ์ง€์ •ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.
resize() {
  const width = this._divContainer.clientWidth;
  const height = this._divContainer.clientHeight;
  const aspect = width / height;
  if(this._camera instanceof THREE.PerspectiveCamera) {
    this._camera.aspect = aspect;
  } else {
        // OrthographicCamera
    this._camera.left = -10 * aspect;
    this._camera.right = 10 * aspect;
  }

  this._camera.updateProjectionMatrix();

  this._renderer.setSize(width, height);
}

 

์นด๋ฉ”๋ผ๊ฐ€ ํŠน์ • ๊ฐ์ฒด๋ฅผ ๋”ฐ๋ผ๊ฐ€๋„๋ก ๋งŒ๋“ค๊ธฐ

update ํ•จ์ˆ˜(๋ Œ๋”๋ง ์‹œ๊ฐ„๋™์•ˆ ๊ณ„์† ํ˜ธ์ถœ๋˜๋Š” ํ•จ์ˆ˜)์—์„œ ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•˜๋ฉด ์นด๋ฉ”๋ผ์˜ ์œ„์น˜๊ฐ€ smallSphere ๊ฐ์ฒด์˜ ์œ„์น˜๋กœ ์—…๋ฐ์ดํŠธ ๋œ๋‹ค.

const smallSphere = smallShperePivot.children[0];
smallSphere.getWorldPosition(this._camera.position);

 

PerspectiveCamera์™€ OrthographicCamera์˜ ์ฐจ์ด์  ๋น„๊ต

์นด๋ฉ”๋ผ๊ฐ€ ๋นจ๊ฐ„์ƒ‰ ๊ตฌ์˜ ๋’ค์ชฝ์„ ๋”ฐ๋ผ๊ฐ€๋„๋ก ์„ค์ •ํ•˜๋ฉด ๋‘˜์˜ ์ฐจ์ด์ ์„ ํ™•์‹คํžˆ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

PerspectiveCamera
OrthographicCamera