3d-camera-core 中文文档教程

发布于 10年前 浏览 23 项目主页 更新于 3年前

3d-camera-core

3D 相机的通用接口。 该模块是一个缓存层,用于维护坐标系转换并根据一组生成矩阵计算相机属性。 该模块旨在用作通用接口,不应直接需要。

Notes on coordinates

按照惯例,我们将定义 4 个不同的 3 维投影齐次坐标系:

  • Data coordinates: The coordinates used by models and 3D data
  • World coordinates: A common coordinate system for all objects within the scene
  • Camera coordinates: The coordinate system in the world where the camera is at the center
  • Clip coordinates: The device clip coordinate system

这些坐标由一组三个齐次 4x4 矩阵相关:

  • Model matrix: Maps data coordinates to world coordinates
  • View matrix: Maps world coordinates to camera coordinates
  • Projection matrix: Maps view coordinates to device clip coordinates

该模块的目标是将这些坐标系之间的关系保持为矩阵并定义标准接口对于需要消耗相机信息的可渲染对象。 实施者应该采用此模块并连接他们想要计算模型/视图/投影矩阵的任何方法,而用户则可以将生成的相机界面视为处理各种坐标系转换的黑盒。

User side

对于这个模块的大多数用户,你只需要关心这部分的东西。

User example

//You should call some other module to create a camera controller
var myCamera = createCameraType()

//Once you have a camera, then you can access the coordinate conversions directly
var dataToClip = myCamera.data.toClip

//You can also access the origin of the camera in any coordinate system too
var eyePosition = myCamera.world.origin

User API

该模块的总体目标是跟踪许多不同坐标系之间的转换。 由于乘以和重新计算这些转换的成本很高,因此该模块缓存此数据以供将来使用。 创建相机对象后,不会执行进一步的内存分配。

Coordinate system conversions

这个模块最基本的功能是提供一个方便的语法来获取你需要的任何相机转换。

coords.toClip

一个 4x4 矩阵,表示从 coords 到剪辑坐标的转换。

coords.toCamera

一个 4x4 矩阵,表示从 coords 到相机坐标的转换。

coords.toWorld

表示从 coords 到世界坐标

coords.toData

的转换的 4x4 矩阵 表示从 coords 到数据坐标的转换的 4x4 矩阵。

Origin

coords.origin

相机在坐标系中的位置。

For implementors

相机实现应该为每个模型、视图和投影矩阵提供一个或多个“控制器”。 每个控制器都是一个具有两种方法的对象; 一种用于测试控制器是否已更改,另一种用于读取控制器矩阵的状态。

Implementation example

var createCamera = require('3d-camera-core')

//A simple implementation of a camera controller
function simpleController() {
  var data = [1,0,0,0,
              0,1,0,0,
              0,0,1,0,
              0,0,0,1]
  var isDirty = false
  return {
    dirty: function() {
      return isDirty
    },
    get: function(m) {
      isDirty = false
      for(var i=0; i<16; ++i) {
        m[i] = data[i]
      }
    },
    set: function(m) {
      isDirty = true
      for(var i=0; i<16; ++i) {
        data[i] = m[i]
      }
    }
  }
}

//Create a set of controllers for the camera object
var controllers = {
  model: simpleController(),
  view: simpleController(),
  projection: simpleController()
}

//Return camera
var camera = createCamera(controllers)

Implementor API

Constructor

var camera = createCamera(controllers)

这将使用给定的控制器创建一个新的相机对象。 controllers 是一个具有以下属性的对象:

  • controllers.model a controller for the model matrix
  • controllers.view a controller for view matrix
  • controllers.projection a controller for the projection matrix

返回 一个新的相机对象

Controller interface

每个控制器都是一个提供两种方法的对象:

controller.dirty()

此方法应测试控制器的状态是否已更改自上次调用 controller.get() 以来。 如果有,则矩阵值将被重新计算。

返回 true 如果摄像机矩阵已更改,否则返回false

controller.get(matrix)

这将检索控制器矩阵的状态。 结果应写入 matrix

Methods

camera.setController(matrix, controller)

将相机上的控制器替换为 matrixcontroller

  • matrix is the name of the matrix, which is either model, view or projection
  • controller is the new controller for the matrix

Legal

(c) 2015 米科拉·李森科。 麻省理工执照

3d-camera-core

A common interface for 3D cameras. This module is a caching layer for maintaining coordinate system transformations and computing camera properties from a set of generating matrices. This module is intended to be used as a common interface and should not be required directly.

Notes on coordinates

By convention, we will define 4 different 3 dimensional projective homogeneous coordinate systems:

  • Data coordinates: The coordinates used by models and 3D data
  • World coordinates: A common coordinate system for all objects within the scene
  • Camera coordinates: The coordinate system in the world where the camera is at the center
  • Clip coordinates: The device clip coordinate system

These coordinates are related by a set of three homogeneous 4x4 matrices:

  • Model matrix: Maps data coordinates to world coordinates
  • View matrix: Maps world coordinates to camera coordinates
  • Projection matrix: Maps view coordinates to device clip coordinates

The goal of this module is to maintain the relationships between these coordinate systems as matrices and to define a standard interface for renderable objects which need to consume camera information. Implementors should take this module and hook up whatever methods they want to compute the model/view/projection matrices, while users can then treat the resulting camera interface as a black box handling the various coordinate system conversions.

User side

For most users of this module, you only need to worry about the stuff in this section.

User example

//You should call some other module to create a camera controller
var myCamera = createCameraType()

//Once you have a camera, then you can access the coordinate conversions directly
var dataToClip = myCamera.data.toClip

//You can also access the origin of the camera in any coordinate system too
var eyePosition = myCamera.world.origin

User API

The overall goal of this module is to keep track of conversions between a number of different coordinate systems. Because multiplying and recalculating these conversions is expensive, this module caches this data for future use. After a camera object has been created, no further memory allocations are performed.

Coordinate system conversions

The most basic function of this module is to provide a convenient syntax for getting whatever camera transformations you need.

coords.toClip

A 4x4 matrix representing the conversion from coords into clip coordinates.

coords.toCamera

A 4x4 matrix representing the conversion from coords into camera coordinates.

coords.toWorld

A 4x4 matrix representing the conversion from coords into world coordinates

coords.toData

A 4x4 matrix representing the conversion from coords into data coordinates.

Origin

coords.origin

The position of the camera in the coordinate system.

For implementors

A camera implementation should provide one or more "controllers" for each of the model, view and projection matrices. Each controller is an object with two methods; one which tests if the controller has changed and one which reads out the state of the matrix for the controller.

Implementation example

var createCamera = require('3d-camera-core')

//A simple implementation of a camera controller
function simpleController() {
  var data = [1,0,0,0,
              0,1,0,0,
              0,0,1,0,
              0,0,0,1]
  var isDirty = false
  return {
    dirty: function() {
      return isDirty
    },
    get: function(m) {
      isDirty = false
      for(var i=0; i<16; ++i) {
        m[i] = data[i]
      }
    },
    set: function(m) {
      isDirty = true
      for(var i=0; i<16; ++i) {
        data[i] = m[i]
      }
    }
  }
}

//Create a set of controllers for the camera object
var controllers = {
  model: simpleController(),
  view: simpleController(),
  projection: simpleController()
}

//Return camera
var camera = createCamera(controllers)

Implementor API

Constructor

var camera = createCamera(controllers)

This creates a new camera object with the given controllers. controllers is an object with the following properties:

  • controllers.model a controller for the model matrix
  • controllers.view a controller for view matrix
  • controllers.projection a controller for the projection matrix

Returns A new camera object

Controller interface

Each controller is an object which provides two methods:

controller.dirty()

This method should test if the state of the controller has changed since the last time controller.get() was called. If it has, then the matrix value will be recomputed.

Returns true if the camera matrix has changed, otherwise false

controller.get(matrix)

This retrieves the state of the controller's matrix. The result should be written into matrix

Methods

camera.setController(matrix, controller)

Replaces the controller on the camera for matrix with controller.

  • matrix is the name of the matrix, which is either model, view or projection
  • controller is the new controller for the matrix

Legal

(c) 2015 Mikola Lysenko. MIT License

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文