{"_id":"3d-camera-core","_rev":"4-07e65f716c72b9207d7863ea73353c6a","name":"3d-camera-core","description":"An interface for 3D cameras","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"3d-camera-core","version":"1.0.0","description":"An interface for 3D cameras","main":"camera.js","directories":{"test":"test"},"dependencies":{"dup":"^1.0.0","gl-mat4":"^1.0.2"},"devDependencies":{"tape":"^3.5.0"},"scripts":{"test":"tape test/*.js"},"repository":{"type":"git","url":"https://github.com/mikolalysenko/3d-camera-core.git"},"keywords":["camera","3d","webgl","interface"],"author":{"name":"Mikola Lysenko"},"license":"MIT","bugs":{"url":"https://github.com/mikolalysenko/3d-camera-core/issues"},"homepage":"https://github.com/mikolalysenko/3d-camera-core","gitHead":"4d7ae75be679c04affaa6ac0589acb754276efba","_id":"3d-camera-core@1.0.0","_shasum":"c3c000ba87fccf3f60435c480d87de57f722eb1c","_from":".","_npmVersion":"2.1.4","_nodeVersion":"0.10.26","_npmUser":{"name":"mikolalysenko","email":"mikolalysenko@gmail.com"},"maintainers":[{"name":"mikolalysenko","email":"mikolalysenko@gmail.com"}],"dist":{"shasum":"c3c000ba87fccf3f60435c480d87de57f722eb1c","tarball":"https://registry.npmjs.org/3d-camera-core/-/3d-camera-core-1.0.0.tgz","integrity":"sha512-ECu7FoM9J6ieyVwS82PVidYTayItmmtRQcrQwgtJijbhOEd0oVAb1EFDwl/4uWYQ+cenU6LoSqVWGAVTZAg3Pw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAcFgQFg6L0w3ejzkN63xzEfbeLduGgBU4HzrNRqjRbVAiBFBkJ+U4HBhsYVv6vTqab/92ErXnFY7KpvUTzqmU7OTw=="}]}}},"readme":"3d-camera-core\n==============\nA 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.\n\n### Notes on coordinates\n\nBy convention, we will define 4 different 3 dimensional projective homogeneous coordinate systems:\n\n* **Data coordinates**: The coordinates used by models and 3D data\n* **World coordinates**: A common coordinate system for all objects within the scene\n* **Camera coordinates**: The coordinate system in the world where the camera is at the center\n* **Clip coordinates**: The device clip coordinate system\n\nThese coordinates are related by a set of three homogeneous 4x4 matrices:\n\n* **Model matrix**: Maps data coordinates to world coordinates\n* **View matrix**: Maps world coordinates to camera coordinates\n* **Projection matrix**: Maps view coordinates to device clip coordinates\n\nThe 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.\n\n# User side\n\nFor most users of this module, you only need to worry about the stuff in this section.\n\n## User example\n\n```javascript\n//You should call some other module to create a camera controller\nvar myCamera = createCameraType()\n\n//Once you have a camera, then you can access the coordinate conversions directly\nvar dataToClip = myCamera.data.toClip\n\n//You can also access the origin of the camera in any coordinate system too\nvar eyePosition = myCamera.world.origin\n```\n\n## User API\n\nThe 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.\n\n### Coordinate system conversions\n\nThe most basic function of this module is to provide a convenient syntax for getting whatever camera transformations you need.\n\n#### `coords.toClip`\nA 4x4 matrix representing the conversion from `coords` into clip coordinates.\n\n#### `coords.toCamera`\nA 4x4 matrix representing the conversion from `coords` into camera coordinates.\n\n#### `coords.toWorld`\nA 4x4 matrix representing the conversion from `coords` into world coordinates\n\n#### `coords.toData`\nA 4x4 matrix representing the conversion from `coords` into data coordinates.\n\n### Origin\n\n#### `coords.origin`\n\nThe position of the camera in the coordinate system.\n\n# For implementors\n\nA 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.\n\n## Implementation example\n\n```javascript\nvar createCamera = require('3d-camera-core')\n\n//A simple implementation of a camera controller\nfunction simpleController() {\n  var data = [1,0,0,0,\n              0,1,0,0,\n              0,0,1,0,\n              0,0,0,1]\n  var isDirty = false\n  return {\n    dirty: function() {\n      return isDirty\n    },\n    get: function(m) {\n      isDirty = false\n      for(var i=0; i<16; ++i) {\n        m[i] = data[i]\n      }\n    },\n    set: function(m) {\n      isDirty = true\n      for(var i=0; i<16; ++i) {\n        data[i] = m[i]\n      }\n    }\n  }\n}\n\n//Create a set of controllers for the camera object\nvar controllers = {\n  model: simpleController(),\n  view: simpleController(),\n  projection: simpleController()\n}\n\n//Return camera\nvar camera = createCamera(controllers)\n```\n\n## Implementor API\n\n### Constructor\n\n#### `var camera = createCamera(controllers)`\n\nThis creates a new camera object with the given controllers.  `controllers` is an object with the following properties:\n\n* `controllers.model` a controller for the model matrix\n* `controllers.view` a controller for view matrix\n* `controllers.projection` a controller for the projection matrix\n\n**Returns** A new camera object\n\n### Controller interface\n\nEach controller is an object which provides two methods:\n\n#### `controller.dirty()`\nThis 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.\n\n**Returns** `true` if the camera matrix has changed, otherwise `false`\n\n#### `controller.get(matrix)`\nThis retrieves the state of the controller's matrix.  The result should be written into `matrix`\n\n### Methods\n\n#### `camera.setController(matrix, controller)`\n\nReplaces the controller on the camera for `matrix` with `controller`.\n\n* `matrix` is the name of the matrix, which is either `model`, `view` or `projection`\n* `controller` is the new controller for the matrix\n\n# Legal\n\n(c) 2015 Mikola Lysenko.  MIT License","maintainers":[{"name":"mikolalysenko","email":"mikolalysenko@gmail.com"}],"time":{"modified":"2022-06-12T14:07:18.720Z","created":"2015-02-02T15:07:02.121Z","1.0.0":"2015-02-02T15:07:02.121Z"},"homepage":"https://github.com/mikolalysenko/3d-camera-core","keywords":["camera","3d","webgl","interface"],"repository":{"type":"git","url":"https://github.com/mikolalysenko/3d-camera-core.git"},"author":{"name":"Mikola Lysenko"},"bugs":{"url":"https://github.com/mikolalysenko/3d-camera-core/issues"},"license":"MIT","readmeFilename":"README.md"}