Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
planetis-m committed Nov 23, 2024
1 parent e7a0a58 commit cb979af
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
17 changes: 17 additions & 0 deletions manual/config_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,23 @@ MOUSE_CURSOR_

The prefixes are removed in the order they appear.

#### TypePrefixes

Type-specific prefixing is an adopted convention in C programming for organizing
functions that operate on a particular data structure.

```ini
[TypePrefixes]
Float
Vector2
Vector3
Vector4
Matrix
Quaternion
```

The prefixes are removed from function names.

### Misc

#### KeepNamespacePrefix
Expand Down
2 changes: 1 addition & 1 deletion src/raymath.nim
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func equals*(p: Quaternion, q: Quaternion): int32 {.importc: "QuaternionEquals".
func decompose*(mat: Matrix, translation: out Vector3, rotation: out Quaternion, scale: out Vector3) {.importc: "MatrixDecompose".}
{.pop.}

# template `=~`*[T: float32|Vector2|Vector3|Vector4|Quaternion](v1, v2: T): bool = equals(v1, v2)
template `=~`*[T: float32|Vector2|Vector3|Vector4|Quaternion](v1, v2: T): bool = equals(v1, v2)

template `+`*[T: Vector2|Vector3|Vector4|Quaternion|Matrix](v1, v2: T): T = add(v1, v2)
template `+=`*[T: Vector2|Vector3|Vector4|Quaternion|Matrix](v1: var T, v2: T) = v1 = add(v1, v2)
Expand Down
20 changes: 10 additions & 10 deletions src/rcamera.nim
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ func getCameraUp*(camera: Camera): Vector3 =

func getCameraRight*(camera: Camera): Vector3 =
## Returns the camera's right vector (normalized)
let forward = getForward(camera)
let up = getUp(camera)
let forward = getCameraForward(camera)
let up = getCameraUp(camera)
normalize(crossProduct(forward, up))

func moveForward*(camera: var Camera, distance: float32, moveInWorldPlane: bool) =
## Moves the camera in its forward direction
var forward = getForward(camera)
var forward = getCameraForward(camera)

if moveInWorldPlane:
# Project vector onto world plane
Expand All @@ -57,7 +57,7 @@ func moveForward*(camera: var Camera, distance: float32, moveInWorldPlane: bool)

func moveUp*(camera: var Camera, distance: float32) =
## Moves the camera in its up direction
var up = getUp(camera)
var up = getCameraUp(camera)

# Scale by distance
up *= distance
Expand All @@ -68,7 +68,7 @@ func moveUp*(camera: var Camera, distance: float32) =

func moveRight*(camera: var Camera, distance: float32, moveInWorldPlane: bool) =
## Moves the camera target in its current right direction
var right = getRight(camera)
var right = getCameraRight(camera)

if moveInWorldPlane:
# Project vector onto world plane
Expand All @@ -93,7 +93,7 @@ func moveToTarget*(camera: var Camera, delta: float32) =
if distance <= 0: distance = 0.001'f32

# Set new distance by moving the position along the forward vector
let forward = getForward(camera)
let forward = getCameraForward(camera)
camera.position = camera.target + (forward * -distance)

func yaw*(camera: var Camera, angle: float32, rotateAroundTarget: bool) =
Expand All @@ -102,7 +102,7 @@ func yaw*(camera: var Camera, angle: float32, rotateAroundTarget: bool) =
## If rotateAroundTarget is false, the camera rotates around its position
## Note: angle must be provided in radians
# Rotation axis
let up = getUp(camera)
let up = getCameraUp(camera)

# View vector
var targetPosition = camera.target - camera.position
Expand All @@ -125,7 +125,7 @@ func pitch*(camera: var Camera, angle: float32, lockView, rotateAroundTarget, ro
## NOTE: angle must be provided in radians
# Up direction
var angle = angle
let up = getUp(camera)
let up = getCameraUp(camera)

# View vector
var targetPosition = camera.target - camera.position
Expand All @@ -146,7 +146,7 @@ func pitch*(camera: var Camera, angle: float32, lockView, rotateAroundTarget, ro
if angle < maxAngleDown: angle = maxAngleDown

# Rotation axis
let right = getRight(camera)
let right = getCameraRight(camera)

# Rotate view vector around right axis
targetPosition = rotateByAxisAngle(targetPosition, right, angle)
Expand All @@ -167,7 +167,7 @@ func roll*(camera: var Camera, angle: float32) =
## Roll is "turning your head sideways to the left or right"
## Note: angle must be provided in radians
# Rotation axis
let forward = getForward(camera)
let forward = getCameraForward(camera)

# Rotate up direction around forward axis
camera.up = rotateByAxisAngle(camera.up, forward, angle)
Expand Down
2 changes: 1 addition & 1 deletion tools/wrapper/snippets/raymath_wrap.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# template `=~`*[T: float32|Vector2|Vector3|Vector4|Quaternion](v1, v2: T): bool = equals(v1, v2)
template `=~`*[T: float32|Vector2|Vector3|Vector4|Quaternion](v1, v2: T): bool = equals(v1, v2)

template `+`*[T: Vector2|Vector3|Vector4|Quaternion|Matrix](v1, v2: T): T = add(v1, v2)
template `+=`*[T: Vector2|Vector3|Vector4|Quaternion|Matrix](v1: var T, v2: T) = v1 = add(v1, v2)
Expand Down

0 comments on commit cb979af

Please sign in to comment.