Skip to content

Commit 851775a

Browse files
committed
New MeshCamera class
1 parent 8ff008b commit 851775a

1 file changed

Lines changed: 159 additions & 0 deletions

File tree

src/gameobjects/mesh/MeshCamera.js

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2020 Photon Storm Ltd.
4+
* @license {@link https://opensource.org/licenses/MIT|MIT License}
5+
*/
6+
7+
var Class = require('../../utils/Class');
8+
var DegToRad = require('../../math/DegToRad');
9+
var Matrix4 = require('../../math/Matrix4');
10+
var Vector3 = require('../../math/Vector3');
11+
12+
/**
13+
* @classdesc
14+
* A Model Game Object.
15+
*
16+
* @class Model
17+
* @memberof Phaser.Geom.Mesh
18+
* @constructor
19+
* @since 3.50.0
20+
*/
21+
var MeshCamera = new Class({
22+
23+
initialize:
24+
25+
function MeshCamera (fov, x, y, z, near, far)
26+
{
27+
this.dirty = true;
28+
this.aspectRatio = 1;
29+
30+
this._fov = fov;
31+
this._near = near;
32+
this._far = far;
33+
34+
this._position = new Vector3(x, y, z);
35+
this._target = new Vector3();
36+
37+
this.viewMatrix = new Matrix4();
38+
this.projectionMatrix = new Matrix4();
39+
},
40+
41+
update: function (width, height)
42+
{
43+
this.aspectRatio = width / height;
44+
45+
this.viewMatrix.lookAt(this._position, this._target, Vector3.UP);
46+
47+
this.projectionMatrix.perspective(DegToRad(this._fov), this.aspectRatio, this._near, this._far);
48+
},
49+
50+
fov: {
51+
52+
get: function ()
53+
{
54+
return this._fov;
55+
},
56+
57+
set: function (value)
58+
{
59+
if (value > 0 && value < 180)
60+
{
61+
this._fov = value;
62+
this.dirty = true;
63+
}
64+
}
65+
66+
},
67+
68+
near: {
69+
70+
get: function ()
71+
{
72+
return this._near;
73+
},
74+
75+
set: function (value)
76+
{
77+
if (value > 0)
78+
{
79+
this._near = value;
80+
this.dirty = true;
81+
}
82+
}
83+
84+
},
85+
86+
far: {
87+
88+
get: function ()
89+
{
90+
return this._far;
91+
},
92+
93+
set: function (value)
94+
{
95+
if (value > 0)
96+
{
97+
this._far = value;
98+
this.dirty = true;
99+
}
100+
}
101+
102+
},
103+
104+
x: {
105+
106+
get: function ()
107+
{
108+
return this._position.x;
109+
},
110+
111+
set: function (value)
112+
{
113+
this._position.x = value;
114+
this.dirty = true;
115+
}
116+
117+
},
118+
119+
y: {
120+
121+
get: function ()
122+
{
123+
return this._position.y;
124+
},
125+
126+
set: function (value)
127+
{
128+
this._position.y = value;
129+
this.dirty = true;
130+
}
131+
132+
},
133+
134+
z: {
135+
136+
get: function ()
137+
{
138+
return this._position.z;
139+
},
140+
141+
set: function (value)
142+
{
143+
this._position.z = value;
144+
this.dirty = true;
145+
}
146+
147+
},
148+
149+
destroy: function ()
150+
{
151+
this._position = null;
152+
this._target = null;
153+
this.viewMatrix = null;
154+
this.projectionMatrix = null;
155+
}
156+
157+
});
158+
159+
module.exports = MeshCamera;

0 commit comments

Comments
 (0)