BrawlCrate v0.41
Wii File Editor
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Properties | Events | List of all members
BrawlLib.OpenGL.GLCamera Class Reference

Public Member Functions

void SetProjectionParams (float aspect, float fovy, float farz, float nearz)
 
 GLCamera ()
 
 GLCamera (float width, float height, Vector3 defaultTranslate, Vector3 defaultRotate, Vector3 defaultScale)
 
Vector3 GetPoint ()
 
void Scale (float x, float y, float z)
 
void Scale (Vector3 v)
 
void Zoom (float amt)
 
void Translate (Vector3 v)
 
void Translate (float x, float y, float z)
 
void Rotate (float x, float y, float z)
 
void Rotate (Vector3 v)
 
void Rotate (float x, float y)
 
void Pivot (float radius, float x, float y)
 
void Set (Vector3 translate, Vector3 rotate, Vector3 scale)
 
void Reset ()
 
void CalculateProjection ()
 
void SetDimensions (float width, float height)
 
Vector3 UnProject (Vector3 point)
 Projects a screen point to world coordinates. More...
 
Vector3 UnProject (float x, float y, float z)
 Projects a screen point to world coordinates. More...
 
Vector3 Project (float x, float y, float z)
 Projects a world point to screen coordinates. More...
 
Vector3 Project (Vector3 source)
 Projects a world point to screen coordinates. More...
 
Vector3 ProjectCameraSphere (Vector2 screenPoint, Vector3 center, float radius, bool clamp)
 
void ProjectCameraPlanes (Vector2 screenPoint, Matrix transform, out Vector3 xy, out Vector3 yz, out Vector3 xz)
 
void LoadProjection ()
 
void LoadModelView ()
 
void ZoomExtents (Vector3 point, float distance)
 
void SaveDefaults ()
 

Public Attributes

Matrix _matrix
 
Matrix _matrixInverse
 
Matrix _projectionMatrix
 
Matrix _projectionInverse
 
Vector3 _rotation
 
Vector3 _scale
 
bool _ortho
 
bool _restrictXRot
 
bool _restrictYRot
 
bool _restrictZRot
 
float _fovY = 45.0f
 
float _nearZ = 1.0f
 
float _farZ = 200000.0f
 
float _width = 1
 
float _height = 1
 
float _aspect = 1
 
Vector4 _orthoDimensions = new Vector4(0, 1, 0, 1)
 
Vector3 _defaultTranslate
 
Vector3 _defaultRotate
 
Vector3 _defaultScale = new Vector3(1)
 
Action OnPositionChanged
 

Properties

float VerticalFieldOfView [get, set]
 
float NearDepth [get, set]
 
float FarDepth [get, set]
 
float Width [get, set]
 
float Height [get, set]
 
float Aspect [get, set]
 
bool Orthographic [get, set]
 

Events

Action OnDimensionsChanged
 

Constructor & Destructor Documentation

◆ GLCamera() [1/2]

BrawlLib.OpenGL.GLCamera.GLCamera ( )
inline
119 {
120 Reset();
121 }
void Reset()
Definition: GLCamera.cs:252

◆ GLCamera() [2/2]

BrawlLib.OpenGL.GLCamera.GLCamera ( float  width,
float  height,
Vector3  defaultTranslate,
Vector3  defaultRotate,
Vector3  defaultScale 
)
inline
125 {
126 _width = width;
127 _height = height;
128
129 _orthoDimensions = new Vector4(-_width / 2.0f, _width / 2.0f, _height / 2.0f, -_height / 2.0f);
130
131 _scale = _defaultScale = defaultScale;
132 _rotation = _defaultRotate = defaultRotate;
133 _defaultTranslate = defaultTranslate;
134
137 }
Vector4 _orthoDimensions
Definition: GLCamera.cs:27
Vector3 _scale
Definition: GLCamera.cs:15
Matrix _matrix
Definition: GLCamera.cs:9
Matrix _matrixInverse
Definition: GLCamera.cs:10
float _height
Definition: GLCamera.cs:24
Vector3 _defaultScale
Definition: GLCamera.cs:31
Vector3 _rotation
Definition: GLCamera.cs:14
float _width
Definition: GLCamera.cs:23
Vector3 _defaultTranslate
Definition: GLCamera.cs:29
Vector3 _defaultRotate
Definition: GLCamera.cs:30
Definition: Matrix.cs:14
static Matrix TransformMatrix(Vector3 scale, Vector3 rotate, Vector3 translate)
Definition: Matrix.cs:1214
static Matrix ReverseTransformMatrix(Vector3 scale, Vector3 rotation, Vector3 translation)
Definition: Matrix.cs:1246
Definition: Vector4.cs:12

Member Function Documentation

◆ CalculateProjection()

void BrawlLib.OpenGL.GLCamera.CalculateProjection ( )
inline
273 {
274 if (_ortho)
275 {
278 }
279 else
280 {
283 }
284 }
Matrix _projectionMatrix
Definition: GLCamera.cs:11
float _aspect
Definition: GLCamera.cs:25
Matrix _projectionInverse
Definition: GLCamera.cs:12
float _fovY
Definition: GLCamera.cs:20
bool _ortho
Definition: GLCamera.cs:17
float _farZ
Definition: GLCamera.cs:22
float _nearZ
Definition: GLCamera.cs:21
static Matrix OrthographicMatrix(Vector4 dimensions, Vector2 depth)
Definition: Matrix.cs:1101
static Matrix ReversePerspectiveMatrix(float fovY, float aspect, float nearZ, float farZ)
Definition: Matrix.cs:1194
static Matrix PerspectiveMatrix(float fovY, float aspect, float nearZ, float farZ)
Definition: Matrix.cs:1175
static Matrix ReverseOrthographicMatrix(Vector4 dimensions, Vector2 depth)
Definition: Matrix.cs:1138

◆ GetPoint()

Vector3 BrawlLib.OpenGL.GLCamera.GetPoint ( )
inline
140 {
141 return _matrixInverse.Multiply(new Vector3());
142 }
Vector3 Multiply(Vector3 v)
Definition: Matrix.cs:541
Definition: Vector3.cs:40

◆ LoadModelView()

void BrawlLib.OpenGL.GLCamera.LoadModelView ( )
inline
401 {
402 GL.MatrixMode(MatrixMode.Modelview);
403 GL.LoadIdentity();
404 fixed (Matrix* p = &_matrix)
405 {
406 GL.LoadMatrix((float*) p);
407 }
408 }

◆ LoadProjection()

void BrawlLib.OpenGL.GLCamera.LoadProjection ( )
inline
391 {
392 GL.MatrixMode(MatrixMode.Projection);
393 GL.LoadIdentity();
394 fixed (Matrix* p = &_projectionMatrix)
395 {
396 GL.LoadMatrix((float*) p);
397 }
398 }

◆ Pivot()

void BrawlLib.OpenGL.GLCamera.Pivot ( float  radius,
float  x,
float  y 
)
inline
232 {
233 _updating = true;
234 Translate(0, 0, -radius);
235 Rotate(x, y);
236 Translate(0, 0, radius);
237 _updating = false;
238 PositionChanged();
239 }
void Rotate(float x, float y, float z)
Definition: GLCamera.cs:181
void Translate(Vector3 v)
Definition: GLCamera.cs:168

◆ Project() [1/2]

Vector3 BrawlLib.OpenGL.GLCamera.Project ( float  x,
float  y,
float  z 
)
inline

Projects a world point to screen coordinates.

Returns
2D coordinate on the screen with z as depth (z is not a distance value!)
330 {
331 return Project(new Vector3(x, y, z));
332 }
Vector3 Project(float x, float y, float z)
Projects a world point to screen coordinates.
Definition: GLCamera.cs:329

◆ Project() [2/2]

Vector3 BrawlLib.OpenGL.GLCamera.Project ( Vector3  source)
inline

Projects a world point to screen coordinates.

Returns
2D coordinate on the screen with z as depth (z is not a distance value!)
339 {
340 //This needs to be converted to a Vector4 in order to work
341 //Also the order of the matrix multiplication matters
342 Vector4 t1 = _matrix * (Vector4) source;
343 Vector4 t2 = _projectionMatrix * t1;
344 if (t2._w == 0)
345 {
346 return new Vector3();
347 }
348
349 Vector3 v = (Vector3) t2;
350 return new Vector3(
351 (v._x / 2.0f + 0.5f) * Width,
352 Height - (v._y / 2.0f + 0.5f) * Height,
353 (v._z + 1.0f) / 2.0f);
354 }
float Height
Definition: GLCamera.cs:84
float Width
Definition: GLCamera.cs:74
float _y
Definition: Vector3.cs:41
float _z
Definition: Vector3.cs:41
float _x
Definition: Vector3.cs:41

◆ ProjectCameraPlanes()

void BrawlLib.OpenGL.GLCamera.ProjectCameraPlanes ( Vector2  screenPoint,
Matrix  transform,
out Vector3  xy,
out Vector3  yz,
out Vector3  xz 
)
inline
379 {
380 Vector3 ray1 = UnProject(screenPoint._x, screenPoint._y, 0.0f);
381 Vector3 ray2 = UnProject(screenPoint._x, screenPoint._y, 1.0f);
382
383 Vector3 center = transform.GetPoint();
384
385 Maths.LinePlaneIntersect(ray1, ray2, center, (transform * Vector3.UnitX).Normalize(center), out yz);
386 Maths.LinePlaneIntersect(ray1, ray2, center, (transform * Vector3.UnitY).Normalize(center), out xz);
387 Maths.LinePlaneIntersect(ray1, ray2, center, (transform * Vector3.UnitZ).Normalize(center), out xy);
388 }
Vector3 UnProject(Vector3 point)
Projects a screen point to world coordinates.
Definition: GLCamera.cs:305
Vector3 GetPoint()
Definition: Matrix.cs:321
float _y
Definition: Vector2.cs:17
float _x
Definition: Vector2.cs:11
static readonly Vector3 UnitX
Definition: Vector3.cs:420
static readonly Vector3 UnitZ
Definition: Vector3.cs:422
static readonly Vector3 UnitY
Definition: Vector3.cs:421

◆ ProjectCameraSphere()

Vector3 BrawlLib.OpenGL.GLCamera.ProjectCameraSphere ( Vector2  screenPoint,
Vector3  center,
float  radius,
bool  clamp 
)
inline
357 {
358 //Get ray points
359 Vector3 ray1 = UnProject(screenPoint._x, screenPoint._y, 0.0f);
360 Vector3 ray2 = UnProject(screenPoint._x, screenPoint._y, 1.0f);
361
362 if (!Maths.LineSphereIntersect(ray1, ray2, center, radius, out Vector3 point))
363 {
364 //If no intersect is found, project the ray through the plane perpendicular to the camera.
365 Maths.LinePlaneIntersect(ray1, ray2, center, GetPoint().Normalize(center), out point);
366
367 //Clamp the point to edge of the sphere
368 if (clamp)
369 {
370 point = Maths.PointAtLineDistance(center, point, radius);
371 }
372 }
373
374 return point;
375 }
Vector3 GetPoint()
Definition: GLCamera.cs:139

◆ Reset()

void BrawlLib.OpenGL.GLCamera.Reset ( )
inline

◆ Rotate() [1/3]

void BrawlLib.OpenGL.GLCamera.Rotate ( float  x,
float  y 
)
inline
227 {
228 Rotate(x, y, 0);
229 }

◆ Rotate() [2/3]

void BrawlLib.OpenGL.GLCamera.Rotate ( float  x,
float  y,
float  z 
)
inline
182 {
183 Rotate(new Vector3(x, y, z));
184 }

◆ Rotate() [3/3]

void BrawlLib.OpenGL.GLCamera.Rotate ( Vector3  v)
inline
187 {
188 //Fix for left and right dragging when the camera is upside down
189 if (_rotation._x < -90.0f || _rotation._x > 90.0f)
190 {
191 v._y = -v._y;
192 }
193
194 if (_restrictXRot)
195 {
196 v._x = 0.0f;
197 }
198
199 if (_restrictYRot)
200 {
201 v._y = 0.0f;
202 }
203
204 if (_restrictZRot)
205 {
206 v._z = 0.0f;
207 }
208
209 _rotation = (_rotation + v).RemappedToRange(-180.0f, 180.0f);
210
211 Apply();
212 }
bool _restrictXRot
Definition: GLCamera.cs:17
bool _restrictYRot
Definition: GLCamera.cs:17
bool _restrictZRot
Definition: GLCamera.cs:17

◆ SaveDefaults()

void BrawlLib.OpenGL.GLCamera.SaveDefaults ( )
inline

◆ Scale() [1/2]

void BrawlLib.OpenGL.GLCamera.Scale ( float  x,
float  y,
float  z 
)
inline
145 {
146 Scale(new Vector3(x, y, z));
147 }
void Scale(float x, float y, float z)
Definition: GLCamera.cs:144

◆ Scale() [2/2]

void BrawlLib.OpenGL.GLCamera.Scale ( Vector3  v)
inline
150 {
151 _scale *= v;
152 Apply();
153 }

◆ Set()

void BrawlLib.OpenGL.GLCamera.Set ( Vector3  translate,
Vector3  rotate,
Vector3  scale 
)
inline
242 {
243 _scale = scale;
244 _rotation = rotate;
245
248
249 PositionChanged();
250 }

◆ SetDimensions()

void BrawlLib.OpenGL.GLCamera.SetDimensions ( float  width,
float  height 
)
inline
289 {
290 _width = width;
291 _height = height;
293
294 _orthoDimensions = new Vector4(-_width / 2.0f, _width / 2.0f, _height / 2.0f, -_height / 2.0f);
295
297
298 OnDimensionsChanged?.Invoke();
299 }
void CalculateProjection()
Definition: GLCamera.cs:272
Action OnDimensionsChanged
Definition: GLCamera.cs:286

◆ SetProjectionParams()

void BrawlLib.OpenGL.GLCamera.SetProjectionParams ( float  aspect,
float  fovy,
float  farz,
float  nearz 
)
inline
34 {
35 _aspect = aspect;
36 _fovY = fovy;
37 _farZ = farz;
38 _nearZ = nearz;
39
41 }

◆ Translate() [1/2]

void BrawlLib.OpenGL.GLCamera.Translate ( float  x,
float  y,
float  z 
)
inline
174 {
175 _matrix = Matrix.TranslationMatrix(-x, -y, -z) * _matrix;
176 _matrixInverse.Translate(x, y, z);
177
178 PositionChanged();
179 }
static Matrix TranslationMatrix(Vector3 v)
Definition: Matrix.cs:353
void Translate(Vector3 v)
Definition: Matrix.cs:525

◆ Translate() [2/2]

void BrawlLib.OpenGL.GLCamera.Translate ( Vector3  v)
inline
169 {
170 Translate(v._x, v._y, v._z);
171 }

◆ UnProject() [1/2]

Vector3 BrawlLib.OpenGL.GLCamera.UnProject ( float  x,
float  y,
float  z 
)
inline

Projects a screen point to world coordinates.

Returns
3D world point perpendicular to the camera with a depth value of z (z is not a distance value!)
315 {
316 //This needs to be a Vector4 converted to a Vector3 in order to work
317 //Also the order of the matrix multiplication matters
319 2.0f * (x / Width) - 1.0f,
320 2.0f * ((Height - y) / Height) - 1.0f,
321 2.0f * z - 1.0f,
322 1.0f));
323 }

◆ UnProject() [2/2]

Vector3 BrawlLib.OpenGL.GLCamera.UnProject ( Vector3  point)
inline

Projects a screen point to world coordinates.

Returns
3D world point perpendicular to the camera with a depth value of z (z is not a distance value!)
306 {
307 return UnProject(point._x, point._y, point._z);
308 }

◆ Zoom()

void BrawlLib.OpenGL.GLCamera.Zoom ( float  amt)
inline
156 {
157 if (_ortho)
158 {
159 float scale = amt >= 0 ? amt / 2.0f : 2.0f / -amt;
160 Scale(scale, scale, scale);
161 }
162 else
163 {
164 Translate(0.0f, 0.0f, amt);
165 }
166 }

◆ ZoomExtents()

void BrawlLib.OpenGL.GLCamera.ZoomExtents ( Vector3  point,
float  distance 
)
inline
411 {
412 if (!_ortho)
413 {
414 _rotation = new Vector3();
415 }
416
417 Vector3 position = point + new Vector3(0.0f, 0.0f, distance);
420 }

Member Data Documentation

◆ _aspect

float BrawlLib.OpenGL.GLCamera._aspect = 1

◆ _defaultRotate

Vector3 BrawlLib.OpenGL.GLCamera._defaultRotate

◆ _defaultScale

Vector3 BrawlLib.OpenGL.GLCamera._defaultScale = new Vector3(1)

◆ _defaultTranslate

Vector3 BrawlLib.OpenGL.GLCamera._defaultTranslate

◆ _farZ

float BrawlLib.OpenGL.GLCamera._farZ = 200000.0f

◆ _fovY

float BrawlLib.OpenGL.GLCamera._fovY = 45.0f

◆ _height

float BrawlLib.OpenGL.GLCamera._height = 1

◆ _matrix

Matrix BrawlLib.OpenGL.GLCamera._matrix

◆ _matrixInverse

Matrix BrawlLib.OpenGL.GLCamera._matrixInverse

◆ _nearZ

float BrawlLib.OpenGL.GLCamera._nearZ = 1.0f

◆ _ortho

bool BrawlLib.OpenGL.GLCamera._ortho

◆ _orthoDimensions

Vector4 BrawlLib.OpenGL.GLCamera._orthoDimensions = new Vector4(0, 1, 0, 1)

◆ _projectionInverse

Matrix BrawlLib.OpenGL.GLCamera._projectionInverse

◆ _projectionMatrix

Matrix BrawlLib.OpenGL.GLCamera._projectionMatrix

◆ _restrictXRot

bool BrawlLib.OpenGL.GLCamera._restrictXRot

◆ _restrictYRot

bool BrawlLib.OpenGL.GLCamera._restrictYRot

◆ _restrictZRot

bool BrawlLib.OpenGL.GLCamera._restrictZRot

◆ _rotation

Vector3 BrawlLib.OpenGL.GLCamera._rotation

◆ _scale

Vector3 BrawlLib.OpenGL.GLCamera._scale

◆ _width

float BrawlLib.OpenGL.GLCamera._width = 1

◆ OnPositionChanged

Action BrawlLib.OpenGL.GLCamera.OnPositionChanged

Property Documentation

◆ Aspect

float BrawlLib.OpenGL.GLCamera.Aspect
getset
94 {
95 get => _aspect;
96 set
97 {
98 _aspect = value;
100 }
101 }

◆ FarDepth

float BrawlLib.OpenGL.GLCamera.FarDepth
getset
64 {
65 get => _farZ;
66 set
67 {
68 _farZ = value;
70 }
71 }

◆ Height

float BrawlLib.OpenGL.GLCamera.Height
getset
84 {
85 get => _height;
86 set
87 {
88 _height = value;
90 }
91 }

◆ NearDepth

float BrawlLib.OpenGL.GLCamera.NearDepth
getset
54 {
55 get => _nearZ;
56 set
57 {
58 _nearZ = value;
60 }
61 }

◆ Orthographic

bool BrawlLib.OpenGL.GLCamera.Orthographic
getset
104 {
105 get => _ortho;
106 set
107 {
108 if (_ortho == value)
109 {
110 return;
111 }
112
113 _ortho = value;
115 }
116 }

◆ VerticalFieldOfView

float BrawlLib.OpenGL.GLCamera.VerticalFieldOfView
getset
44 {
45 get => _fovY;
46 set
47 {
48 _fovY = value;
50 }
51 }

◆ Width

float BrawlLib.OpenGL.GLCamera.Width
getset
74 {
75 get => _width;
76 set
77 {
78 _width = value;
80 }
81 }

Event Documentation

◆ OnDimensionsChanged

Action BrawlLib.OpenGL.GLCamera.OnDimensionsChanged

The documentation for this class was generated from the following file: