瀏覽代碼

Add class Ray

customisations
alemart 10 月之前
父節點
當前提交
cc97c1bdbc
共有 3 個文件被更改,包括 85 次插入0 次删除
  1. 19
    0
      docs/api/ray.md
  2. 1
    0
      mkdocs.yml
  3. 65
    0
      src/geometry/ray.ts

+ 19
- 0
docs/api/ray.md 查看文件

@@ -0,0 +1,19 @@
1
+# Ray
2
+
3
+A ray with origin and direction.
4
+
5
+*Since:* 0.4.0
6
+
7
+## Properties
8
+
9
+### origin
10
+
11
+`ray.origin: Vector3`
12
+
13
+The origin point of the ray.
14
+
15
+### direction
16
+
17
+`ray.direction: Vector3`
18
+
19
+The direction of the ray, a unit vector.

+ 1
- 0
mkdocs.yml 查看文件

@@ -103,6 +103,7 @@ nav:
103 103
       - 'Vector2': 'api/vector2.md'
104 104
       - 'Vector3': 'api/vector3.md'
105 105
       - 'Quaternion': 'api/quaternion.md'
106
+      - 'Ray': 'api/ray.md'
106 107
     - 'Visualization':
107 108
       - 'Viewport': 'api/viewport.md'
108 109
       - 'HUD': 'api/hud.md'

+ 65
- 0
src/geometry/ray.ts 查看文件

@@ -0,0 +1,65 @@
1
+/*
2
+ * encantar.js
3
+ * GPU-accelerated Augmented Reality for the web
4
+ * Copyright (C) 2022-2024 Alexandre Martins <alemartf(at)gmail.com>
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU Lesser General Public License as published
8
+ * by the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public License
17
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
18
+ *
19
+ * ray.ts
20
+ * Rays
21
+ */
22
+
23
+import { Vector3 } from './vector3';
24
+
25
+
26
+/**
27
+ * A ray with origin and direction
28
+ */
29
+export class Ray
30
+{
31
+    /** origin of the ray, a point */
32
+    private _origin: Vector3;
33
+
34
+    /** direction, a unit vector */
35
+    private _direction: Vector3;
36
+
37
+
38
+
39
+    /**
40
+     * Constructor
41
+     * @param origin a point
42
+     * @param direction a unit vector
43
+     */
44
+    constructor(origin: Vector3, direction: Vector3)
45
+    {
46
+        this._origin = origin;
47
+        this._direction = direction;
48
+    }
49
+
50
+    /**
51
+     * The origin point of the ray
52
+     */
53
+    get origin(): Vector3
54
+    {
55
+        return this._origin;
56
+    }
57
+
58
+    /**
59
+     * The direction of the ray, a unit vector
60
+     */
61
+    get direction(): Vector3
62
+    {
63
+        return this._direction;
64
+    }
65
+}

Loading…
取消
儲存