Added UI functionality to the Graphics System #232
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,454 @@
|
||||||
|
- EID: 0
|
||||||
|
Name: ScoreZone
|
||||||
|
IsActive: true
|
||||||
|
NumberOfChildren: 0
|
||||||
|
Components:
|
||||||
|
Camera Component:
|
||||||
|
Position: {x: 0, y: 0, z: 0}
|
||||||
|
Pitch: 0
|
||||||
|
Yaw: 0
|
||||||
|
Roll: 0
|
||||||
|
Width: 1920
|
||||||
|
Height: 1080
|
||||||
|
Near: 0.00999999978
|
||||||
|
Far: 10000
|
||||||
|
Perspective: true
|
||||||
|
IsActive: true
|
||||||
|
Light Component:
|
||||||
|
Position: {x: 0, y: 0, z: 0}
|
||||||
|
Type: Directional
|
||||||
|
Direction: {x: 1.79999995, y: 0, z: 1}
|
||||||
|
Color: {x: 0.951541841, y: 0.921719015, z: 0.553319454, w: 1}
|
||||||
|
Layer: 4294967295
|
||||||
|
Strength: 0
|
||||||
|
IsActive: true
|
||||||
|
Scripts: ~
|
||||||
|
- EID: 1
|
||||||
|
Name: Default
|
||||||
|
IsActive: true
|
||||||
|
NumberOfChildren: 0
|
||||||
|
Components:
|
||||||
|
Transform Component:
|
||||||
|
Translate: {x: -1.440328, y: -4.41369677, z: -5}
|
||||||
|
Rotate: {x: -0, y: 0, z: -0}
|
||||||
|
Scale: {x: 49.4798889, y: 0.5, z: 17.5}
|
||||||
|
IsActive: true
|
||||||
|
Renderable Component:
|
||||||
|
Mesh: 149697411
|
||||||
|
Material: 126974645
|
||||||
|
IsActive: true
|
||||||
|
RigidBody Component:
|
||||||
|
Type: Static
|
||||||
|
Mass: 1
|
||||||
|
Drag: 0.00999999978
|
||||||
|
Angular Drag: 0.00999999978
|
||||||
|
Use Gravity: true
|
||||||
|
Interpolate: true
|
||||||
|
Freeze Position X: false
|
||||||
|
Freeze Position Y: false
|
||||||
|
Freeze Position Z: false
|
||||||
|
Freeze Rotation X: false
|
||||||
|
Freeze Rotation Y: false
|
||||||
|
Freeze Rotation Z: false
|
||||||
|
IsActive: true
|
||||||
|
Collider Component:
|
||||||
|
Colliders:
|
||||||
|
- Is Trigger: false
|
||||||
|
Type: Box
|
||||||
|
Half Extents: {x: 1, y: 1, z: 1}
|
||||||
|
Friction: 0.400000006
|
||||||
|
Bounciness: 0
|
||||||
|
Density: 1
|
||||||
|
Position Offset: {x: 0, y: 0, z: 0}
|
||||||
|
IsActive: true
|
||||||
|
Scripts: ~
|
||||||
|
- EID: 2
|
||||||
|
Name: Player
|
||||||
|
IsActive: true
|
||||||
|
NumberOfChildren: 3
|
||||||
|
Components:
|
||||||
|
Transform Component:
|
||||||
|
Translate: {x: -18.9007454, y: -3.67369723, z: -5.23871422}
|
||||||
|
Rotate: {x: -0, y: 0, z: 0}
|
||||||
|
Scale: {x: 2, y: 2, z: 2}
|
||||||
|
IsActive: true
|
||||||
|
Renderable Component:
|
||||||
|
Mesh: 149697411
|
||||||
|
Material: 126974645
|
||||||
|
IsActive: true
|
||||||
|
RigidBody Component:
|
||||||
|
Type: Dynamic
|
||||||
|
Mass: 1
|
||||||
|
Drag: 2
|
||||||
|
Angular Drag: 0
|
||||||
|
Use Gravity: false
|
||||||
|
Interpolate: false
|
||||||
|
Freeze Position X: false
|
||||||
|
Freeze Position Y: false
|
||||||
|
Freeze Position Z: false
|
||||||
|
Freeze Rotation X: true
|
||||||
|
Freeze Rotation Y: true
|
||||||
|
Freeze Rotation Z: true
|
||||||
|
IsActive: true
|
||||||
|
Collider Component:
|
||||||
|
Colliders:
|
||||||
|
- Is Trigger: false
|
||||||
|
Type: Box
|
||||||
|
Half Extents: {x: 1, y: 1, z: 1}
|
||||||
|
Friction: 0.400000006
|
||||||
|
Bounciness: 0
|
||||||
|
Density: 1
|
||||||
|
Position Offset: {x: 0, y: 0.5, z: 0}
|
||||||
|
IsActive: true
|
||||||
|
Scripts:
|
||||||
|
- Type: PlayerController
|
||||||
|
currentState: 0
|
||||||
|
maxMoveVel: 4
|
||||||
|
moveForce: 50
|
||||||
|
sprintMultiplier: 1.5
|
||||||
|
rotationFactorPerFrame: 1
|
||||||
|
maxJumpHeight: 4
|
||||||
|
maxJumpTime: 0.75
|
||||||
|
fallMultipler: 2
|
||||||
|
lightMultiper: 0.75
|
||||||
|
mediumMultiper: 0.5
|
||||||
|
heavyMultiper: 0.25
|
||||||
|
- Type: PickAndThrow
|
||||||
|
holdPosition: [0, 1.20000005, 0]
|
||||||
|
throwForce: [200, 300, 200]
|
||||||
|
- EID: 3
|
||||||
|
Name: Default
|
||||||
|
IsActive: true
|
||||||
|
NumberOfChildren: 0
|
||||||
|
Components:
|
||||||
|
Transform Component:
|
||||||
|
Translate: {x: 0, y: 1.20000005, z: 0}
|
||||||
|
Rotate: {x: -0, y: 0, z: -0}
|
||||||
|
Scale: {x: 1, y: 1, z: 1}
|
||||||
|
IsActive: true
|
||||||
|
Scripts: ~
|
||||||
|
- EID: 4
|
||||||
|
Name: Default
|
||||||
|
IsActive: true
|
||||||
|
NumberOfChildren: 0
|
||||||
|
Components:
|
||||||
|
Transform Component:
|
||||||
|
Translate: {x: 0, y: 0, z: 0}
|
||||||
|
Rotate: {x: -0.785401046, y: 1.65799224, z: 0}
|
||||||
|
Scale: {x: 1, y: 1, z: 1}
|
||||||
|
IsActive: true
|
||||||
|
Camera Component:
|
||||||
|
Position: {x: -18.9007454, y: -3.67369723, z: -5.23871422}
|
||||||
|
Pitch: -45.000164
|
||||||
|
Yaw: 94.9959564
|
||||||
|
Roll: 0
|
||||||
|
Width: 1920
|
||||||
|
Height: 1080
|
||||||
|
Near: 0.00999999978
|
||||||
|
Far: 10000
|
||||||
|
Perspective: true
|
||||||
|
IsActive: true
|
||||||
|
Scripts:
|
||||||
|
- Type: SHADE_Scripting.ThirdPersonCamera
|
||||||
|
armLength: 2
|
||||||
|
turnSpeedPitch: 0.300000012
|
||||||
|
turnSpeedYaw: 0.5
|
||||||
|
pitchClamp: 45
|
||||||
|
- EID: 9
|
||||||
|
Name: Default
|
||||||
|
IsActive: true
|
||||||
|
NumberOfChildren: 0
|
||||||
|
Components:
|
||||||
|
Transform Component:
|
||||||
|
Translate: {x: 0, y: 0, z: 0}
|
||||||
|
Rotate: {x: 0, y: 0, z: 0}
|
||||||
|
Scale: {x: 1, y: 1, z: 1}
|
||||||
|
IsActive: true
|
||||||
|
Renderable Component:
|
||||||
|
Mesh: 144838771
|
||||||
|
Material: 123745521
|
||||||
|
IsActive: true
|
||||||
|
Scripts: ~
|
||||||
|
- EID: 6
|
||||||
|
Name: AI
|
||||||
|
IsActive: true
|
||||||
|
NumberOfChildren: 0
|
||||||
|
Components:
|
||||||
|
Transform Component:
|
||||||
|
Translate: {x: -8, y: -4.42369843, z: 2.5}
|
||||||
|
Rotate: {x: -0, y: 0, z: 0}
|
||||||
|
Scale: {x: 1, y: 1, z: 1}
|
||||||
|
IsActive: true
|
||||||
|
Renderable Component:
|
||||||
|
Mesh: 149697411
|
||||||
|
Material: 126974645
|
||||||
|
IsActive: true
|
||||||
|
RigidBody Component:
|
||||||
|
Type: Dynamic
|
||||||
|
Mass: 1
|
||||||
|
Drag: 0
|
||||||
|
Angular Drag: 0
|
||||||
|
Use Gravity: true
|
||||||
|
Interpolate: false
|
||||||
|
Freeze Position X: false
|
||||||
|
Freeze Position Y: false
|
||||||
|
Freeze Position Z: false
|
||||||
|
Freeze Rotation X: true
|
||||||
|
Freeze Rotation Y: true
|
||||||
|
Freeze Rotation Z: true
|
||||||
|
IsActive: true
|
||||||
|
Collider Component:
|
||||||
|
Colliders:
|
||||||
|
- Is Trigger: false
|
||||||
|
Type: Box
|
||||||
|
Half Extents: {x: 0.5, y: 0.5, z: 0.5}
|
||||||
|
Friction: 0.400000006
|
||||||
|
Bounciness: 0
|
||||||
|
Density: 1
|
||||||
|
Position Offset: {x: 0, y: 0.5, z: 0}
|
||||||
|
IsActive: true
|
||||||
|
Scripts: ~
|
||||||
|
- EID: 7
|
||||||
|
Name: Default
|
||||||
|
IsActive: true
|
||||||
|
NumberOfChildren: 0
|
||||||
|
Components:
|
||||||
|
Transform Component:
|
||||||
|
Translate: {x: 0, y: -16.8647861, z: -14.039052}
|
||||||
|
Rotate: {x: -0, y: 0, z: -0}
|
||||||
|
Scale: {x: 28.1434975, y: 28.1434975, z: 28.1434975}
|
||||||
|
IsActive: true
|
||||||
|
Renderable Component:
|
||||||
|
Mesh: 149697411
|
||||||
|
Material: 126974645
|
||||||
|
IsActive: true
|
||||||
|
Scripts: ~
|
||||||
|
- EID: 8
|
||||||
|
Name: Default
|
||||||
|
IsActive: true
|
||||||
|
NumberOfChildren: 0
|
||||||
|
Components:
|
||||||
|
Light Component:
|
||||||
|
Position: {x: 0, y: 0, z: 0}
|
||||||
|
Type: Ambient
|
||||||
|
Direction: {x: 0, y: 0, z: 1}
|
||||||
|
Color: {x: 1, y: 1, z: 1, w: 1}
|
||||||
|
Layer: 4294967295
|
||||||
|
Strength: 0.25
|
||||||
|
IsActive: true
|
||||||
|
Scripts: ~
|
||||||
|
- EID: 11
|
||||||
|
Name: GameManager
|
||||||
|
IsActive: true
|
||||||
|
NumberOfChildren: 0
|
||||||
|
Components:
|
||||||
|
Transform Component:
|
||||||
|
Translate: {x: 0, y: 0, z: 0}
|
||||||
|
Rotate: {x: 0, y: 0, z: 0}
|
||||||
|
Scale: {x: 1, y: 1, z: 1}
|
||||||
|
IsActive: true
|
||||||
|
RigidBody Component:
|
||||||
|
Type: Static
|
||||||
|
Mass: 1
|
||||||
|
Drag: 0.00999999978
|
||||||
|
Angular Drag: 0.00999999978
|
||||||
|
Use Gravity: true
|
||||||
|
Interpolate: true
|
||||||
|
Freeze Position X: false
|
||||||
|
Freeze Position Y: false
|
||||||
|
Freeze Position Z: false
|
||||||
|
Freeze Rotation X: false
|
||||||
|
Freeze Rotation Y: false
|
||||||
|
Freeze Rotation Z: false
|
||||||
|
IsActive: true
|
||||||
|
Collider Component:
|
||||||
|
Colliders: ~
|
||||||
|
IsActive: true
|
||||||
|
Scripts:
|
||||||
|
- Type: GameManager
|
||||||
|
itemPool: 12
|
||||||
|
zonePool: 51000
|
||||||
|
currGameState: 0
|
||||||
|
totalItemCount: -202
|
||||||
|
Score: 204
|
||||||
|
timer: 0
|
||||||
|
- EID: 12
|
||||||
|
Name: ItemPool
|
||||||
|
IsActive: true
|
||||||
|
NumberOfChildren: 2
|
||||||
|
Components: ~
|
||||||
|
Scripts: ~
|
||||||
|
- EID: 10
|
||||||
|
Name: item
|
||||||
|
IsActive: true
|
||||||
|
NumberOfChildren: 0
|
||||||
|
Components:
|
||||||
|
Transform Component:
|
||||||
|
Translate: {x: 3.19870043, y: -3.67369723, z: -5}
|
||||||
|
Rotate: {x: -0, y: 0, z: 0}
|
||||||
|
Scale: {x: 2, y: 2, z: 2}
|
||||||
|
IsActive: true
|
||||||
|
Renderable Component:
|
||||||
|
Mesh: 144838771
|
||||||
|
Material: 123745521
|
||||||
|
IsActive: true
|
||||||
|
RigidBody Component:
|
||||||
|
Type: Dynamic
|
||||||
|
Mass: 1
|
||||||
|
Drag: 0
|
||||||
|
Angular Drag: 0
|
||||||
|
Use Gravity: true
|
||||||
|
Interpolate: false
|
||||||
|
Freeze Position X: false
|
||||||
|
Freeze Position Y: false
|
||||||
|
Freeze Position Z: false
|
||||||
|
Freeze Rotation X: true
|
||||||
|
Freeze Rotation Y: true
|
||||||
|
Freeze Rotation Z: true
|
||||||
|
IsActive: true
|
||||||
|
Collider Component:
|
||||||
|
Colliders:
|
||||||
|
- Is Trigger: false
|
||||||
|
Type: Box
|
||||||
|
Half Extents: {x: 1, y: 1, z: 1}
|
||||||
|
Friction: 0.400000006
|
||||||
|
Bounciness: 0
|
||||||
|
Density: 1
|
||||||
|
Position Offset: {x: 0, y: 0.5, z: 0}
|
||||||
|
- Is Trigger: true
|
||||||
|
Type: Box
|
||||||
|
Half Extents: {x: 2, y: 2, z: 2}
|
||||||
|
Friction: 0.400000006
|
||||||
|
Bounciness: 0
|
||||||
|
Density: 1
|
||||||
|
Position Offset: {x: 0, y: 0.5, z: 0}
|
||||||
|
IsActive: true
|
||||||
|
Scripts:
|
||||||
|
- Type: Item
|
||||||
|
Score: 1
|
||||||
|
currCategory: 0
|
||||||
|
- EID: 5
|
||||||
|
Name: item
|
||||||
|
IsActive: true
|
||||||
|
NumberOfChildren: 0
|
||||||
|
Components:
|
||||||
|
Transform Component:
|
||||||
|
Translate: {x: -20.6163979, y: -0.0419634879, z: -5.08873653}
|
||||||
|
Rotate: {x: -0, y: 0, z: 0}
|
||||||
|
Scale: {x: 2, y: 2, z: 2}
|
||||||
|
IsActive: false
|
||||||
|
Renderable Component:
|
||||||
|
Mesh: 144838771
|
||||||
|
Material: 123745521
|
||||||
|
IsActive: false
|
||||||
|
RigidBody Component:
|
||||||
|
Type: Dynamic
|
||||||
|
Mass: 1
|
||||||
|
Drag: 0
|
||||||
|
Angular Drag: 0
|
||||||
|
Use Gravity: true
|
||||||
|
Interpolate: false
|
||||||
|
Freeze Position X: false
|
||||||
|
Freeze Position Y: false
|
||||||
|
Freeze Position Z: false
|
||||||
|
Freeze Rotation X: true
|
||||||
|
Freeze Rotation Y: true
|
||||||
|
Freeze Rotation Z: true
|
||||||
|
IsActive: false
|
||||||
|
Collider Component:
|
||||||
|
Colliders:
|
||||||
|
- Is Trigger: false
|
||||||
|
Type: Box
|
||||||
|
Half Extents: {x: 1, y: 1, z: 1}
|
||||||
|
Friction: 0.400000006
|
||||||
|
Bounciness: 0
|
||||||
|
Density: 1
|
||||||
|
Position Offset: {x: 0, y: 0.5, z: 0}
|
||||||
|
- Is Trigger: true
|
||||||
|
Type: Box
|
||||||
|
Half Extents: {x: 2, y: 2, z: 2}
|
||||||
|
Friction: 0.400000006
|
||||||
|
Bounciness: 0
|
||||||
|
Density: 1
|
||||||
|
Position Offset: {x: 0, y: 0.5, z: 0}
|
||||||
|
IsActive: false
|
||||||
|
Scripts:
|
||||||
|
- Type: Item
|
||||||
|
Score: 1
|
||||||
|
currCategory: 0
|
||||||
|
- EID: 15
|
||||||
|
Name: ScoreZonePool
|
||||||
|
IsActive: true
|
||||||
|
NumberOfChildren: 2
|
||||||
|
Components: ~
|
||||||
|
Scripts: ~
|
||||||
|
- EID: 13
|
||||||
|
Name: ScoreZone
|
||||||
|
IsActive: true
|
||||||
|
NumberOfChildren: 0
|
||||||
|
Components:
|
||||||
|
Transform Component:
|
||||||
|
Translate: {x: -24.5947151, y: -3.15127993, z: -3.29243231}
|
||||||
|
Rotate: {x: 0, y: 0, z: 0}
|
||||||
|
Scale: {x: 1, y: 1, z: 1}
|
||||||
|
IsActive: true
|
||||||
|
RigidBody Component:
|
||||||
|
Type: Static
|
||||||
|
Mass: 1
|
||||||
|
Drag: 0.00999999978
|
||||||
|
Angular Drag: 0.00999999978
|
||||||
|
Use Gravity: true
|
||||||
|
Interpolate: true
|
||||||
|
Freeze Position X: false
|
||||||
|
Freeze Position Y: false
|
||||||
|
Freeze Position Z: false
|
||||||
|
Freeze Rotation X: false
|
||||||
|
Freeze Rotation Y: false
|
||||||
|
Freeze Rotation Z: false
|
||||||
|
IsActive: true
|
||||||
|
Collider Component:
|
||||||
|
Colliders:
|
||||||
|
- Is Trigger: true
|
||||||
|
Type: Box
|
||||||
|
Half Extents: {x: 1, y: 20, z: 20}
|
||||||
|
Friction: 0.400000006
|
||||||
|
Bounciness: 0
|
||||||
|
Density: 1
|
||||||
|
Position Offset: {x: 0, y: 0, z: 0}
|
||||||
|
IsActive: true
|
||||||
|
Scripts: ~
|
||||||
|
- EID: 14
|
||||||
|
Name: ScoreZone
|
||||||
|
IsActive: true
|
||||||
|
NumberOfChildren: 0
|
||||||
|
Components:
|
||||||
|
Transform Component:
|
||||||
|
Translate: {x: -6.64785767, y: 0, z: -14.217104}
|
||||||
|
Rotate: {x: -0, y: 0, z: -0}
|
||||||
|
Scale: {x: 1, y: 1, z: 1}
|
||||||
|
IsActive: true
|
||||||
|
RigidBody Component:
|
||||||
|
Type: Static
|
||||||
|
Mass: 1
|
||||||
|
Drag: 0.00999999978
|
||||||
|
Angular Drag: 0.00999999978
|
||||||
|
Use Gravity: true
|
||||||
|
Interpolate: true
|
||||||
|
Freeze Position X: false
|
||||||
|
Freeze Position Y: false
|
||||||
|
Freeze Position Z: false
|
||||||
|
Freeze Rotation X: false
|
||||||
|
Freeze Rotation Y: false
|
||||||
|
Freeze Rotation Z: false
|
||||||
|
IsActive: true
|
||||||
|
Collider Component:
|
||||||
|
Colliders:
|
||||||
|
- Is Trigger: true
|
||||||
|
Type: Box
|
||||||
|
Half Extents: {x: 20, y: 20, z: 1}
|
||||||
|
Friction: 0.400000006
|
||||||
|
Bounciness: 0
|
||||||
|
Density: 1
|
||||||
|
Position Offset: {x: 0, y: 0, z: 0}
|
||||||
|
IsActive: true
|
||||||
|
Scripts: ~
|
|
@ -0,0 +1,3 @@
|
||||||
|
Name: PlayerControllerTest
|
||||||
|
ID: 92100024
|
||||||
|
Type: 5
|
|
@ -0,0 +1,62 @@
|
||||||
|
using SHADE;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
public class GameManager : Script
|
||||||
|
{
|
||||||
|
public enum GameState
|
||||||
|
{
|
||||||
|
MAINMENU,
|
||||||
|
WIN,
|
||||||
|
LOSE,
|
||||||
|
TOTAL
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameObject itemPool;
|
||||||
|
public GameObject zonePool;
|
||||||
|
public GameState currGameState;
|
||||||
|
|
||||||
|
[NonSerialized]
|
||||||
|
public int totalItemCount;
|
||||||
|
[NonSerialized]
|
||||||
|
public int Score;
|
||||||
|
[NonSerialized]
|
||||||
|
public float timer;
|
||||||
|
|
||||||
|
private IEnumerable<Item> listOfItems;
|
||||||
|
private IEnumerable<ScoringZone> listOfZone;
|
||||||
|
|
||||||
|
protected override void awake()
|
||||||
|
{
|
||||||
|
totalItemCount = 0;
|
||||||
|
Score = 0;
|
||||||
|
currGameState = GameState.MAINMENU;
|
||||||
|
|
||||||
|
if (itemPool)
|
||||||
|
{
|
||||||
|
listOfItems = itemPool.GetScriptsInChildren<Item>();
|
||||||
|
foreach (Item i in listOfItems)
|
||||||
|
totalItemCount += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (zonePool)
|
||||||
|
{
|
||||||
|
listOfZone = itemPool.GetScriptsInChildren<ScoringZone>();
|
||||||
|
foreach (ScoringZone i in listOfZone)
|
||||||
|
i.gameManger = Owner.GetScript<GameManager>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void update()
|
||||||
|
{
|
||||||
|
if (timer > 0)
|
||||||
|
timer -= Time.DeltaTimeF;
|
||||||
|
else
|
||||||
|
currGameState = GameState.LOSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void onTriggerEnter(CollisionInfo info)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
Name: SC_GameManager
|
||||||
|
ID: 161629605
|
||||||
|
Type: 9
|
|
@ -9,9 +9,16 @@ public class Item : Script
|
||||||
HEAVY
|
HEAVY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int Score = 10;
|
||||||
|
|
||||||
public ItemCategory currCategory;
|
public ItemCategory currCategory;
|
||||||
|
|
||||||
protected override void awake()
|
protected override void awake()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void onTriggerEnter(CollisionInfo info)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
Name: SC_Item
|
||||||
|
ID: 153136539
|
||||||
|
Type: 9
|
|
@ -4,8 +4,9 @@ using static PlayerController;
|
||||||
|
|
||||||
public class PickAndThrow : Script
|
public class PickAndThrow : Script
|
||||||
{
|
{
|
||||||
|
public Vector3 holdPosition = new Vector3(0.0f, 1.0f, 0.0f);
|
||||||
public Vector3 throwForce = new Vector3(100.0f, 200.0f, 100.0f);
|
public Vector3 throwForce = new Vector3(100.0f, 200.0f, 100.0f);
|
||||||
public GameObject item;
|
public GameObject item { get; set; }
|
||||||
private PlayerController pc;
|
private PlayerController pc;
|
||||||
private Camera cam;
|
private Camera cam;
|
||||||
private Transform itemTransform;
|
private Transform itemTransform;
|
||||||
|
@ -22,36 +23,13 @@ public class PickAndThrow : Script
|
||||||
if (raccoonHoldLocation == null)
|
if (raccoonHoldLocation == null)
|
||||||
Debug.Log("CHILD EMPTY");
|
Debug.Log("CHILD EMPTY");
|
||||||
else
|
else
|
||||||
raccoonHoldLocation.LocalPosition = new Vector3(0.0f, 1.0f, 0.0f);
|
raccoonHoldLocation.LocalPosition = holdPosition;
|
||||||
}
|
}
|
||||||
protected override void update()
|
protected override void update()
|
||||||
{
|
{
|
||||||
if (cam == null)
|
CalculateDir();
|
||||||
cam = GetComponentInChildren<Camera>();
|
|
||||||
else if (cam != null)
|
|
||||||
{
|
|
||||||
Vector3 camerAixs = cam.GetForward();
|
|
||||||
camerAixs.y = 0;
|
|
||||||
camerAixs.Normalise();
|
|
||||||
lastXDir = camerAixs.x;
|
|
||||||
lastZDir = camerAixs.z;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.GetScript<Item>() != null && itemTransform == null && itemRidibody == null)
|
if (pc != null && pc.holdItem && itemRidibody != null && itemTransform != null)
|
||||||
{
|
|
||||||
itemTransform = item.GetComponent<Transform>();
|
|
||||||
if (itemTransform == null)
|
|
||||||
Debug.Log("Item transform EMPTY");
|
|
||||||
|
|
||||||
itemRidibody = item.GetComponent<RigidBody>();
|
|
||||||
if (itemRidibody == null)
|
|
||||||
Debug.Log("Item rb EMPTY");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pc != null && inRange && !pc.holdItem && Input.GetKey(Input.KeyCode.E))
|
|
||||||
pc.holdItem = true;
|
|
||||||
|
|
||||||
if (pc != null && itemRidibody != null && itemTransform != null && pc.holdItem)
|
|
||||||
{
|
{
|
||||||
itemTransform.LocalPosition = raccoonHoldLocation.GlobalPosition;
|
itemTransform.LocalPosition = raccoonHoldLocation.GlobalPosition;
|
||||||
itemRidibody.IsGravityEnabled = false;
|
itemRidibody.IsGravityEnabled = false;
|
||||||
|
@ -65,17 +43,60 @@ public class PickAndThrow : Script
|
||||||
itemRidibody.IsGravityEnabled = true;
|
itemRidibody.IsGravityEnabled = true;
|
||||||
itemRidibody.AddForce(new Vector3(throwForce.x * lastXDir, throwForce.y, throwForce.z * lastZDir));
|
itemRidibody.AddForce(new Vector3(throwForce.x * lastXDir, throwForce.y, throwForce.z * lastZDir));
|
||||||
itemRidibody.LinearVelocity += pc.rb.LinearVelocity;
|
itemRidibody.LinearVelocity += pc.rb.LinearVelocity;
|
||||||
|
ResetItemObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(!pc.holdItem && itemRidibody != null)
|
else if(!pc.holdItem && itemRidibody != null)
|
||||||
itemRidibody.IsGravityEnabled = true;
|
itemRidibody.IsGravityEnabled = true;
|
||||||
|
|
||||||
|
if (pc != null && !pc.holdItem && inRange && Input.GetMouseButtonDown(Input.MouseCode.LeftButton))
|
||||||
|
{
|
||||||
|
pc.holdItem = true;
|
||||||
|
RetrieveItemComponets();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ResetItemObject()
|
||||||
|
{
|
||||||
|
itemRidibody = null;
|
||||||
|
itemTransform = null;
|
||||||
|
item = new GameObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RetrieveItemComponets()
|
||||||
|
{
|
||||||
|
//get the transform of the given item
|
||||||
|
if (item.GetScript<Item>() != null && itemTransform == null && itemRidibody == null)
|
||||||
|
{
|
||||||
|
itemTransform = item.GetComponent<Transform>();
|
||||||
|
if (itemTransform == null)
|
||||||
|
Debug.Log("Item transform EMPTY");
|
||||||
|
|
||||||
|
itemRidibody = item.GetComponent<RigidBody>();
|
||||||
|
if (itemRidibody == null)
|
||||||
|
Debug.Log("Item rb EMPTY");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CalculateDir()
|
||||||
|
{
|
||||||
|
if (cam == null)
|
||||||
|
cam = GetComponentInChildren<Camera>();
|
||||||
|
else if (cam != null)
|
||||||
|
{
|
||||||
|
Vector3 camerAixs = cam.GetForward();
|
||||||
|
camerAixs.y = 0;
|
||||||
|
camerAixs.Normalise();
|
||||||
|
lastXDir = camerAixs.x;
|
||||||
|
lastZDir = camerAixs.z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override void onCollisionEnter(CollisionInfo info)
|
protected override void onCollisionEnter(CollisionInfo info)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
protected override void onTriggerEnter(CollisionInfo info)
|
protected override void onTriggerEnter(CollisionInfo info)
|
||||||
{
|
{
|
||||||
//Debug.Log("ENTER");
|
|
||||||
if (info.GameObject.GetScript<Item>() != null && !pc.holdItem)
|
if (info.GameObject.GetScript<Item>() != null && !pc.holdItem)
|
||||||
{
|
{
|
||||||
item = info.GameObject;
|
item = info.GameObject;
|
|
@ -0,0 +1,3 @@
|
||||||
|
Name: SC_PickAndThrow
|
||||||
|
ID: 154802724
|
||||||
|
Type: 9
|
|
@ -1,40 +1,47 @@
|
||||||
using SHADE;
|
using SHADE;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using static Item;
|
using static Item;
|
||||||
|
|
||||||
public class PlayerController : Script
|
public class PlayerController : Script
|
||||||
{
|
{
|
||||||
public enum RaccoonStates
|
public enum RaccoonStates
|
||||||
{
|
{
|
||||||
IDILE,
|
IDLE,
|
||||||
WALKING,
|
WALKING,
|
||||||
RUNNING,
|
RUNNING,
|
||||||
JUMP,
|
JUMP,
|
||||||
FALLING,
|
FALLING,
|
||||||
|
LANDED,
|
||||||
CAUGHT,
|
CAUGHT,
|
||||||
TOTAL
|
TOTAL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum WalkingState
|
||||||
|
{
|
||||||
|
CARRY,
|
||||||
|
AIMING,
|
||||||
|
THROW,
|
||||||
|
WALK,
|
||||||
|
TOTAL
|
||||||
|
}
|
||||||
|
|
||||||
public RigidBody rb { get; set; }
|
public RigidBody rb { get; set; }
|
||||||
private Transform tranform;
|
private Transform tranform;
|
||||||
private Camera cam;
|
private Camera cam;
|
||||||
private PickAndThrow pat;
|
private PickAndThrow pat;
|
||||||
|
private StateMachine stateMachine;
|
||||||
|
|
||||||
//to be remove
|
|
||||||
public float drag = 2.0f;
|
|
||||||
public bool holdItem { get; set; }
|
public bool holdItem { get; set; }
|
||||||
[SerializeField]
|
|
||||||
[Tooltip("The current state fo the raccoon")]
|
[Tooltip("The current state fo the raccoon")]
|
||||||
public RaccoonStates currentState = RaccoonStates.IDILE;
|
public RaccoonStates currentState = RaccoonStates.IDLE;
|
||||||
|
|
||||||
//Movement variables============================================================
|
//Movement variables============================================================
|
||||||
[SerializeField]
|
|
||||||
[Tooltip("Max vel for walking")]
|
[Tooltip("Max vel for walking")]
|
||||||
public float maxMoveVel = 2.0f;
|
public float maxMoveVel = 2.0f;
|
||||||
[SerializeField]
|
|
||||||
[Tooltip("how much force is apply for walking")]
|
[Tooltip("how much force is apply for walking")]
|
||||||
public float moveForce = 50.0f;
|
public float moveForce = 2.0f;
|
||||||
[SerializeField]
|
|
||||||
[Tooltip("increase the moveForce and maxMoveVel by its amt")]
|
[Tooltip("increase the moveForce and maxMoveVel by its amt")]
|
||||||
public float sprintMultiplier = 2.0f;
|
public float sprintMultiplier = 2.0f;
|
||||||
|
|
||||||
|
@ -49,7 +56,6 @@ public class PlayerController : Script
|
||||||
|
|
||||||
public bool isMoveKeyPress { get; set; }
|
public bool isMoveKeyPress { get; set; }
|
||||||
|
|
||||||
[SerializeField]
|
|
||||||
[Tooltip("curr not working")]
|
[Tooltip("curr not working")]
|
||||||
public float rotationFactorPerFrame = 1.0f;
|
public float rotationFactorPerFrame = 1.0f;
|
||||||
|
|
||||||
|
@ -75,6 +81,7 @@ public class PlayerController : Script
|
||||||
|
|
||||||
protected override void awake()
|
protected override void awake()
|
||||||
{
|
{
|
||||||
|
Audio.PlayBGMOnce2D("event:/Music/player_undetected");
|
||||||
//default setup
|
//default setup
|
||||||
isMoveKeyPress = false;
|
isMoveKeyPress = false;
|
||||||
holdItem = false;
|
holdItem = false;
|
||||||
|
@ -91,10 +98,6 @@ public class PlayerController : Script
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rb.IsGravityEnabled = false;
|
rb.IsGravityEnabled = false;
|
||||||
rb.FreezeRotationX = true;
|
|
||||||
rb.FreezeRotationY = true;
|
|
||||||
rb.FreezeRotationZ = true;
|
|
||||||
rb.Drag = drag;
|
|
||||||
rb.Interpolating = false;
|
rb.Interpolating = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,14 +106,18 @@ public class PlayerController : Script
|
||||||
if(tranform == null)
|
if(tranform == null)
|
||||||
Debug.LogError("tranform is NULL!");
|
Debug.LogError("tranform is NULL!");
|
||||||
|
|
||||||
//PickAndThrow checl
|
//PickAndThrow check
|
||||||
pat = GetScript<PickAndThrow>();
|
pat = GetScript<PickAndThrow>();
|
||||||
if (pat == null)
|
if (pat == null)
|
||||||
Debug.LogError("PickAndThrow is NULL!");
|
Debug.LogError("PickAndThrow is NULL!");
|
||||||
|
|
||||||
//toRemove
|
stateMachine = AddScript<StateMachine>();
|
||||||
tranform.LocalPosition = new Vector3(-3.0f, -2.0f, -5.0f);
|
Dictionary<Type, BaseState> dictionary = new Dictionary<Type, BaseState>();
|
||||||
tranform.LocalRotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
|
dictionary.Add(typeof(IdleState), new IdleState(stateMachine));
|
||||||
|
dictionary.Add(typeof(WalkState), new WalkState(stateMachine));
|
||||||
|
dictionary.Add(typeof(RunState), new RunState(stateMachine));
|
||||||
|
stateMachine.InitStateMachine(dictionary);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void update()
|
protected override void update()
|
||||||
|
@ -118,118 +125,103 @@ public class PlayerController : Script
|
||||||
if (cam == null)
|
if (cam == null)
|
||||||
cam = GetComponentInChildren<Camera>();
|
cam = GetComponentInChildren<Camera>();
|
||||||
|
|
||||||
//toRemove
|
|
||||||
if (Input.GetKey(Input.KeyCode.G))
|
|
||||||
{
|
|
||||||
tranform.LocalRotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
|
|
||||||
tranform.LocalPosition = new Vector3(-3.0f, -2.0f, -5.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
GotCaught();
|
GotCaught();
|
||||||
MoveKey();
|
//Debug.Log($"{currentState}");
|
||||||
|
//Debug.Log($" axisX: {axisMove.x} axisY:{axisMove.y}");
|
||||||
|
//Debug.Log($"X: {rb.LinearVelocity.x}" + $" Z: {rb.LinearVelocity.z}");
|
||||||
|
|
||||||
//Debug.Log(currentState.ToString() + " x:" + rb.LinearVelocity.x.ToString() + " y:" + rb.LinearVelocity.y.ToString() + " z:" + rb.LinearVelocity.z.ToString());
|
//Debug.Log(currentState.ToString() + " x:" + rb.LinearVelocity.x.ToString() + " y:" + rb.LinearVelocity.y.ToString() + " z:" + rb.LinearVelocity.z.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void fixedUpdate()
|
protected override void fixedUpdate()
|
||||||
{
|
{
|
||||||
//Rotation();
|
//Rotation();
|
||||||
|
|
||||||
|
|
||||||
|
MoveKey();
|
||||||
Move();
|
Move();
|
||||||
Sprint();
|
Sprint();
|
||||||
Jump();
|
Jump();
|
||||||
Gravity();
|
Gravity();
|
||||||
|
//Debug.Log($"X: {rb.LinearVelocity.x}" + $" Z: {rb.LinearVelocity.z}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void MoveKey()
|
private void MoveKey()
|
||||||
{
|
{
|
||||||
/* if (Input.GetKey(Input.KeyCode.A))
|
|
||||||
xAxisMove = -1;
|
|
||||||
else if (Input.GetKey(Input.KeyCode.D))
|
|
||||||
xAxisMove = 1;
|
|
||||||
else
|
|
||||||
xAxisMove = 0;
|
|
||||||
|
|
||||||
if (Input.GetKey(Input.KeyCode.W))
|
|
||||||
zAxisMove = -1;
|
|
||||||
else if (Input.GetKey(Input.KeyCode.S))
|
|
||||||
zAxisMove = 1;
|
|
||||||
else
|
|
||||||
zAxisMove = 0;*/
|
|
||||||
|
|
||||||
|
|
||||||
xAxisMove = 0;
|
|
||||||
zAxisMove = 0;
|
|
||||||
axisMove = Vector2.Zero;
|
axisMove = Vector2.Zero;
|
||||||
if (Input.GetKey(Input.KeyCode.W))
|
if (Input.GetKey(Input.KeyCode.W))
|
||||||
{
|
{
|
||||||
Vector3 camerAixs = cam.GetForward();
|
Vector3 camerAixs = cam.GetForward();
|
||||||
camerAixs.y = 0;
|
camerAixs.y = 0;
|
||||||
camerAixs.Normalise();
|
camerAixs.Normalise();
|
||||||
xAxisMove = camerAixs.x;
|
|
||||||
zAxisMove = camerAixs.z;
|
|
||||||
axisMove += new Vector2(camerAixs.x, camerAixs.z);
|
axisMove += new Vector2(camerAixs.x, camerAixs.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input.GetKey(Input.KeyCode.S))
|
if (Input.GetKey(Input.KeyCode.S))
|
||||||
{
|
{
|
||||||
Vector3 camerAixs = cam.GetForward();
|
Vector3 camerAixs = cam.GetForward();
|
||||||
camerAixs.y = 0;
|
camerAixs.y = 0;
|
||||||
camerAixs.Normalise();
|
camerAixs.Normalise();
|
||||||
xAxisMove = -camerAixs.x;
|
|
||||||
zAxisMove = -camerAixs.z;
|
|
||||||
axisMove -= new Vector2(camerAixs.x, camerAixs.z);
|
axisMove -= new Vector2(camerAixs.x, camerAixs.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input.GetKey(Input.KeyCode.A))
|
if (Input.GetKey(Input.KeyCode.A))
|
||||||
{
|
{
|
||||||
Vector3 camerAixs = cam.GetRight();
|
Vector3 camerAixs = cam.GetRight();
|
||||||
camerAixs.y = 0;
|
camerAixs.y = 0;
|
||||||
camerAixs.Normalise();
|
camerAixs.Normalise();
|
||||||
xAxisMove = -camerAixs.x;
|
|
||||||
zAxisMove = -camerAixs.z;
|
|
||||||
axisMove -= new Vector2(camerAixs.x, camerAixs.z);
|
axisMove -= new Vector2(camerAixs.x, camerAixs.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input.GetKey(Input.KeyCode.D))
|
if (Input.GetKey(Input.KeyCode.D))
|
||||||
{
|
{
|
||||||
Vector3 camerAixs = cam.GetRight();
|
Vector3 camerAixs = cam.GetRight();
|
||||||
camerAixs.y = 0;
|
camerAixs.y = 0;
|
||||||
camerAixs.Normalise();
|
camerAixs.Normalise();
|
||||||
xAxisMove = camerAixs.x;
|
|
||||||
zAxisMove = camerAixs.z;
|
|
||||||
axisMove += new Vector2(camerAixs.x, camerAixs.z);
|
axisMove += new Vector2(camerAixs.x, camerAixs.z);
|
||||||
}
|
}
|
||||||
axisMove.Normalise();
|
|
||||||
isMoveKeyPress = xAxisMove != 0 || zAxisMove != 0;
|
|
||||||
|
|
||||||
if(isMoveKeyPress && currentState != RaccoonStates.RUNNING && isGrounded)
|
axisMove.Normalise();
|
||||||
|
isMoveKeyPress = axisMove.x != 0 || axisMove.y != 0;
|
||||||
|
|
||||||
|
if (isMoveKeyPress && isGrounded && !Input.GetKey(Input.KeyCode.LeftShift))
|
||||||
|
{
|
||||||
currentState = RaccoonStates.WALKING;
|
currentState = RaccoonStates.WALKING;
|
||||||
|
|
||||||
|
if(stateMachine && !stateMachine.IsState(typeof(WalkState)))
|
||||||
|
stateMachine.SetState(typeof(WalkState));
|
||||||
|
}
|
||||||
|
|
||||||
if (!isMoveKeyPress && isGrounded)
|
if (!isMoveKeyPress && isGrounded)
|
||||||
currentState = RaccoonStates.IDILE;
|
{
|
||||||
|
currentState = RaccoonStates.IDLE;
|
||||||
|
|
||||||
|
if(stateMachine && !stateMachine.IsState(typeof(IdleState)))
|
||||||
|
stateMachine.SetState(typeof(IdleState));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Move()
|
private void Move()
|
||||||
{
|
{
|
||||||
if (rb != null)
|
if (rb != null)
|
||||||
{
|
{
|
||||||
rb.AddForce(new Vector3(axisMove.x, 0.0f,axisMove.y) * moveForce);
|
rb.LinearVelocity += new Vector3(axisMove.x * moveForce, 0.0f, axisMove.y * moveForce) * Time.DeltaTimeF;
|
||||||
|
|
||||||
if (isMoveKeyPress)
|
if (isMoveKeyPress)
|
||||||
{
|
{
|
||||||
if (rb.LinearVelocity.x > maxMoveVel || rb.LinearVelocity.x < -maxMoveVel)
|
if (rb)
|
||||||
{
|
{
|
||||||
Vector3 v = rb.LinearVelocity;
|
Vector3 velNor = rb.LinearVelocity;
|
||||||
v.x = System.Math.Clamp(v.x, -maxMoveVel, maxMoveVel);
|
velNor.y = 0.0f;
|
||||||
rb.LinearVelocity = v;
|
if (velNor.GetMagnitude() > maxMoveVel)
|
||||||
}
|
|
||||||
if (rb.LinearVelocity.z > maxMoveVel || rb.LinearVelocity.z < -maxMoveVel)
|
|
||||||
{
|
{
|
||||||
Vector3 v = rb.LinearVelocity;
|
velNor.Normalise();
|
||||||
v.z = System.Math.Clamp(v.z, -maxMoveVel, maxMoveVel);
|
velNor *= maxMoveVel;
|
||||||
rb.LinearVelocity = v;
|
rb.LinearVelocity = new Vector3(velNor.x, rb.LinearVelocity.y, velNor.z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,6 +230,9 @@ public class PlayerController : Script
|
||||||
if (Input.GetKey(Input.KeyCode.LeftShift) && isMoveKeyPress && isGrounded)
|
if (Input.GetKey(Input.KeyCode.LeftShift) && isMoveKeyPress && isGrounded)
|
||||||
{
|
{
|
||||||
currentState = RaccoonStates.RUNNING;
|
currentState = RaccoonStates.RUNNING;
|
||||||
|
if (stateMachine && !stateMachine.IsState(typeof(RunState)))
|
||||||
|
stateMachine.SetState(typeof(RunState));
|
||||||
|
|
||||||
holdItem = false;
|
holdItem = false;
|
||||||
if (!sprintIncreaseOnce)
|
if (!sprintIncreaseOnce)
|
||||||
{
|
{
|
||||||
|
@ -252,8 +247,12 @@ public class PlayerController : Script
|
||||||
|
|
||||||
if (Input.GetKeyUp(Input.KeyCode.LeftShift))
|
if (Input.GetKeyUp(Input.KeyCode.LeftShift))
|
||||||
{
|
{
|
||||||
if(isMoveKeyPress)
|
if (isMoveKeyPress)
|
||||||
|
{
|
||||||
currentState = RaccoonStates.WALKING;
|
currentState = RaccoonStates.WALKING;
|
||||||
|
if(stateMachine && !stateMachine.IsState(typeof(WalkState)))
|
||||||
|
stateMachine.SetState(typeof(WalkState));
|
||||||
|
}
|
||||||
sprintIncreaseOnce = false;
|
sprintIncreaseOnce = false;
|
||||||
moveForce = oldForce;
|
moveForce = oldForce;
|
||||||
maxMoveVel = maxOldVel;
|
maxMoveVel = maxOldVel;
|
||||||
|
@ -263,37 +262,38 @@ public class PlayerController : Script
|
||||||
//press and hold jump
|
//press and hold jump
|
||||||
private void Jump()
|
private void Jump()
|
||||||
{
|
{
|
||||||
if (currentState == RaccoonStates.WALKING || currentState == RaccoonStates.RUNNING || currentState == RaccoonStates.IDILE)
|
if (currentState == RaccoonStates.WALKING || currentState == RaccoonStates.RUNNING || currentState == RaccoonStates.IDLE)
|
||||||
{
|
{
|
||||||
if (Input.GetKeyDown(Input.KeyCode.Space) && isGrounded && rb != null)
|
if (Input.GetKeyDown(Input.KeyCode.Space) && isGrounded && rb != null)
|
||||||
{
|
{
|
||||||
currentState = RaccoonStates.JUMP;
|
currentState = RaccoonStates.JUMP;
|
||||||
Vector3 v = rb.LinearVelocity;
|
Vector3 v = rb.LinearVelocity;
|
||||||
v.y = initialJumpVel * 0.5f;
|
v.y = initialJumpVel * 0.5f;
|
||||||
if (pat != null && pat.item.GetScript<Item>() != null && holdItem)
|
if (holdItem && pat != null && pat.item.GetScript<Item>() != null)
|
||||||
{
|
{
|
||||||
Item item = pat.item.GetScript<Item>();
|
Item item = pat.item.GetScript<Item>();
|
||||||
if (item.currCategory == ItemCategory.LIGHT)
|
if (item != null && item.currCategory == ItemCategory.LIGHT)
|
||||||
v.y *= lightMultiper;
|
v.y *= lightMultiper;
|
||||||
if (item.currCategory == ItemCategory.MEDIUM)
|
if (item != null && item.currCategory == ItemCategory.MEDIUM)
|
||||||
v.y *= mediumMultiper;
|
v.y *= mediumMultiper;
|
||||||
if (item.currCategory == ItemCategory.HEAVY)
|
if (item != null && item.currCategory == ItemCategory.HEAVY)
|
||||||
v.y *= heavyMultiper;
|
v.y *= heavyMultiper;
|
||||||
}
|
}
|
||||||
rb.LinearVelocity = v;
|
rb.LinearVelocity = v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(rb != null && !isGrounded && (rb.LinearVelocity.y < 0.0f || Input.GetKeyUp(Input.KeyCode.Space)))
|
if(!isGrounded && rb != null && (rb.LinearVelocity.y < 0.0f || Input.GetKeyUp(Input.KeyCode.Space)))
|
||||||
currentState = RaccoonStates.FALLING;
|
currentState = RaccoonStates.FALLING;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Rotation()
|
private void Rotation()
|
||||||
{
|
{
|
||||||
Vector3 poitionToLookAt;
|
Vector3 poitionToLookAt;
|
||||||
poitionToLookAt.x = xAxisMove;
|
poitionToLookAt.x = axisMove.x;
|
||||||
poitionToLookAt.y = 0.0f;
|
poitionToLookAt.y = 0.0f;
|
||||||
poitionToLookAt.z = zAxisMove;
|
poitionToLookAt.z = axisMove.y;
|
||||||
|
|
||||||
if (tranform != null)
|
if (tranform != null)
|
||||||
{
|
{
|
||||||
|
@ -312,7 +312,11 @@ public class PlayerController : Script
|
||||||
{
|
{
|
||||||
//check player vel.y if its close to zero its on the ground
|
//check player vel.y if its close to zero its on the ground
|
||||||
if (SHADE.Math.CompareFloat(rb.LinearVelocity.y, 0.0f))
|
if (SHADE.Math.CompareFloat(rb.LinearVelocity.y, 0.0f))
|
||||||
|
{
|
||||||
isGrounded = true;
|
isGrounded = true;
|
||||||
|
if (currentState == RaccoonStates.FALLING)
|
||||||
|
currentState = RaccoonStates.LANDED;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
isGrounded = false;
|
isGrounded = false;
|
||||||
|
|
||||||
|
@ -344,7 +348,9 @@ public class PlayerController : Script
|
||||||
{
|
{
|
||||||
if (currentState == RaccoonStates.CAUGHT && tranform != null)
|
if (currentState == RaccoonStates.CAUGHT && tranform != null)
|
||||||
{
|
{
|
||||||
currentState = RaccoonStates.IDILE;
|
currentState = RaccoonStates.IDLE;
|
||||||
|
if (stateMachine && !stateMachine.IsState(typeof(IdleState)))
|
||||||
|
stateMachine.SetState(typeof(IdleState));
|
||||||
tranform.LocalPosition = new Vector3(-3.0f, -2.0f, -5.0f);
|
tranform.LocalPosition = new Vector3(-3.0f, -2.0f, -5.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -353,6 +359,82 @@ public class PlayerController : Script
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public class WalkState : BaseState
|
||||||
|
{
|
||||||
|
public WalkState(StateMachine stateMachine) : base(stateMachine)
|
||||||
|
{
|
||||||
|
stateName = "Walk State";
|
||||||
|
}
|
||||||
|
public override void OnEnter()
|
||||||
|
{
|
||||||
|
//Debug.Log("WALK ENTER");
|
||||||
|
}
|
||||||
|
public override void update()
|
||||||
|
{
|
||||||
|
//Debug.Log("WALKING");
|
||||||
|
}
|
||||||
|
public override void fixedUpdate()
|
||||||
|
{
|
||||||
|
//Debug.Log("FIXED WALKING");
|
||||||
|
}
|
||||||
|
public override void OnExit()
|
||||||
|
{
|
||||||
|
//Debug.Log("WALK EXIT");
|
||||||
|
}
|
||||||
|
public override void onTriggerEnter(CollisionInfo info)
|
||||||
|
{
|
||||||
|
//Debug.Log("TRIGGER");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class RunState : BaseState
|
||||||
|
{
|
||||||
|
public RunState(StateMachine stateMachine) : base(stateMachine)
|
||||||
|
{
|
||||||
|
stateName = "Run State";
|
||||||
|
}
|
||||||
|
public override void OnEnter()
|
||||||
|
{
|
||||||
|
//Debug.Log("Run ENTER");
|
||||||
|
}
|
||||||
|
public override void update()
|
||||||
|
{
|
||||||
|
//Debug.Log("RUNING");
|
||||||
|
}
|
||||||
|
public override void fixedUpdate()
|
||||||
|
{
|
||||||
|
//Debug.Log("FIXED RUNNING");
|
||||||
|
}
|
||||||
|
public override void OnExit()
|
||||||
|
{
|
||||||
|
//Debug.Log("Run EXIT");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class IdleState : BaseState
|
||||||
|
{
|
||||||
|
public IdleState(StateMachine stateMachine) : base(stateMachine)
|
||||||
|
{
|
||||||
|
stateName = "Idle State";
|
||||||
|
}
|
||||||
|
public override void OnEnter()
|
||||||
|
{
|
||||||
|
//Debug.Log("IDLE ENTER");
|
||||||
|
}
|
||||||
|
public override void update()
|
||||||
|
{
|
||||||
|
//Debug.Log("IDLING");
|
||||||
|
}
|
||||||
|
public override void fixedUpdate()
|
||||||
|
{
|
||||||
|
//Debug.Log("FIXED IDLING");
|
||||||
|
}
|
||||||
|
public override void OnExit()
|
||||||
|
{
|
||||||
|
//Debug.Log("IDLE EXIT");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
Name: SC_PlayerController
|
||||||
|
ID: 160432754
|
||||||
|
Type: 9
|
|
@ -0,0 +1,21 @@
|
||||||
|
using SHADE;
|
||||||
|
using System;
|
||||||
|
public class ScoringZone : Script
|
||||||
|
{
|
||||||
|
public GameManager gameManger { get; set; }
|
||||||
|
|
||||||
|
protected override void awake()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void onTriggerEnter(CollisionInfo info)
|
||||||
|
{
|
||||||
|
if (gameManger && info.GameObject.GetScript<Item>())
|
||||||
|
{
|
||||||
|
gameManger.Score += info.GameObject.GetScript<Item>().Score;
|
||||||
|
gameManger.totalItemCount -= 1;
|
||||||
|
info.GameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
Name: SC_ScoringZone
|
||||||
|
ID: 153171688
|
||||||
|
Type: 9
|
|
@ -0,0 +1,68 @@
|
||||||
|
using SHADE;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
public abstract class BaseState
|
||||||
|
{
|
||||||
|
|
||||||
|
protected string stateName = "Base State";
|
||||||
|
protected StateMachine machine;
|
||||||
|
protected string animationName = "";
|
||||||
|
|
||||||
|
public BaseState(StateMachine stateMachine, string animName = "")
|
||||||
|
{
|
||||||
|
machine = stateMachine;
|
||||||
|
animationName = animName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnEnter()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void update();
|
||||||
|
|
||||||
|
public abstract void fixedUpdate();
|
||||||
|
|
||||||
|
public virtual void OnExit()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetStateName()
|
||||||
|
{
|
||||||
|
return stateName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetAnimName()
|
||||||
|
{
|
||||||
|
return animationName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual float GetAnimPercent()
|
||||||
|
{
|
||||||
|
return 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void onCollisionEnter(CollisionInfo info)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void onCollisionStay(CollisionInfo info)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void onCollisionExit(CollisionInfo info)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void onTriggerEnter(CollisionInfo info)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void onTriggerStay(CollisionInfo info)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void onTriggerExit(CollisionInfo info)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
Name: UT_BaseSate
|
||||||
|
ID: 154709755
|
||||||
|
Type: 9
|
|
@ -0,0 +1,126 @@
|
||||||
|
using SHADE;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
public class StateMachine : Script
|
||||||
|
{
|
||||||
|
private Dictionary<Type, BaseState> stateDictionary;
|
||||||
|
public BaseState currentState = null;
|
||||||
|
public string currentStateName;
|
||||||
|
public string currentAnimName;
|
||||||
|
|
||||||
|
public void InitStateMachine(Dictionary<Type, BaseState> dictionary)
|
||||||
|
{
|
||||||
|
|
||||||
|
stateDictionary = dictionary;
|
||||||
|
currentState = stateDictionary.First().Value;
|
||||||
|
currentStateName = currentState.GetStateName();
|
||||||
|
currentAnimName = currentState.GetAnimName();
|
||||||
|
currentState.OnEnter();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HasState(Type type)
|
||||||
|
{
|
||||||
|
if (!type.IsSubclassOf(typeof(BaseState)))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return stateDictionary.ContainsKey(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetState(Type type)
|
||||||
|
{
|
||||||
|
if (!type.IsSubclassOf(typeof(BaseState)))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (stateDictionary.ContainsKey(type))
|
||||||
|
{
|
||||||
|
currentState.OnExit();
|
||||||
|
currentState = stateDictionary[type];
|
||||||
|
currentState.OnEnter();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetState(stateDictionary.First().Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public BaseState GetState(Type type)
|
||||||
|
{
|
||||||
|
if (!stateDictionary.ContainsKey(type))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return stateDictionary[type];
|
||||||
|
}
|
||||||
|
public bool IsState(Type type)
|
||||||
|
{
|
||||||
|
return (currentState.GetType() == type);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void update()
|
||||||
|
{
|
||||||
|
if (currentState != (null))
|
||||||
|
{
|
||||||
|
currentStateName = currentState.GetStateName();
|
||||||
|
currentAnimName = currentState.GetAnimName();
|
||||||
|
currentState.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void fixedUpdate()
|
||||||
|
{
|
||||||
|
if (currentState != (null))
|
||||||
|
{
|
||||||
|
currentStateName = currentState.GetStateName();
|
||||||
|
currentAnimName = currentState.GetAnimName();
|
||||||
|
currentState.fixedUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void onCollisionEnter(CollisionInfo info)
|
||||||
|
{
|
||||||
|
if (currentState != (null))
|
||||||
|
currentState.onCollisionEnter(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void onCollisionStay(CollisionInfo info)
|
||||||
|
{
|
||||||
|
if (currentState != (null))
|
||||||
|
currentState.onCollisionStay(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void onCollisionExit(CollisionInfo info)
|
||||||
|
{
|
||||||
|
if (currentState != (null))
|
||||||
|
currentState.onCollisionExit(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void onTriggerEnter(CollisionInfo info)
|
||||||
|
{
|
||||||
|
if (currentState != (null))
|
||||||
|
currentState.onTriggerEnter(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void onTriggerStay(CollisionInfo info)
|
||||||
|
{
|
||||||
|
if (currentState != (null))
|
||||||
|
currentState.onTriggerStay(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void onTriggerExit(CollisionInfo info)
|
||||||
|
{
|
||||||
|
if (currentState != (null))
|
||||||
|
currentState.onTriggerExit(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
Name: UT_StateMachine
|
||||||
|
ID: 166010611
|
||||||
|
Type: 9
|
|
@ -186,6 +186,12 @@ namespace Sandbox
|
||||||
drawColliders = !drawColliders;
|
drawColliders = !drawColliders;
|
||||||
SHSystemManager::GetSystem<SHPhysicsDebugDrawSystem>()->SetDebugDrawFlag(SHPhysicsDebugDrawSystem::DebugDrawFlags::COLLIDER, drawColliders);
|
SHSystemManager::GetSystem<SHPhysicsDebugDrawSystem>()->SetDebugDrawFlag(SHPhysicsDebugDrawSystem::DebugDrawFlags::COLLIDER, drawColliders);
|
||||||
}
|
}
|
||||||
|
static bool drawRays = false;
|
||||||
|
if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::F11))
|
||||||
|
{
|
||||||
|
drawRays = !drawRays;
|
||||||
|
SHSystemManager::GetSystem<SHPhysicsDebugDrawSystem>()->SetDebugDrawFlag(SHPhysicsDebugDrawSystem::DebugDrawFlags::RAYCASTS, drawRays);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Finish all graphics jobs first
|
// Finish all graphics jobs first
|
||||||
graphicsSystem->AwaitGraphicsExecution();
|
graphicsSystem->AwaitGraphicsExecution();
|
||||||
|
|
|
@ -50,6 +50,9 @@ project "SHADE_CSharp"
|
||||||
function platformsElementCS(cfg)
|
function platformsElementCS(cfg)
|
||||||
_p(2,'<Platforms>x64</Platforms>')
|
_p(2,'<Platforms>x64</Platforms>')
|
||||||
end
|
end
|
||||||
|
function configElementCS(cfg)
|
||||||
|
_p(2,'<Configurations>Debug;Release;Publish</Configurations>')
|
||||||
|
end
|
||||||
function docsElementCS(cfg)
|
function docsElementCS(cfg)
|
||||||
_p(2,'<GenerateDocumentationFile>true</GenerateDocumentationFile>')
|
_p(2,'<GenerateDocumentationFile>true</GenerateDocumentationFile>')
|
||||||
end
|
end
|
||||||
|
@ -59,6 +62,6 @@ project "SHADE_CSharp"
|
||||||
|
|
||||||
premake.override(premake.vstudio.cs2005.elements, "projectProperties", function (oldfn, cfg)
|
premake.override(premake.vstudio.cs2005.elements, "projectProperties", function (oldfn, cfg)
|
||||||
return table.join(oldfn(cfg), {
|
return table.join(oldfn(cfg), {
|
||||||
platformsElementCS, docsElementCS, docsLocationElementCS,
|
platformsElementCS, configElementCS, docsElementCS, docsLocationElementCS,
|
||||||
})
|
})
|
||||||
end)
|
end)
|
|
@ -84,12 +84,32 @@ namespace SHADE
|
||||||
LoadBank((AUDIO_FOLDER_PATH + "Master.bank").data());
|
LoadBank((AUDIO_FOLDER_PATH + "Master.bank").data());
|
||||||
LoadBank((AUDIO_FOLDER_PATH + "Master.strings.bank").data());
|
LoadBank((AUDIO_FOLDER_PATH + "Master.strings.bank").data());
|
||||||
//LoadBank((AUDIO_FOLDER_PATH + "Music.bank").data());
|
//LoadBank((AUDIO_FOLDER_PATH + "Music.bank").data());
|
||||||
LoadBank((AUDIO_FOLDER_PATH + "footsteps.bank").data());
|
//LoadBank((AUDIO_FOLDER_PATH + "footsteps.bank").data());
|
||||||
|
LoadBank((AUDIO_FOLDER_PATH + "Music.bank").data());
|
||||||
|
LoadBank((AUDIO_FOLDER_PATH + "SFX.bank").data());
|
||||||
|
LoadBank((AUDIO_FOLDER_PATH + "UI.bank").data());
|
||||||
|
|
||||||
//auto clip = CreateAudioClip("event:/Characters/sfx_footsteps_human");
|
//auto clip = CreateAudioClip("event:/Characters/sfx_footsteps_human");
|
||||||
//clip->Play();
|
//clip->Play();
|
||||||
//PlayEventOnce("event:/Characters/sfx_footsteps_raccoon");
|
//PlayEventOnce("event:/Characters/sfx_footsteps_raccoon");
|
||||||
//PlayEventOnce("event:/SFX/Dawn/Dawn_Attack");
|
//PlayEventOnce("event:/SFX/Dawn/Dawn_Attack");
|
||||||
|
|
||||||
|
#ifdef SHEDITOR
|
||||||
|
|
||||||
|
// Subscribe to Editor State Change Events
|
||||||
|
const std::shared_ptr ON_PLAY_RECEIVER{ std::make_shared<SHEventReceiverSpec<SHAudioSystem>>(this, &SHAudioSystem::onPlay) };
|
||||||
|
const ReceiverPtr ON_PLAY_RECEIVER_PTR = std::dynamic_pointer_cast<SHEventReceiver>(ON_PLAY_RECEIVER);
|
||||||
|
SHEventManager::SubscribeTo(SH_EDITOR_ON_PLAY_EVENT, ON_PLAY_RECEIVER_PTR);
|
||||||
|
|
||||||
|
const std::shared_ptr ON_STOP_RECEIVER{ std::make_shared<SHEventReceiverSpec<SHAudioSystem>>(this, &SHAudioSystem::onStop) };
|
||||||
|
const ReceiverPtr ON_STOP_RECEIVER_PTR = std::dynamic_pointer_cast<SHEventReceiver>(ON_STOP_RECEIVER);
|
||||||
|
SHEventManager::SubscribeTo(SH_EDITOR_ON_STOP_EVENT, ON_STOP_RECEIVER_PTR);
|
||||||
|
|
||||||
|
const std::shared_ptr ON_PAUSE_RECEIVER{ std::make_shared<SHEventReceiverSpec<SHAudioSystem>>(this, &SHAudioSystem::onPause) };
|
||||||
|
const ReceiverPtr ON_PAUSE_RECEIVER_PTR = std::dynamic_pointer_cast<SHEventReceiver>(ON_PAUSE_RECEIVER);
|
||||||
|
SHEventManager::SubscribeTo(SH_EDITOR_ON_PAUSE_EVENT, ON_PAUSE_RECEIVER_PTR);
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHADE::SHAudioSystem::Run(double dt)
|
void SHADE::SHAudioSystem::Run(double dt)
|
||||||
|
@ -179,7 +199,6 @@ namespace SHADE
|
||||||
it->second->createInstance(&event);
|
it->second->createInstance(&event);
|
||||||
if (event)
|
if (event)
|
||||||
{
|
{
|
||||||
|
|
||||||
event->setVolume(masterVolume * (isSFX ? sfxVolume : bgmVolume));
|
event->setVolume(masterVolume * (isSFX ? sfxVolume : bgmVolume));
|
||||||
if (spatial)
|
if (spatial)
|
||||||
{
|
{
|
||||||
|
@ -285,6 +304,7 @@ namespace SHADE
|
||||||
if (channel->isPlaying(&isPlaying) == FMOD_OK && isPlaying)
|
if (channel->isPlaying(&isPlaying) == FMOD_OK && isPlaying)
|
||||||
channel->stop();
|
channel->stop();
|
||||||
}
|
}
|
||||||
|
masterGroup->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<FMOD_GUID> SHAudioSystem::GetEventGUID(const char* path)
|
std::optional<FMOD_GUID> SHAudioSystem::GetEventGUID(const char* path)
|
||||||
|
@ -410,6 +430,7 @@ namespace SHADE
|
||||||
void SHAudioSystem::SetPaused(bool pause)
|
void SHAudioSystem::SetPaused(bool pause)
|
||||||
{
|
{
|
||||||
paused = pause;
|
paused = pause;
|
||||||
|
masterGroup->setPaused(pause);
|
||||||
for (auto const& channel : audioChannels)
|
for (auto const& channel : audioChannels)
|
||||||
{
|
{
|
||||||
channel->setPaused(paused);
|
channel->setPaused(paused);
|
||||||
|
@ -552,6 +573,27 @@ namespace SHADE
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SHEventHandle SHAudioSystem::onStop(SHEventPtr onStopEvent)
|
||||||
|
{
|
||||||
|
StopAllSounds();
|
||||||
|
|
||||||
|
return onStopEvent->handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
SHEventHandle SHAudioSystem::onPause(SHEventPtr onStopEvent)
|
||||||
|
{
|
||||||
|
SetPaused(true);
|
||||||
|
|
||||||
|
return onStopEvent->handle;
|
||||||
|
}
|
||||||
|
SHEventHandle SHAudioSystem::onPlay(SHEventPtr onStopEvent)
|
||||||
|
{
|
||||||
|
if(GetPaused())
|
||||||
|
SetPaused(false);
|
||||||
|
|
||||||
|
return onStopEvent->handle;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
#include "Math/Vector/SHVec3.h"
|
#include "Math/Vector/SHVec3.h"
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <FMOD/fmod_studio.hpp>
|
#include <FMOD/fmod_studio.hpp>
|
||||||
|
#include "Events/SHEvent.h"
|
||||||
|
|
||||||
#include "SH_API.h"
|
#include "SH_API.h"
|
||||||
#define AUDIO_SYS_MAX_CHANNELS 1024
|
#define AUDIO_SYS_MAX_CHANNELS 1024
|
||||||
|
|
||||||
|
@ -104,6 +106,10 @@ namespace SHADE
|
||||||
|
|
||||||
std::vector<SHAudioListenerComponent>* denseListener;
|
std::vector<SHAudioListenerComponent>* denseListener;
|
||||||
AudioClipID clipID = 0;
|
AudioClipID clipID = 0;
|
||||||
|
|
||||||
|
SHEventHandle onPlay(SHEventPtr onStopEvent);
|
||||||
|
SHEventHandle onStop(SHEventPtr onStopEvent);
|
||||||
|
SHEventHandle onPause(SHEventPtr onStopEvent);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "UI/SHUIComponent.h"
|
#include "UI/SHUIComponent.h"
|
||||||
#include "UI/SHCanvasComponent.h"
|
#include "UI/SHCanvasComponent.h"
|
||||||
#include "SHEditorComponentView.h"
|
#include "SHEditorComponentView.h"
|
||||||
|
#include "AudioSystem/SHAudioListenerComponent.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -130,7 +131,8 @@ namespace SHADE
|
||||||
if (auto cameraComponent = SHComponentManager::GetComponent_s<SHCameraComponent>(eid))
|
if (auto cameraComponent = SHComponentManager::GetComponent_s<SHCameraComponent>(eid))
|
||||||
{
|
{
|
||||||
DrawComponent(cameraComponent);
|
DrawComponent(cameraComponent);
|
||||||
}if (auto cameraArmComponent = SHComponentManager::GetComponent_s<SHCameraArmComponent>(eid))
|
}
|
||||||
|
if (auto cameraArmComponent = SHComponentManager::GetComponent_s<SHCameraArmComponent>(eid))
|
||||||
{
|
{
|
||||||
DrawComponent(cameraArmComponent);
|
DrawComponent(cameraArmComponent);
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,7 +174,6 @@ namespace SHADE
|
||||||
bool shaderChanged = false;
|
bool shaderChanged = false;
|
||||||
const auto* SHADER_INFO = SHAssetManager::GetData<SHShaderAsset>(currentMatSpec->fragShader);
|
const auto* SHADER_INFO = SHAssetManager::GetData<SHShaderAsset>(currentMatSpec->fragShader);
|
||||||
const std::string SHADER_NAME = SHADER_INFO ? SHADER_INFO->name : "Unknown Shader";
|
const std::string SHADER_NAME = SHADER_INFO ? SHADER_INFO->name : "Unknown Shader";
|
||||||
ImGui::BeginDisabled();
|
|
||||||
isDirty |= SHEditorWidgets::DragDropReadOnlyField<AssetID>
|
isDirty |= SHEditorWidgets::DragDropReadOnlyField<AssetID>
|
||||||
(
|
(
|
||||||
"Fragment Shader", SHADER_NAME.data(),
|
"Fragment Shader", SHADER_NAME.data(),
|
||||||
|
@ -182,7 +181,6 @@ namespace SHADE
|
||||||
[this](const AssetID& id) { currentMatSpec->fragShader = id; },
|
[this](const AssetID& id) { currentMatSpec->fragShader = id; },
|
||||||
SHDragDrop::DRAG_RESOURCE
|
SHDragDrop::DRAG_RESOURCE
|
||||||
);
|
);
|
||||||
ImGui::EndDisabled();
|
|
||||||
|
|
||||||
// Load the shader to access it's data
|
// Load the shader to access it's data
|
||||||
auto fragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(currentMatSpec->fragShader);
|
auto fragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(currentMatSpec->fragShader);
|
||||||
|
|
|
@ -27,6 +27,7 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include "Math/Transform/SHTransformComponent.h"
|
#include "Math/Transform/SHTransformComponent.h"
|
||||||
#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h"
|
#include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h"
|
||||||
#include "Graphics/Descriptors/SHVkDescriptorPool.h"
|
#include "Graphics/Descriptors/SHVkDescriptorPool.h"
|
||||||
|
#include "Scene/SHSceneManager.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -49,7 +50,7 @@ namespace SHADE
|
||||||
, referencedMatInstances { std::move(rhs.referencedMatInstances) }
|
, referencedMatInstances { std::move(rhs.referencedMatInstances) }
|
||||||
, matBufferDirty { std::move(rhs.matBufferDirty) }
|
, matBufferDirty { std::move(rhs.matBufferDirty) }
|
||||||
, subBatches { std::move(rhs.subBatches) }
|
, subBatches { std::move(rhs.subBatches) }
|
||||||
, drawData { std::move(drawData) }
|
, drawData { std::move(rhs.drawData) }
|
||||||
, transformData { std::move(rhs.transformData) }
|
, transformData { std::move(rhs.transformData) }
|
||||||
, instancedIntegerData { std::move(rhs.instancedIntegerData) }
|
, instancedIntegerData { std::move(rhs.instancedIntegerData) }
|
||||||
, matPropsData { std::move(rhs.matPropsData) }
|
, matPropsData { std::move(rhs.matPropsData) }
|
||||||
|
@ -80,7 +81,7 @@ namespace SHADE
|
||||||
referencedMatInstances = std::move(rhs.referencedMatInstances);
|
referencedMatInstances = std::move(rhs.referencedMatInstances);
|
||||||
matBufferDirty = std::move(rhs.matBufferDirty) ;
|
matBufferDirty = std::move(rhs.matBufferDirty) ;
|
||||||
subBatches = std::move(rhs.subBatches) ;
|
subBatches = std::move(rhs.subBatches) ;
|
||||||
drawData = std::move(drawData) ;
|
drawData = std::move(rhs.drawData) ;
|
||||||
transformData = std::move(rhs.transformData) ;
|
transformData = std::move(rhs.transformData) ;
|
||||||
instancedIntegerData = std::move(rhs.instancedIntegerData) ;
|
instancedIntegerData = std::move(rhs.instancedIntegerData) ;
|
||||||
matPropsData = std::move(rhs.matPropsData) ;
|
matPropsData = std::move(rhs.matPropsData) ;
|
||||||
|
@ -218,9 +219,13 @@ namespace SHADE
|
||||||
for (int i = 0; i < SHGraphicsConstants::NUM_FRAME_BUFFERS; ++i)
|
for (int i = 0; i < SHGraphicsConstants::NUM_FRAME_BUFFERS; ++i)
|
||||||
{
|
{
|
||||||
drawDataBuffer[i].Free();
|
drawDataBuffer[i].Free();
|
||||||
|
drawDataBuffer[i] = {};
|
||||||
transformDataBuffer[i].Free();
|
transformDataBuffer[i].Free();
|
||||||
|
transformDataBuffer[i] = {};
|
||||||
instancedIntegerBuffer[i].Free();
|
instancedIntegerBuffer[i].Free();
|
||||||
|
instancedIntegerBuffer[i] = {};
|
||||||
matPropsBuffer[i].Free();
|
matPropsBuffer[i].Free();
|
||||||
|
matPropsBuffer[i] = {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,10 +306,25 @@ namespace SHADE
|
||||||
// Transform
|
// Transform
|
||||||
auto transform = SHComponentManager::GetComponent<SHTransformComponent>(rendId);
|
auto transform = SHComponentManager::GetComponent<SHTransformComponent>(rendId);
|
||||||
if (transform)
|
if (transform)
|
||||||
|
{
|
||||||
|
if (SHSceneManager::CheckNodeAndComponentsActive<SHRenderable>(rendId))
|
||||||
{
|
{
|
||||||
transformData.emplace_back(transform->GetTRS());
|
transformData.emplace_back(transform->GetTRS());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
// Should be deactivated
|
||||||
|
static const SHMatrix ZERO_MTX =
|
||||||
|
{
|
||||||
|
0.0f, 0.0f, 0.0f, 0.0f,
|
||||||
|
0.0f, 0.0f, 0.0f, 0.0f,
|
||||||
|
0.0f, 0.0f, 0.0f, 0.0f,
|
||||||
|
0.0f, 0.0f, 0.0f, 0.0f
|
||||||
|
};
|
||||||
|
transformData.emplace_back(ZERO_MTX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
SHLOG_WARNING("[SHBatch] Entity contianing a SHRenderable with no SHTransformComponent found!");
|
SHLOG_WARNING("[SHBatch] Entity contianing a SHRenderable with no SHTransformComponent found!");
|
||||||
transformData.emplace_back();
|
transformData.emplace_back();
|
||||||
|
@ -425,14 +445,29 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
// Transform
|
// Transform
|
||||||
auto transform = SHComponentManager::GetComponent_s<SHTransformComponent>(rendId);
|
auto transform = SHComponentManager::GetComponent_s<SHTransformComponent>(rendId);
|
||||||
if (!transform)
|
if (transform)
|
||||||
{
|
{
|
||||||
SHLOG_WARNING("[SHBatch] Entity contianing a SHRenderable with no SHTransformComponent found!");
|
if (SHSceneManager::CheckNodeAndComponentsActive<SHRenderable>(rendId))
|
||||||
transformData.emplace_back();
|
{
|
||||||
|
transformData.emplace_back(transform->GetTRS());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
transformData.emplace_back(transform->GetTRS());
|
// Should be deactivated
|
||||||
|
static const SHMatrix ZERO_MTX =
|
||||||
|
{
|
||||||
|
0.0f, 0.0f, 0.0f, 0.0f,
|
||||||
|
0.0f, 0.0f, 0.0f, 0.0f,
|
||||||
|
0.0f, 0.0f, 0.0f, 0.0f,
|
||||||
|
0.0f, 0.0f, 0.0f, 0.0f
|
||||||
|
};
|
||||||
|
transformData.emplace_back(ZERO_MTX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SHLOG_WARNING("[SHBatch] Entity contianing a SHRenderable with no SHTransformComponent found!");
|
||||||
|
transformData.emplace_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
const SHRenderable* renderable = SHComponentManager::GetComponent<SHRenderable>(rendId);
|
const SHRenderable* renderable = SHComponentManager::GetComponent<SHRenderable>(rendId);
|
||||||
|
@ -507,9 +542,13 @@ namespace SHADE
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Nothing to draw
|
||||||
|
if (subBatches.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
// Bind all required objects before drawing
|
// Bind all required objects before drawing
|
||||||
static std::array<uint32_t, 1> dynamicOffset{ 0 };
|
static std::array<uint32_t, 1> dynamicOffset{ 0 };
|
||||||
cmdBuffer->BeginLabeledSegment("SHBatch");
|
cmdBuffer->BeginLabeledSegment("SHBatch for Pipeline #" + std::to_string(pipeline.GetId().Data.Index));
|
||||||
cmdBuffer->BindPipeline(pipeline);
|
cmdBuffer->BindPipeline(pipeline);
|
||||||
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::TRANSFORM, transformDataBuffer[frameIndex], 0);
|
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::TRANSFORM, transformDataBuffer[frameIndex], 0);
|
||||||
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::INTEGER_DATA, instancedIntegerBuffer[frameIndex], 0);
|
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::INTEGER_DATA, instancedIntegerBuffer[frameIndex], 0);
|
||||||
|
|
|
@ -55,7 +55,8 @@ namespace SHADE
|
||||||
|
|
||||||
void SHSuperBatch::Remove(const SHRenderable* renderable) noexcept
|
void SHSuperBatch::Remove(const SHRenderable* renderable) noexcept
|
||||||
{
|
{
|
||||||
const Handle<SHVkPipeline> PIPELINE = renderable->GetMaterial()->GetBaseMaterial()->GetPipeline();
|
Handle<SHMaterial> baseMat = renderable->GetMaterial()->GetBaseMaterial();
|
||||||
|
const Handle<SHVkPipeline> PIPELINE = baseMat->HasPipelineChanged() ? baseMat->GetPrevPipeline() : baseMat->GetPipeline();
|
||||||
|
|
||||||
// Check if we have a Batch with the same pipeline yet
|
// Check if we have a Batch with the same pipeline yet
|
||||||
auto batch = std::find_if(batches.begin(), batches.end(), [&](const SHBatch& batch)
|
auto batch = std::find_if(batches.begin(), batches.end(), [&](const SHBatch& batch)
|
||||||
|
|
|
@ -971,7 +971,9 @@ namespace SHADE
|
||||||
Handle<SHMaterialInstance> prevMaterial = renderable.HasMaterialChanged() ? renderable.GetPrevMaterial() : renderable.GetMaterial();
|
Handle<SHMaterialInstance> prevMaterial = renderable.HasMaterialChanged() ? renderable.GetPrevMaterial() : renderable.GetMaterial();
|
||||||
if (prevMaterial)
|
if (prevMaterial)
|
||||||
{
|
{
|
||||||
Handle<SHSuperBatch> oldSuperBatch = prevMaterial->GetBaseMaterial()->GetPipeline()->GetPipelineState().GetSubpass()->GetSuperBatch();
|
Handle<SHMaterial> baseMat = prevMaterial->GetBaseMaterial();
|
||||||
|
Handle<SHVkPipeline> prevPipeline = baseMat->HasPipelineChanged() ? baseMat->GetPrevPipeline() : baseMat->GetPipeline();
|
||||||
|
Handle<SHSuperBatch> oldSuperBatch = prevPipeline->GetPipelineState().GetSubpass()->GetSuperBatch();
|
||||||
oldSuperBatch->Remove(&renderable);
|
oldSuperBatch->Remove(&renderable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -986,6 +988,14 @@ namespace SHADE
|
||||||
// Unset change flag
|
// Unset change flag
|
||||||
renderable.ResetChangedFlag();
|
renderable.ResetChangedFlag();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unset all material old pipeline since we would have finished processing
|
||||||
|
auto gfxSystem = reinterpret_cast<SHGraphicsSystem*>(system);
|
||||||
|
auto [matBegin, matEnd] = gfxSystem->resourceManager.GetDenseAccess<SHMaterial>();
|
||||||
|
for (auto iter = matBegin; iter != matEnd; ++iter)
|
||||||
|
{
|
||||||
|
iter->ForgetOldPipeline();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#pragma endregion ROUTINES
|
#pragma endregion ROUTINES
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,8 @@ namespace SHADE
|
||||||
if (_pipeline == pipeline)
|
if (_pipeline == pipeline)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Mark old pipeline and set new pipeline
|
||||||
|
oldPipeline = pipeline;
|
||||||
pipeline = _pipeline;
|
pipeline = _pipeline;
|
||||||
|
|
||||||
// Set up properties based on the pipeline
|
// Set up properties based on the pipeline
|
||||||
|
@ -41,9 +43,6 @@ namespace SHADE
|
||||||
|
|
||||||
// Reset since pipeline changed
|
// Reset since pipeline changed
|
||||||
ResetProperties();
|
ResetProperties();
|
||||||
|
|
||||||
// Mark changed so that we know to update dependent material instances
|
|
||||||
propertiesChanged = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle<SHVkPipeline> SHMaterial::GetPipeline() const
|
Handle<SHVkPipeline> SHMaterial::GetPipeline() const
|
||||||
|
@ -111,4 +110,9 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
propertiesChanged = false;
|
propertiesChanged = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SHMaterial::ForgetOldPipeline() noexcept
|
||||||
|
{
|
||||||
|
oldPipeline = {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ namespace SHADE
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
void SetPipeline(Handle<SHVkPipeline> _pipeline);
|
void SetPipeline(Handle<SHVkPipeline> _pipeline);
|
||||||
Handle<SHVkPipeline> GetPipeline() const;
|
Handle<SHVkPipeline> GetPipeline() const;
|
||||||
|
Handle<SHVkPipeline> GetPrevPipeline() const { return oldPipeline; };
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Property Functions */
|
/* Property Functions */
|
||||||
|
@ -68,10 +69,11 @@ namespace SHADE
|
||||||
/* Query Functions */
|
/* Query Functions */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
Handle<SHShaderBlockInterface> GetShaderBlockInterface() const noexcept;
|
Handle<SHShaderBlockInterface> GetShaderBlockInterface() const noexcept;
|
||||||
bool HasPipelineChanged() const noexcept { return pipelineChanged; }
|
bool HasPipelineChanged() const noexcept { return oldPipeline; }
|
||||||
bool HasPropertiesChanged() const noexcept { return propertiesChanged; }
|
bool HasPropertiesChanged() const noexcept { return propertiesChanged; }
|
||||||
bool HasChanged() const noexcept { return pipelineChanged || propertiesChanged; }
|
bool HasChanged() const noexcept { return oldPipeline || propertiesChanged; }
|
||||||
void ClearChangeFlag() noexcept;
|
void ClearChangeFlag() noexcept;
|
||||||
|
void ForgetOldPipeline() noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
@ -81,7 +83,7 @@ namespace SHADE
|
||||||
std::unique_ptr<char> propMemory;
|
std::unique_ptr<char> propMemory;
|
||||||
Byte propMemorySize = 0;
|
Byte propMemorySize = 0;
|
||||||
bool propertiesChanged = true;
|
bool propertiesChanged = true;
|
||||||
bool pipelineChanged = true;
|
Handle<SHVkPipeline> oldPipeline;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Helper Functions */
|
/* Helper Functions */
|
||||||
|
|
|
@ -129,7 +129,7 @@ namespace SHADE
|
||||||
// Otherwise just copy the data over
|
// Otherwise just copy the data over
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bufferHandle->MapWriteUnmap(src, size, 0, 0);
|
bufferHandle->WriteToMemory(src, size, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -30,11 +30,17 @@ namespace SHADE
|
||||||
, direction { dir }
|
, direction { dir }
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
SHRay::SHRay(const reactphysics3d::Ray rp3dRay) noexcept
|
||||||
|
: position { rp3dRay.point1 }
|
||||||
|
, direction { SHVec3::Normalise(rp3dRay.point2 - rp3dRay.point1) }
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/* Operator Overload Definitions */
|
/* Operator Overload Definitions */
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
bool SHRay::operator==(const SHRay& rhs) noexcept
|
bool SHRay::operator==(const SHRay& rhs) const noexcept
|
||||||
{
|
{
|
||||||
const XMVECTOR LHS_POS = XMLoadFloat3(&position);
|
const XMVECTOR LHS_POS = XMLoadFloat3(&position);
|
||||||
const XMVECTOR RHS_POS = XMLoadFloat3(&rhs.position);
|
const XMVECTOR RHS_POS = XMLoadFloat3(&rhs.position);
|
||||||
|
@ -45,7 +51,7 @@ namespace SHADE
|
||||||
return XMVector3Equal(LHS_POS, RHS_POS) && XMVector3NotEqual(LHS_DIR, RHS_DIR);
|
return XMVector3Equal(LHS_POS, RHS_POS) && XMVector3NotEqual(LHS_DIR, RHS_DIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SHRay::operator!=(const SHRay& rhs) noexcept
|
bool SHRay::operator!=(const SHRay& rhs) const noexcept
|
||||||
{
|
{
|
||||||
const XMVECTOR LHS_POS = XMLoadFloat3(&position);
|
const XMVECTOR LHS_POS = XMLoadFloat3(&position);
|
||||||
const XMVECTOR RHS_POS = XMLoadFloat3(&rhs.position);
|
const XMVECTOR RHS_POS = XMLoadFloat3(&rhs.position);
|
||||||
|
@ -56,5 +62,16 @@ namespace SHADE
|
||||||
return XMVector3NotEqual(LHS_POS, RHS_POS) || XMVector3NotEqual(LHS_DIR, RHS_DIR);
|
return XMVector3NotEqual(LHS_POS, RHS_POS) || XMVector3NotEqual(LHS_DIR, RHS_DIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SHRay::operator reactphysics3d::Ray() const noexcept
|
||||||
|
{
|
||||||
|
// We use 2km. Temp solution.
|
||||||
|
return reactphysics3d::Ray{ position, position + (direction * MAX_RAYCAST_DIST) };
|
||||||
|
}
|
||||||
|
|
||||||
|
SHRaycastResult::operator bool() const noexcept
|
||||||
|
{
|
||||||
|
return hit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace SHADE
|
} // namespace SHADE
|
|
@ -1,7 +1,7 @@
|
||||||
/****************************************************************************************
|
/****************************************************************************************
|
||||||
* \file SHRay.h
|
* \file SHRay.h
|
||||||
* \author Diren D Bharwani, diren.dbharwani, 390002520
|
* \author Diren D Bharwani, diren.dbharwani, 390002520
|
||||||
* \brief Interface for a Ray.
|
* \brief Interface for a Ray & Raycast Result
|
||||||
*
|
*
|
||||||
* \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
* \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||||
* disclosure of this file or its contents without the prior written consent
|
* disclosure of this file or its contents without the prior written consent
|
||||||
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <DirectXMath.h>
|
#include <reactphysics3d/mathematics/Ray.h>
|
||||||
|
|
||||||
// Project Headers
|
// Project Headers
|
||||||
#include "SH_API.h"
|
#include "SH_API.h"
|
||||||
|
@ -29,6 +29,8 @@ namespace SHADE
|
||||||
/* Data Members */
|
/* Data Members */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
static constexpr float MAX_RAYCAST_DIST = 2000.0f; // We use 2km as physics typically tends to lose accuracy beyond 2km.
|
||||||
|
|
||||||
SHVec3 position;
|
SHVec3 position;
|
||||||
SHVec3 direction;
|
SHVec3 direction;
|
||||||
|
|
||||||
|
@ -36,19 +38,46 @@ namespace SHADE
|
||||||
/* Constructors & Destructor */
|
/* Constructors & Destructor */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
SHRay() noexcept;
|
SHRay () noexcept;
|
||||||
SHRay(const SHVec3& pos, const SHVec3& dir) noexcept;
|
SHRay (const SHVec3& pos, const SHVec3& dir) noexcept;
|
||||||
SHRay(const SHRay& rhs) noexcept = default;
|
SHRay (const reactphysics3d::Ray rp3dRay) noexcept;
|
||||||
SHRay(SHRay&& rhs) noexcept = default;
|
|
||||||
|
SHRay (const SHRay&) noexcept = default;
|
||||||
|
SHRay (SHRay&& ) noexcept = default;
|
||||||
|
~SHRay() = default;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Operator Overloads */
|
/* Operator Overloads */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
SHRay& operator= (const SHRay& rhs) noexcept = default;
|
SHRay& operator= (const SHRay&) noexcept = default;
|
||||||
SHRay& operator= (SHRay&& rhs) noexcept = default;
|
SHRay& operator= (SHRay&&) noexcept = default;
|
||||||
|
|
||||||
|
[[nodiscard]] bool operator==(const SHRay& rhs) const noexcept;
|
||||||
|
[[nodiscard]] bool operator!=(const SHRay& rhs) const noexcept;
|
||||||
|
|
||||||
|
operator reactphysics3d::Ray() const noexcept;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SH_API SHRaycastResult
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Data Members */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
bool hit = false;
|
||||||
|
float distance = std::numeric_limits<float>::infinity();
|
||||||
|
float angle = 0.0f;
|
||||||
|
|
||||||
|
SHVec3 position;
|
||||||
|
SHVec3 normal;
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Operator Overloads */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
operator bool() const noexcept;
|
||||||
|
|
||||||
[[nodiscard]] bool operator==(const SHRay& rhs) noexcept;
|
|
||||||
[[nodiscard]] bool operator!=(const SHRay& rhs) noexcept;
|
|
||||||
};
|
};
|
||||||
} // namespace SHADE
|
} // namespace SHADE
|
|
@ -32,7 +32,6 @@ namespace SHADE
|
||||||
class SH_API SHCollisionListener final : public rp3d::EventListener
|
class SH_API SHCollisionListener final : public rp3d::EventListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Constructors & Destructor */
|
/* Constructors & Destructor */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
/****************************************************************************************
|
||||||
|
* \file SHPhysicsRaycastResult.h
|
||||||
|
* \author Diren D Bharwani, diren.dbharwani, 390002520
|
||||||
|
* \brief Interface for a Physics Raycast Result
|
||||||
|
*
|
||||||
|
* \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||||
|
* disclosure of this file or its contents without the prior written consent
|
||||||
|
* of DigiPen Institute of Technology is prohibited.
|
||||||
|
****************************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Project Includes
|
||||||
|
#include "ECS_Base/SHECSMacros.h"
|
||||||
|
#include "Math/SHRay.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Type Definitions */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
struct SH_API SHPhysicsRaycastResult : public SHRaycastResult
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Data Members */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
EntityID entityHit = MAX_EID;
|
||||||
|
int shapeIndex = -1;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
|
@ -0,0 +1,350 @@
|
||||||
|
/****************************************************************************************
|
||||||
|
* \file SHPhysicsRaycaster.cpp
|
||||||
|
* \author Diren D Bharwani, diren.dbharwani, 390002520
|
||||||
|
* \brief Implementation for a Physics Raycaster.
|
||||||
|
*
|
||||||
|
* \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||||
|
* disclosure of this file or its contents without the prior written consent
|
||||||
|
* of DigiPen Institute of Technology is prohibited.
|
||||||
|
****************************************************************************************/
|
||||||
|
|
||||||
|
#include <SHpch.h>
|
||||||
|
|
||||||
|
// Primary Header
|
||||||
|
#include "SHPhysicsRaycaster.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TODO(DIREN):
|
||||||
|
* Once the physics engine has been rebuilt, this whole implementation should change
|
||||||
|
* and just call PhysicsWorld.Raycast etc.
|
||||||
|
*
|
||||||
|
* SHRaycastResult can be converted to a bool when necessary.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Constructors & Destructor Definitions */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
SHPhysicsRaycaster::SHPhysicsRaycaster() noexcept
|
||||||
|
: world { nullptr }
|
||||||
|
{}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Getter Function Definitions */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
const SHPhysicsRaycaster::RaycastPairs& SHPhysicsRaycaster::GetRaycasts() const noexcept
|
||||||
|
{
|
||||||
|
return raycasts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Getter Function Definitions */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void SHPhysicsRaycaster::SetObjectManager(SHPhysicsObjectManager* physicsObjectManager) noexcept
|
||||||
|
{
|
||||||
|
objectManager = physicsObjectManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Public Function Member Definitions */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void SHPhysicsRaycaster::BindToWorld(rp3d::PhysicsWorld* physicsWorld) noexcept
|
||||||
|
{
|
||||||
|
world = physicsWorld;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHPhysicsRaycaster::ClearFrame() noexcept
|
||||||
|
{
|
||||||
|
raycasts.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
SHPhysicsRaycastResult SHPhysicsRaycaster::Raycast(const SHRay& ray, float distance) noexcept
|
||||||
|
{
|
||||||
|
// Reset temp
|
||||||
|
temp = SHPhysicsRaycastResult{};
|
||||||
|
temp.distance = distance;
|
||||||
|
|
||||||
|
if (!world)
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Physics world missing for raycasting!")
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If distance in infinity, cast to the default max distance of 2 km.
|
||||||
|
if (distance == std::numeric_limits<float>::infinity())
|
||||||
|
{
|
||||||
|
world->raycast(ray, this);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const SHVec3 END_POINT = ray.position + ray.direction * distance;
|
||||||
|
const rp3d::Ray RP3D_RAY{ ray.position, END_POINT };
|
||||||
|
world->raycast(RP3D_RAY, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If a hit was found, populate temp info for return.
|
||||||
|
if (temp.hit)
|
||||||
|
{
|
||||||
|
temp.distance = SHVec3::Distance(ray.position, temp.position);
|
||||||
|
temp.angle = SHVec3::Angle(ray.position, temp.position);
|
||||||
|
}
|
||||||
|
|
||||||
|
raycasts.emplace_back(ray, temp);
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
SHPhysicsRaycastResult SHPhysicsRaycaster::Linecast(const SHVec3& start, const SHVec3& end) noexcept
|
||||||
|
{
|
||||||
|
temp = SHPhysicsRaycastResult{};
|
||||||
|
temp.distance = SHVec3::Distance(start, end);
|
||||||
|
|
||||||
|
if (!world)
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Physics world missing for raycasting!")
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
const rp3d::Ray RP3D_RAY{ start, end };
|
||||||
|
world->raycast(RP3D_RAY, this);
|
||||||
|
|
||||||
|
if (temp.hit)
|
||||||
|
{
|
||||||
|
temp.distance = SHVec3::Distance(start, temp.position);
|
||||||
|
temp.angle = SHVec3::Angle(start, temp.position);
|
||||||
|
}
|
||||||
|
|
||||||
|
raycasts.emplace_back(RP3D_RAY, temp);
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
SHPhysicsRaycastResult SHPhysicsRaycaster::ColliderRaycast(EntityID eid, const SHRay& ray, float distance) noexcept
|
||||||
|
{
|
||||||
|
SHPhysicsRaycastResult result;
|
||||||
|
result.distance = distance;
|
||||||
|
|
||||||
|
// Get a valid physics object with at least 1 collider.
|
||||||
|
const auto* PHYSICS_OBJECT = validateColliderRaycast(eid);
|
||||||
|
if (!PHYSICS_OBJECT)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
auto* rp3dBody = PHYSICS_OBJECT->GetCollisionBody();
|
||||||
|
|
||||||
|
// Data to populate
|
||||||
|
rp3d::RaycastInfo rp3dRaycastInfo;
|
||||||
|
bool hit = false;
|
||||||
|
|
||||||
|
if (distance == std::numeric_limits<float>::infinity())
|
||||||
|
{
|
||||||
|
hit = rp3dBody->raycast(ray, rp3dRaycastInfo);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const SHVec3 END_POINT = ray.position + ray.direction * distance;
|
||||||
|
const rp3d::Ray RP3D_RAY{ ray.position, END_POINT };
|
||||||
|
hit = rp3dBody->raycast(RP3D_RAY, rp3dRaycastInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hit)
|
||||||
|
{
|
||||||
|
result.hit = true;
|
||||||
|
result.position = rp3dRaycastInfo.worldPoint;
|
||||||
|
result.normal = rp3dRaycastInfo.worldPoint;
|
||||||
|
result.distance = SHVec3::Distance(ray.position, result.position);
|
||||||
|
result.angle = SHVec3::Angle(ray.position, result.position);
|
||||||
|
result.entityHit = eid;
|
||||||
|
result.shapeIndex = findColliderIndex(rp3dBody, rp3dRaycastInfo.collider->getEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
raycasts.emplace_back(ray, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
SHPhysicsRaycastResult SHPhysicsRaycaster::ColliderRaycast(EntityID eid, int shapeIndex, const SHRay& ray, float distance) noexcept
|
||||||
|
{
|
||||||
|
SHPhysicsRaycastResult result;
|
||||||
|
result.distance = distance;
|
||||||
|
|
||||||
|
// Get a valid physics object with at least 1 collider.
|
||||||
|
const auto* PHYSICS_OBJECT = validateColliderRaycast(eid);
|
||||||
|
if (!PHYSICS_OBJECT)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
// Boundary check for shape index
|
||||||
|
if (shapeIndex < 0 || shapeIndex >= static_cast<int>(PHYSICS_OBJECT->GetCollisionBody()->getNbColliders()))
|
||||||
|
{
|
||||||
|
SHLOGV_WARNING("Invalid collision shape index passed in")
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto* rp3dCollider = PHYSICS_OBJECT->GetCollisionBody()->getCollider(shapeIndex);
|
||||||
|
|
||||||
|
rp3d::RaycastInfo rp3dRaycastInfo;
|
||||||
|
bool hit = false;
|
||||||
|
if (distance == std::numeric_limits<float>::infinity())
|
||||||
|
{
|
||||||
|
hit = rp3dCollider->raycast(ray, rp3dRaycastInfo);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const SHVec3 END_POINT = ray.position + ray.direction * distance;
|
||||||
|
const rp3d::Ray RP3D_RAY{ ray.position, END_POINT };
|
||||||
|
hit = rp3dCollider->raycast(RP3D_RAY, rp3dRaycastInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hit)
|
||||||
|
{
|
||||||
|
result.hit = true;
|
||||||
|
result.position = rp3dRaycastInfo.worldPoint;
|
||||||
|
result.normal = rp3dRaycastInfo.worldPoint;
|
||||||
|
result.distance = SHVec3::Distance(ray.position, result.position);
|
||||||
|
result.angle = SHVec3::Angle(ray.position, result.position);
|
||||||
|
result.entityHit = eid;
|
||||||
|
result.shapeIndex = shapeIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
raycasts.emplace_back(ray, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
SHPhysicsRaycastResult SHPhysicsRaycaster::ColliderLinecast(EntityID eid, const SHVec3& start, const SHVec3& end) noexcept
|
||||||
|
{
|
||||||
|
SHPhysicsRaycastResult result;
|
||||||
|
result.distance = SHVec3::Distance(start, end);
|
||||||
|
|
||||||
|
const auto* PHYSICS_OBJECT = validateColliderRaycast(eid);
|
||||||
|
if (!PHYSICS_OBJECT)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
auto* rp3dBody = PHYSICS_OBJECT->GetCollisionBody();
|
||||||
|
|
||||||
|
rp3d::RaycastInfo rp3dRaycastInfo;
|
||||||
|
|
||||||
|
const rp3d::Ray RP3D_RAY{ start, end };
|
||||||
|
if (rp3dBody->raycast(RP3D_RAY, rp3dRaycastInfo))
|
||||||
|
{
|
||||||
|
result.hit = true;
|
||||||
|
result.position = rp3dRaycastInfo.worldPoint;
|
||||||
|
result.normal = rp3dRaycastInfo.worldPoint;
|
||||||
|
result.distance = SHVec3::Distance(start, result.position);
|
||||||
|
result.angle = SHVec3::Angle(end, result.position);
|
||||||
|
result.entityHit = eid;
|
||||||
|
result.shapeIndex = findColliderIndex(rp3dBody, rp3dRaycastInfo.collider->getEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
raycasts.emplace_back(RP3D_RAY, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
SHPhysicsRaycastResult SHPhysicsRaycaster::ColliderLinecast(EntityID eid, int shapeIndex, const SHVec3& start, const SHVec3& end) noexcept
|
||||||
|
{
|
||||||
|
SHPhysicsRaycastResult result;
|
||||||
|
result.distance = SHVec3::Distance(start, end);
|
||||||
|
|
||||||
|
const auto* PHYSICS_OBJECT = validateColliderRaycast(eid);
|
||||||
|
if (!PHYSICS_OBJECT)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
if (shapeIndex < 0 || shapeIndex >= static_cast<int>(PHYSICS_OBJECT->GetCollisionBody()->getNbColliders()))
|
||||||
|
{
|
||||||
|
SHLOGV_WARNING("Invalid collision shape index passed in")
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto* rp3dCollider = PHYSICS_OBJECT->GetCollisionBody()->getCollider(shapeIndex);
|
||||||
|
|
||||||
|
rp3d::RaycastInfo rp3dRaycastInfo;
|
||||||
|
|
||||||
|
const rp3d::Ray RP3D_RAY{ start, end };
|
||||||
|
if (rp3dCollider->raycast(RP3D_RAY, rp3dRaycastInfo))
|
||||||
|
{
|
||||||
|
result.hit = true;
|
||||||
|
result.position = rp3dRaycastInfo.worldPoint;
|
||||||
|
result.normal = rp3dRaycastInfo.worldPoint;
|
||||||
|
result.distance = SHVec3::Distance(start, result.position);
|
||||||
|
result.angle = SHVec3::Angle(end, result.position);
|
||||||
|
result.entityHit = eid;
|
||||||
|
result.shapeIndex = shapeIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
raycasts.emplace_back(RP3D_RAY, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
rp3d::decimal SHPhysicsRaycaster::notifyRaycastHit(const rp3d::RaycastInfo& raycastInfo)
|
||||||
|
{
|
||||||
|
temp.hit = true;
|
||||||
|
temp.position = raycastInfo.worldPoint;
|
||||||
|
temp.normal = raycastInfo.worldNormal;
|
||||||
|
|
||||||
|
if (!objectManager)
|
||||||
|
{
|
||||||
|
SHLOGV_ERROR("No physics object manager linked with raycaster to match bodies")
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compare body IDs to find the matching physics object
|
||||||
|
const auto HIT_BODY_EID = raycastInfo.body->getEntity();
|
||||||
|
|
||||||
|
for (const auto& [entityID, physicsObject] : objectManager->GetPhysicsObjects())
|
||||||
|
{
|
||||||
|
const auto RP3D_BODY = physicsObject.GetCollisionBody();
|
||||||
|
|
||||||
|
// Match rp3d bodies
|
||||||
|
if (RP3D_BODY->getEntity() != HIT_BODY_EID)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
temp.entityHit = entityID;
|
||||||
|
|
||||||
|
// Find collider index
|
||||||
|
if (const int INDEX = findColliderIndex(RP3D_BODY, raycastInfo.collider->getEntity()); INDEX > -1)
|
||||||
|
{
|
||||||
|
temp.shapeIndex = INDEX;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Private Function Member Definitions */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
SHPhysicsObject* SHPhysicsRaycaster::validateColliderRaycast(EntityID eid) noexcept
|
||||||
|
{
|
||||||
|
if (!objectManager)
|
||||||
|
{
|
||||||
|
SHLOGV_ERROR("No physics object manager linked with raycaster to match bodies")
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto* physicsObject = objectManager->GetPhysicsObject(eid);
|
||||||
|
if (!physicsObject || physicsObject->GetCollisionBody()->getNbColliders() == 0)
|
||||||
|
{
|
||||||
|
SHLOGV_WARNING("Cannot cast ray at an entity without colliders!")
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return physicsObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SHPhysicsRaycaster::findColliderIndex(const rp3d::CollisionBody* rp3dBody, rp3d::Entity rp3dColliderEID) noexcept
|
||||||
|
{
|
||||||
|
const int NUM_COLLISION_SHAPES = static_cast<int>(rp3dBody->getNbColliders());
|
||||||
|
for (int i = 0; i < NUM_COLLISION_SHAPES; ++i)
|
||||||
|
{
|
||||||
|
const auto COLLIDER_EID = rp3dBody->getCollider(i)->getEntity();
|
||||||
|
if (COLLIDER_EID == rp3dColliderEID)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace SHADE
|
|
@ -0,0 +1,131 @@
|
||||||
|
/****************************************************************************************
|
||||||
|
* \file SHPhysicsRaycaster.h
|
||||||
|
* \author Diren D Bharwani, diren.dbharwani, 390002520
|
||||||
|
* \brief Interface for a Physics Raycaster.
|
||||||
|
*
|
||||||
|
* \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||||
|
* disclosure of this file or its contents without the prior written consent
|
||||||
|
* of DigiPen Institute of Technology is prohibited.
|
||||||
|
****************************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <reactphysics3d/reactphysics3d.h>
|
||||||
|
|
||||||
|
// Project Headers
|
||||||
|
#include "Math/SHRay.h"
|
||||||
|
#include "Physics/PhysicsObject/SHPhysicsObjectManager.h"
|
||||||
|
#include "Physics/SHPhysicsWorld.h"
|
||||||
|
#include "SH_API.h"
|
||||||
|
#include "SHPhysicsRaycastResult.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Type Definitions */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
class SH_API SHPhysicsRaycaster : public reactphysics3d::RaycastCallback
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Type Definitions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
using RaycastPair = std::pair<SHRay, SHPhysicsRaycastResult>;
|
||||||
|
using RaycastPairs = std::vector<RaycastPair>;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Constructors & Destructor */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
SHPhysicsRaycaster() noexcept;
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Getter Functions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
[[nodiscard]] const RaycastPairs& GetRaycasts() const noexcept;
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Setter Functions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void SetObjectManager(SHPhysicsObjectManager* physicsObjectManager) noexcept;
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Function Members */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void BindToWorld (rp3d::PhysicsWorld* physicsWorld) noexcept;
|
||||||
|
void ClearFrame () noexcept;
|
||||||
|
|
||||||
|
// TODO(Diren): Filtering, return all shades ray hits
|
||||||
|
|
||||||
|
SHPhysicsRaycastResult Raycast
|
||||||
|
(
|
||||||
|
const SHRay& ray
|
||||||
|
, float distance = std::numeric_limits<float>::infinity()
|
||||||
|
) noexcept;
|
||||||
|
|
||||||
|
SHPhysicsRaycastResult Linecast
|
||||||
|
(
|
||||||
|
const SHVec3& start
|
||||||
|
, const SHVec3& end
|
||||||
|
) noexcept;
|
||||||
|
|
||||||
|
SHPhysicsRaycastResult ColliderRaycast
|
||||||
|
(
|
||||||
|
EntityID eid
|
||||||
|
, const SHRay& ray
|
||||||
|
, float distance = std::numeric_limits<float>::infinity()
|
||||||
|
) noexcept;
|
||||||
|
|
||||||
|
SHPhysicsRaycastResult ColliderRaycast
|
||||||
|
(
|
||||||
|
EntityID eid
|
||||||
|
, int shapeIndex
|
||||||
|
, const SHRay& ray
|
||||||
|
, float distance = std::numeric_limits<float>::infinity()
|
||||||
|
) noexcept;
|
||||||
|
|
||||||
|
SHPhysicsRaycastResult ColliderLinecast
|
||||||
|
(
|
||||||
|
EntityID eid
|
||||||
|
, const SHVec3& start
|
||||||
|
, const SHVec3& end
|
||||||
|
) noexcept;
|
||||||
|
|
||||||
|
SHPhysicsRaycastResult ColliderLinecast
|
||||||
|
(
|
||||||
|
EntityID eid
|
||||||
|
, int shapeIndex
|
||||||
|
, const SHVec3& start
|
||||||
|
, const SHVec3& end
|
||||||
|
) noexcept;
|
||||||
|
|
||||||
|
rp3d::decimal notifyRaycastHit(const rp3d::RaycastInfo& raycastInfo) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Data Members */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
rp3d::PhysicsWorld* world;
|
||||||
|
SHPhysicsObjectManager* objectManager; // For
|
||||||
|
SHPhysicsRaycastResult temp; // Holds the temporary result after casting into the world
|
||||||
|
RaycastPairs raycasts; // Used for debug drawing
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Function Members */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
SHPhysicsObject* validateColliderRaycast (EntityID eid) noexcept;
|
||||||
|
static int findColliderIndex (const rp3d::CollisionBody* rp3dBody, rp3d::Entity rp3dColliderEID) noexcept;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace SHADE
|
|
@ -294,7 +294,7 @@ namespace SHADE
|
||||||
if (!rp3dBody->isActive())
|
if (!rp3dBody->isActive())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const int NUM_SHAPES = static_cast<int>(component.collisionShapes.size());
|
const int NUM_SHAPES = static_cast<int>(rp3dBody->getNbColliders());
|
||||||
for (int i = 0; i < NUM_SHAPES; ++i)
|
for (int i = 0; i < NUM_SHAPES; ++i)
|
||||||
{
|
{
|
||||||
auto& collisionShape = component.collisionShapes[i];
|
auto& collisionShape = component.collisionShapes[i];
|
||||||
|
|
|
@ -23,11 +23,10 @@ namespace SHADE
|
||||||
/* Static Data Member Definitions */
|
/* Static Data Member Definitions */
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
SHPhysicsObjectManager::CommandFunctionPtr SHPhysicsObjectManager::componentFunc[2][3]
|
SHPhysicsObjectManager::CommandFunctionPtr SHPhysicsObjectManager::componentFunc[3][2]
|
||||||
{
|
{
|
||||||
addRigidBody , addCollider
|
addRigidBody , addCollider , addCollisionShape
|
||||||
, removeRigidBody , removeCollider
|
, removeRigidBody , removeCollider , removeCollisionShape
|
||||||
, addCollisionShape , removeCollisionShape
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -150,7 +150,7 @@ namespace SHADE
|
||||||
/* Data Members */
|
/* Data Members */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
static CommandFunctionPtr componentFunc[2][3]; // 2 commands, 3 components
|
static CommandFunctionPtr componentFunc[3][2]; // 3 components, 2 commands
|
||||||
|
|
||||||
rp3d::PhysicsCommon* factory = nullptr;
|
rp3d::PhysicsCommon* factory = nullptr;
|
||||||
rp3d::PhysicsWorld* world = nullptr;
|
rp3d::PhysicsWorld* world = nullptr;
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
|
|
||||||
// Project Headers
|
// Project Headers
|
||||||
#include "ECS_Base/Managers/SHSystemManager.h"
|
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||||
#include "Graphics/MiddleEnd/Interface/SHDebugDrawSystem.h"
|
|
||||||
#include "Scene/SHSceneManager.h"
|
#include "Scene/SHSceneManager.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
|
@ -26,11 +25,12 @@ namespace SHADE
|
||||||
|
|
||||||
const SHPhysicsDebugDrawSystem::DebugDrawFunction SHPhysicsDebugDrawSystem::drawFunctions[NUM_FLAGS] =
|
const SHPhysicsDebugDrawSystem::DebugDrawFunction SHPhysicsDebugDrawSystem::drawFunctions[NUM_FLAGS] =
|
||||||
{
|
{
|
||||||
SHPhysicsDebugDrawSystem::drawColliders
|
drawColliders
|
||||||
, SHPhysicsDebugDrawSystem::drawColliderAABBs
|
, drawColliderAABBs
|
||||||
, SHPhysicsDebugDrawSystem::drawBroadPhaseAABBs
|
, drawBroadPhaseAABBs
|
||||||
, SHPhysicsDebugDrawSystem::drawContactPoints
|
, drawContactPoints
|
||||||
, SHPhysicsDebugDrawSystem::drawContactNormals
|
, drawContactNormals
|
||||||
|
, drawRaycasts
|
||||||
};
|
};
|
||||||
|
|
||||||
SHVec3 SHPhysicsDebugDrawSystem::boxVertices[NUM_BOX_VERTICES];
|
SHVec3 SHPhysicsDebugDrawSystem::boxVertices[NUM_BOX_VERTICES];
|
||||||
|
@ -42,13 +42,13 @@ namespace SHADE
|
||||||
SHPhysicsDebugDrawSystem::SHPhysicsDebugDrawSystem() noexcept
|
SHPhysicsDebugDrawSystem::SHPhysicsDebugDrawSystem() noexcept
|
||||||
: debugDrawFlags { 0 }
|
: debugDrawFlags { 0 }
|
||||||
, physicsSystem { nullptr }
|
, physicsSystem { nullptr }
|
||||||
, rp3dDebugRenderer { nullptr }
|
|
||||||
{
|
{
|
||||||
debugColours[SHUtilities::ConvertEnum(DebugDrawFlags::COLLIDER)] = SHColour::GREEN;
|
debugColours[SHUtilities::ConvertEnum(DebugDrawFlags::COLLIDER)] = SHColour::GREEN;
|
||||||
debugColours[SHUtilities::ConvertEnum(DebugDrawFlags::COLLIDER_AABB)] = SHColour::YELLOW;
|
debugColours[SHUtilities::ConvertEnum(DebugDrawFlags::COLLIDER_AABB)] = SHColour::YELLOW;
|
||||||
debugColours[SHUtilities::ConvertEnum(DebugDrawFlags::BROAD_PHASE_AABB)] = SHColour::CYAN;
|
debugColours[SHUtilities::ConvertEnum(DebugDrawFlags::BROAD_PHASE_AABB)] = SHColour::CYAN;
|
||||||
debugColours[SHUtilities::ConvertEnum(DebugDrawFlags::CONTACT_POINTS)] = SHColour::RED;
|
debugColours[SHUtilities::ConvertEnum(DebugDrawFlags::CONTACT_POINTS)] = SHColour::RED;
|
||||||
debugColours[SHUtilities::ConvertEnum(DebugDrawFlags::CONTACT_NORMALS)] = SHColour::RED;
|
debugColours[SHUtilities::ConvertEnum(DebugDrawFlags::CONTACT_NORMALS)] = SHColour::RED;
|
||||||
|
debugColours[SHUtilities::ConvertEnum(DebugDrawFlags::RAYCASTS)] = SHColour::ORANGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHPhysicsDebugDrawSystem::PhysicsDebugDrawRoutine::PhysicsDebugDrawRoutine()
|
SHPhysicsDebugDrawSystem::PhysicsDebugDrawRoutine::PhysicsDebugDrawRoutine()
|
||||||
|
@ -111,19 +111,30 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
auto* system = reinterpret_cast<SHPhysicsDebugDrawSystem*>(GetSystem());
|
auto* system = reinterpret_cast<SHPhysicsDebugDrawSystem*>(GetSystem());
|
||||||
|
|
||||||
|
auto* debugDrawSystem = SHSystemManager::GetSystem<SHDebugDrawSystem>();
|
||||||
|
if (debugDrawSystem == nullptr)
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Unable to get a debug draw system for Physics Debug Drawing!")
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < SHUtilities::ConvertEnum(DebugDrawFlags::NUM_FLAGS); ++i)
|
for (int i = 0; i < SHUtilities::ConvertEnum(DebugDrawFlags::NUM_FLAGS); ++i)
|
||||||
{
|
{
|
||||||
const bool DRAW = (system->debugDrawFlags & (1U << i)) > 0;
|
const bool DRAW = (system->debugDrawFlags & (1U << i)) > 0;
|
||||||
if (DRAW)
|
if (DRAW)
|
||||||
drawFunctions[i](system->rp3dDebugRenderer);
|
drawFunctions[i](debugDrawSystem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Automatically clear the container of raycasts despite debug drawing state
|
||||||
|
// TODO(Diren): Move this somewhere else
|
||||||
|
system->physicsSystem->raycaster.ClearFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/* Private Function Member Definitions */
|
/* Private Function Member Definitions */
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void SHPhysicsDebugDrawSystem::drawColliders(rp3d::DebugRenderer* debugRenderer) noexcept
|
void SHPhysicsDebugDrawSystem::drawColliders(SHDebugDrawSystem* debugRenderer) noexcept
|
||||||
{
|
{
|
||||||
const auto& COLLIDER_SET = SHComponentManager::GetDense<SHColliderComponent>();
|
const auto& COLLIDER_SET = SHComponentManager::GetDense<SHColliderComponent>();
|
||||||
for (const auto& COLLIDER : COLLIDER_SET)
|
for (const auto& COLLIDER : COLLIDER_SET)
|
||||||
|
@ -136,34 +147,58 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
switch (collisionShape.GetType())
|
switch (collisionShape.GetType())
|
||||||
{
|
{
|
||||||
case SHCollisionShape::Type::BOX: debugDrawBox(COLLIDER, collisionShape); break;
|
case SHCollisionShape::Type::BOX: debugDrawBox(debugRenderer, COLLIDER, collisionShape); break;
|
||||||
case SHCollisionShape::Type::SPHERE: debugDrawSphere(COLLIDER, collisionShape); break;
|
case SHCollisionShape::Type::SPHERE: debugDrawSphere(debugRenderer, COLLIDER, collisionShape); break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHPhysicsDebugDrawSystem::drawColliderAABBs(rp3d::DebugRenderer* debugRenderer) noexcept
|
void SHPhysicsDebugDrawSystem::drawColliderAABBs(SHDebugDrawSystem* debugRenderer) noexcept
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHPhysicsDebugDrawSystem::drawBroadPhaseAABBs(rp3d::DebugRenderer* debugRenderer) noexcept
|
void SHPhysicsDebugDrawSystem::drawBroadPhaseAABBs(SHDebugDrawSystem* debugRenderer) noexcept
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHPhysicsDebugDrawSystem::drawContactPoints(rp3d::DebugRenderer* debugRenderer) noexcept
|
void SHPhysicsDebugDrawSystem::drawContactPoints(SHDebugDrawSystem* debugRenderer) noexcept
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHPhysicsDebugDrawSystem::drawContactNormals(rp3d::DebugRenderer* debugRenderer) noexcept
|
void SHPhysicsDebugDrawSystem::drawContactNormals(SHDebugDrawSystem* debugRenderer) noexcept
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SHPhysicsDebugDrawSystem::drawRaycasts(SHDebugDrawSystem* debugRenderer) noexcept
|
||||||
|
{
|
||||||
|
auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>();
|
||||||
|
if (!physicsSystem)
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Unable to retrieve physics system for debug drawing raycasts!")
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SHColour& RAY_COLOUR = SHColour::ORANGE;
|
||||||
|
|
||||||
|
// Draw all raycast pairs
|
||||||
|
for (const auto& [ray, raycastResult] : physicsSystem->raycaster.GetRaycasts())
|
||||||
|
{
|
||||||
|
// If infinity, it is an infinite raycast. If not, render the distance in raycastResult.
|
||||||
|
// Ignore the hit variable as it will always correspond to the length of the raycast, hit or miss.
|
||||||
|
const float RENDER_DIST = raycastResult.distance == std::numeric_limits<float>::infinity() ? SHRay::MAX_RAYCAST_DIST : raycastResult.distance;
|
||||||
|
const SHVec3 END_POS = ray.position + (ray.direction * RENDER_DIST);
|
||||||
|
|
||||||
|
debugRenderer->DrawLine(RAY_COLOUR, ray.position, END_POS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SHPhysicsDebugDrawSystem::generateBox() noexcept
|
void SHPhysicsDebugDrawSystem::generateBox() noexcept
|
||||||
{
|
{
|
||||||
boxVertices[0] = { 0.5f, 0.5f, -0.5f }; // TOP_RIGHT_BACK
|
boxVertices[0] = { 0.5f, 0.5f, -0.5f }; // TOP_RIGHT_BACK
|
||||||
|
@ -176,15 +211,8 @@ namespace SHADE
|
||||||
boxVertices[7] = { -0.5f, -0.5f, 0.5f }; // BTM_LEFT_FRONT
|
boxVertices[7] = { -0.5f, -0.5f, 0.5f }; // BTM_LEFT_FRONT
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHPhysicsDebugDrawSystem::debugDrawBox(const SHColliderComponent& colliderComponent, const SHCollisionShape& collisionShape) noexcept
|
void SHPhysicsDebugDrawSystem::debugDrawBox(SHDebugDrawSystem* debugRenderer, const SHColliderComponent& colliderComponent, const SHCollisionShape& collisionShape) noexcept
|
||||||
{
|
{
|
||||||
auto* debugDrawSystem = SHSystemManager::GetSystem<SHDebugDrawSystem>();
|
|
||||||
if (debugDrawSystem == nullptr)
|
|
||||||
{
|
|
||||||
SHLOG_ERROR("Unable to get a debug draw system for Physics Debug Drawing!")
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto* BOX = reinterpret_cast<const SHBox*>(collisionShape.GetShape());
|
auto* BOX = reinterpret_cast<const SHBox*>(collisionShape.GetShape());
|
||||||
|
|
||||||
// Calculate final position & orientation
|
// Calculate final position & orientation
|
||||||
|
@ -211,27 +239,20 @@ namespace SHADE
|
||||||
transformedVertices[IDX2] = SHVec3::Transform(boxVertices[IDX2], FINAL_TRS);
|
transformedVertices[IDX2] = SHVec3::Transform(boxVertices[IDX2], FINAL_TRS);
|
||||||
|
|
||||||
// Draw 4 line to connect the quads
|
// Draw 4 line to connect the quads
|
||||||
debugDrawSystem->DrawLine(COLLIDER_COLOUR, transformedVertices[IDX1], transformedVertices[IDX2]);
|
debugRenderer->DrawLine(COLLIDER_COLOUR, transformedVertices[IDX1], transformedVertices[IDX2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A, B, C, D
|
// A, B, C, D
|
||||||
std::array backQuad { transformedVertices[0], transformedVertices[1], transformedVertices[3], transformedVertices[2] };
|
std::array backQuad { transformedVertices[0], transformedVertices[1], transformedVertices[3], transformedVertices[2] };
|
||||||
debugDrawSystem->DrawPoly(COLLIDER_COLOUR, backQuad.begin(), backQuad.end());
|
debugRenderer->DrawPoly(COLLIDER_COLOUR, backQuad.begin(), backQuad.end());
|
||||||
|
|
||||||
// E, F, G, H
|
// E, F, G, H
|
||||||
std::array frontQuad { transformedVertices[4], transformedVertices[5], transformedVertices[7], transformedVertices[6] };
|
std::array frontQuad { transformedVertices[4], transformedVertices[5], transformedVertices[7], transformedVertices[6] };
|
||||||
debugDrawSystem->DrawPoly(COLLIDER_COLOUR, frontQuad.begin(), frontQuad.end());
|
debugRenderer->DrawPoly(COLLIDER_COLOUR, frontQuad.begin(), frontQuad.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHPhysicsDebugDrawSystem::debugDrawSphere(const SHColliderComponent& colliderComponent, const SHCollisionShape& collisionShape) noexcept
|
void SHPhysicsDebugDrawSystem::debugDrawSphere(SHDebugDrawSystem* debugRenderer, const SHColliderComponent& colliderComponent, const SHCollisionShape& collisionShape) noexcept
|
||||||
{
|
{
|
||||||
auto* debugDrawSystem = SHSystemManager::GetSystem<SHDebugDrawSystem>();
|
|
||||||
if (debugDrawSystem == nullptr)
|
|
||||||
{
|
|
||||||
SHLOG_ERROR("Unable to get a debug draw system for Physics Debug Drawing!")
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto* SPHERE = reinterpret_cast<const SHSphere*>(collisionShape.GetShape());
|
auto* SPHERE = reinterpret_cast<const SHSphere*>(collisionShape.GetShape());
|
||||||
|
|
||||||
const SHColour COLLIDER_COLOUR = collisionShape.IsTrigger() ? SHColour::PURPLE : SHColour::GREEN;
|
const SHColour COLLIDER_COLOUR = collisionShape.IsTrigger() ? SHColour::PURPLE : SHColour::GREEN;
|
||||||
|
@ -240,7 +261,7 @@ namespace SHADE
|
||||||
const SHQuaternion FINAL_ROT = colliderComponent.GetOrientation() * SHQuaternion::FromEuler(collisionShape.GetRotationOffset());
|
const SHQuaternion FINAL_ROT = colliderComponent.GetOrientation() * SHQuaternion::FromEuler(collisionShape.GetRotationOffset());
|
||||||
const SHMatrix TR = SHMatrix::Rotate(FINAL_ROT) * SHMatrix::Translate(colliderComponent.GetPosition());
|
const SHMatrix TR = SHMatrix::Rotate(FINAL_ROT) * SHMatrix::Translate(colliderComponent.GetPosition());
|
||||||
|
|
||||||
debugDrawSystem->DrawSphere(COLLIDER_COLOUR, SHVec3::Transform(collisionShape.GetPositionOffset(), TR), SPHERE->GetWorldRadius());
|
debugRenderer->DrawSphere(COLLIDER_COLOUR, SHVec3::Transform(collisionShape.GetPositionOffset(), TR), SPHERE->GetWorldRadius());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace SHADE
|
} // namespace SHADE
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
// Project Headers
|
// Project Headers
|
||||||
#include "ECS_Base/System/SHSystemRoutine.h"
|
#include "ECS_Base/System/SHSystemRoutine.h"
|
||||||
|
#include "Graphics/MiddleEnd/Interface/SHDebugDrawSystem.h"
|
||||||
#include "Math/SHColour.h"
|
#include "Math/SHColour.h"
|
||||||
#include "SHPhysicsSystem.h"
|
#include "SHPhysicsSystem.h"
|
||||||
#include "Tools/Utilities/SHUtilities.h"
|
#include "Tools/Utilities/SHUtilities.h"
|
||||||
|
@ -38,6 +39,7 @@ namespace SHADE
|
||||||
, BROAD_PHASE_AABB
|
, BROAD_PHASE_AABB
|
||||||
, CONTACT_POINTS
|
, CONTACT_POINTS
|
||||||
, CONTACT_NORMALS
|
, CONTACT_NORMALS
|
||||||
|
, RAYCASTS
|
||||||
|
|
||||||
, NUM_FLAGS
|
, NUM_FLAGS
|
||||||
};
|
};
|
||||||
|
@ -91,7 +93,7 @@ namespace SHADE
|
||||||
/* Type Definitions */
|
/* Type Definitions */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
using DebugDrawFunction = void(*)(rp3d::DebugRenderer*) noexcept;
|
using DebugDrawFunction = void(*)(SHDebugDrawSystem*) noexcept;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Data Members */
|
/* Data Members */
|
||||||
|
@ -108,7 +110,6 @@ namespace SHADE
|
||||||
|
|
||||||
uint8_t debugDrawFlags;
|
uint8_t debugDrawFlags;
|
||||||
SHPhysicsSystem* physicsSystem;
|
SHPhysicsSystem* physicsSystem;
|
||||||
rp3d::DebugRenderer* rp3dDebugRenderer;
|
|
||||||
SHColour debugColours[NUM_FLAGS];
|
SHColour debugColours[NUM_FLAGS];
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
@ -117,11 +118,12 @@ namespace SHADE
|
||||||
|
|
||||||
// Generic Draw Functions
|
// Generic Draw Functions
|
||||||
|
|
||||||
static void drawColliders (rp3d::DebugRenderer* debugRenderer) noexcept;
|
static void drawColliders (SHDebugDrawSystem* debugRenderer) noexcept;
|
||||||
static void drawColliderAABBs (rp3d::DebugRenderer* debugRenderer) noexcept;
|
static void drawColliderAABBs (SHDebugDrawSystem* debugRenderer) noexcept;
|
||||||
static void drawBroadPhaseAABBs (rp3d::DebugRenderer* debugRenderer) noexcept;
|
static void drawBroadPhaseAABBs (SHDebugDrawSystem* debugRenderer) noexcept;
|
||||||
static void drawContactPoints (rp3d::DebugRenderer* debugRenderer) noexcept;
|
static void drawContactPoints (SHDebugDrawSystem* debugRenderer) noexcept;
|
||||||
static void drawContactNormals (rp3d::DebugRenderer* debugRenderer) noexcept;
|
static void drawContactNormals (SHDebugDrawSystem* debugRenderer) noexcept;
|
||||||
|
static void drawRaycasts (SHDebugDrawSystem* debugRenderer) noexcept;
|
||||||
|
|
||||||
// Shape Generation Functions
|
// Shape Generation Functions
|
||||||
|
|
||||||
|
@ -129,8 +131,8 @@ namespace SHADE
|
||||||
|
|
||||||
// Shape Draw Functions
|
// Shape Draw Functions
|
||||||
|
|
||||||
static void debugDrawBox (const SHColliderComponent& colliderComponent, const SHCollisionShape& collisionShape) noexcept;
|
static void debugDrawBox (SHDebugDrawSystem* debugRenderer, const SHColliderComponent& colliderComponent, const SHCollisionShape& collisionShape) noexcept;
|
||||||
static void debugDrawSphere (const SHColliderComponent& colliderComponent, const SHCollisionShape& collisionShape) noexcept;
|
static void debugDrawSphere (SHDebugDrawSystem* debugRenderer, const SHColliderComponent& colliderComponent, const SHCollisionShape& collisionShape) noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace SHADE
|
} // namespace SHADE
|
||||||
|
|
|
@ -22,10 +22,6 @@
|
||||||
#include "Scene/SHSceneManager.h"
|
#include "Scene/SHSceneManager.h"
|
||||||
#include "Scripting/SHScriptEngine.h"
|
#include "Scripting/SHScriptEngine.h"
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------------------*/
|
|
||||||
/* Local Helper Functions */
|
|
||||||
/*-------------------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
@ -115,8 +111,9 @@ namespace SHADE
|
||||||
SHEventManager::SubscribeTo(SH_EDITOR_ON_STOP_EVENT, ON_STOP_RECEIVER_PTR);
|
SHEventManager::SubscribeTo(SH_EDITOR_ON_STOP_EVENT, ON_STOP_RECEIVER_PTR);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
// Link Physics Object Manager with System
|
// Link Physics Object Manager with System & Raycaster
|
||||||
objectManager.SetFactory(factory);
|
objectManager.SetFactory(factory);
|
||||||
|
raycaster.SetObjectManager(&objectManager);
|
||||||
|
|
||||||
// Link Collision Listener with System
|
// Link Collision Listener with System
|
||||||
collisionListener.BindToSystem(this);
|
collisionListener.BindToSystem(this);
|
||||||
|
@ -183,6 +180,35 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SHPhysicsRaycastResult SHPhysicsSystem::Raycast(const SHRay& ray, float distance) noexcept
|
||||||
|
{
|
||||||
|
return raycaster.Raycast(ray, distance);
|
||||||
|
}
|
||||||
|
|
||||||
|
SHPhysicsRaycastResult SHPhysicsSystem::Linecast(const SHVec3& start, const SHVec3& end) noexcept
|
||||||
|
{
|
||||||
|
return raycaster.Linecast(start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
SHPhysicsRaycastResult SHPhysicsSystem::ColliderRaycast(EntityID eid, const SHRay& ray, float distance) noexcept
|
||||||
|
{
|
||||||
|
return raycaster.ColliderRaycast(eid, ray, distance);
|
||||||
|
}
|
||||||
|
|
||||||
|
SHPhysicsRaycastResult SHPhysicsSystem::ColliderRaycast(EntityID eid, int shapeIndex, const SHRay& ray, float distance) noexcept
|
||||||
|
{
|
||||||
|
return raycaster.ColliderRaycast(eid, shapeIndex, ray, distance);
|
||||||
|
}
|
||||||
|
|
||||||
|
SHPhysicsRaycastResult SHPhysicsSystem::ColliderLinecast(EntityID eid, const SHVec3& start, const SHVec3& end) noexcept
|
||||||
|
{
|
||||||
|
return raycaster.ColliderLinecast(eid, start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
SHPhysicsRaycastResult SHPhysicsSystem::ColliderLinecast(EntityID eid, int shapeIndex, const SHVec3& start, const SHVec3& end) noexcept
|
||||||
|
{
|
||||||
|
return raycaster.ColliderLinecast(eid, shapeIndex, start, end);
|
||||||
|
}
|
||||||
|
|
||||||
void SHPhysicsSystem::AddCollisionShape(EntityID eid, int shapeIndex)
|
void SHPhysicsSystem::AddCollisionShape(EntityID eid, int shapeIndex)
|
||||||
{
|
{
|
||||||
|
@ -325,10 +351,14 @@ namespace SHADE
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
// Create physics world
|
// Create physics world
|
||||||
|
if (worldState.world != nullptr)
|
||||||
|
return onPlayEvent->handle;
|
||||||
|
|
||||||
worldState.CreateWorld(factory);
|
worldState.CreateWorld(factory);
|
||||||
|
|
||||||
// Link Collision Listener
|
// Link Collision Listener & Raycaster
|
||||||
collisionListener.BindToWorld(worldState.world);
|
collisionListener.BindToWorld(worldState.world);
|
||||||
|
raycaster.BindToWorld(worldState.world);
|
||||||
|
|
||||||
// Link with object manager & create all physics objects
|
// Link with object manager & create all physics objects
|
||||||
objectManager.SetWorld(worldState.world);
|
objectManager.SetWorld(worldState.world);
|
||||||
|
|
|
@ -21,11 +21,11 @@
|
||||||
#include "ECS_Base/System/SHFixedSystemRoutine.h"
|
#include "ECS_Base/System/SHFixedSystemRoutine.h"
|
||||||
|
|
||||||
#include "Math/Transform/SHTransformComponent.h"
|
#include "Math/Transform/SHTransformComponent.h"
|
||||||
|
|
||||||
#include "Physics/Collision/SHCollisionListener.h"
|
#include "Physics/Collision/SHCollisionListener.h"
|
||||||
|
#include "Physics/Collision/SHPhysicsRaycaster.h"
|
||||||
#include "Physics/Interface/SHRigidBodyComponent.h"
|
#include "Physics/Interface/SHRigidBodyComponent.h"
|
||||||
#include "Physics/Interface/SHColliderComponent.h"
|
#include "Physics/Interface/SHColliderComponent.h"
|
||||||
#include "Physics/PhysicsObject//SHPhysicsObjectManager.h"
|
#include "Physics/PhysicsObject/SHPhysicsObjectManager.h"
|
||||||
#include "Physics/SHPhysicsWorld.h"
|
#include "Physics/SHPhysicsWorld.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,6 +79,90 @@ namespace SHADE
|
||||||
|
|
||||||
void ForceUpdate ();
|
void ForceUpdate ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Casts a ray into the world.
|
||||||
|
* @param ray The ray to cast.
|
||||||
|
* @param distance The distance to cast the ray. Defaults to infinity.
|
||||||
|
* @return The result of the raycast.
|
||||||
|
*/
|
||||||
|
SHPhysicsRaycastResult Raycast
|
||||||
|
(
|
||||||
|
const SHRay& ray
|
||||||
|
, float distance = std::numeric_limits<float>::infinity()
|
||||||
|
) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Casts a bounded ray into the world.
|
||||||
|
* @param start The starting point of the ray.
|
||||||
|
* @param end The end point of the ray.
|
||||||
|
* @return The result of the raycast.
|
||||||
|
*/
|
||||||
|
SHPhysicsRaycastResult Linecast
|
||||||
|
(
|
||||||
|
const SHVec3& start
|
||||||
|
, const SHVec3& end
|
||||||
|
) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Casts a ray at a body with colliders.
|
||||||
|
* @param eid The entity to cast to.
|
||||||
|
* @param ray The ray to cast.
|
||||||
|
* @param distance The distance to cast the ray. Defaults to infinity.
|
||||||
|
* @return The result of the raycast.
|
||||||
|
*/
|
||||||
|
SHPhysicsRaycastResult ColliderRaycast
|
||||||
|
(
|
||||||
|
EntityID eid
|
||||||
|
, const SHRay& ray
|
||||||
|
, float distance = std::numeric_limits<float>::infinity()
|
||||||
|
) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Casts a ray at a collider.
|
||||||
|
* @param eid The entity to cast to.
|
||||||
|
* @param shapeIndex The index of the collision shape.
|
||||||
|
* @param ray The ray to cast.
|
||||||
|
* @param distance The distance to cast the ray. Defaults to infinity.
|
||||||
|
* @return The result of the raycast.
|
||||||
|
*/
|
||||||
|
SHPhysicsRaycastResult ColliderRaycast
|
||||||
|
(
|
||||||
|
EntityID eid
|
||||||
|
, int shapeIndex
|
||||||
|
, const SHRay& ray
|
||||||
|
, float distance = std::numeric_limits<float>::infinity()
|
||||||
|
) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Casts a bounded ray at a body with colliders.
|
||||||
|
* @param eid
|
||||||
|
* @param start
|
||||||
|
* @param end
|
||||||
|
* @return The result of the raycast.
|
||||||
|
*/
|
||||||
|
SHPhysicsRaycastResult ColliderLinecast
|
||||||
|
(
|
||||||
|
EntityID eid
|
||||||
|
, const SHVec3& start
|
||||||
|
, const SHVec3& end
|
||||||
|
) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
* @param eid
|
||||||
|
* @param shapeIndex
|
||||||
|
* @param start
|
||||||
|
* @param end
|
||||||
|
* @return The result of the raycast.
|
||||||
|
*/
|
||||||
|
SHPhysicsRaycastResult ColliderLinecast
|
||||||
|
(
|
||||||
|
EntityID eid
|
||||||
|
, int shapeIndex
|
||||||
|
, const SHVec3& start
|
||||||
|
, const SHVec3& end
|
||||||
|
) noexcept;
|
||||||
|
|
||||||
// Specific Handling for Collision Shapes as they are not under the Component System.
|
// Specific Handling for Collision Shapes as they are not under the Component System.
|
||||||
// This is done as events need to be sent out.
|
// This is done as events need to be sent out.
|
||||||
// TODO(Diren): Consider using a static method through the ColliderComponent.
|
// TODO(Diren): Consider using a static method through the ColliderComponent.
|
||||||
|
@ -190,6 +274,7 @@ namespace SHADE
|
||||||
SHPhysicsWorldState worldState;
|
SHPhysicsWorldState worldState;
|
||||||
SHPhysicsObjectManager objectManager;
|
SHPhysicsObjectManager objectManager;
|
||||||
SHCollisionListener collisionListener;
|
SHCollisionListener collisionListener;
|
||||||
|
SHPhysicsRaycaster raycaster;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Function Members */
|
/* Function Members */
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace SHADE
|
||||||
return phySystem->GetAllCollisionInfo();
|
return phySystem->GetAllCollisionInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
SHLOG_WARNING("[SHPhysicsSystemInterface] Failed to get collision events. Empty vector returned instead.");
|
SHLOGV_WARNING("Failed to get collision events. Empty vector returned instead.");
|
||||||
return emptyVec;
|
return emptyVec;
|
||||||
}
|
}
|
||||||
const std::vector<SHCollisionInfo>& SHPhysicsSystemInterface::GetTriggerInfo() noexcept
|
const std::vector<SHCollisionInfo>& SHPhysicsSystemInterface::GetTriggerInfo() noexcept
|
||||||
|
@ -46,7 +46,7 @@ namespace SHADE
|
||||||
return phySystem->GetAllTriggerInfo();
|
return phySystem->GetAllTriggerInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
SHLOG_WARNING("[SHPhysicsSystemInterface] Failed to get trigger events. Empty vector returned instead.");
|
SHLOGV_WARNING("Failed to get trigger events. Empty vector returned instead.");
|
||||||
return emptyVec;
|
return emptyVec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,79 @@ namespace SHADE
|
||||||
return phySystem->GetFixedUpdateRate();
|
return phySystem->GetFixedUpdateRate();
|
||||||
}
|
}
|
||||||
|
|
||||||
SHLOG_WARNING("[SHPhysicsSystemInterface] Failed to get fixed delta time. 0.0 returned instead.");
|
SHLOGV_WARNING("Failed to get fixed delta time. 0.0 returned instead.");
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SHPhysicsRaycastResult SHPhysicsSystemInterface::Raycast(const SHRay& ray, float distance) noexcept
|
||||||
|
{
|
||||||
|
auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>();
|
||||||
|
if (physicsSystem)
|
||||||
|
{
|
||||||
|
return physicsSystem->Raycast(ray, distance);
|
||||||
|
}
|
||||||
|
|
||||||
|
SHLOGV_WARNING("Failed to get the physics system. No ray was casted.");
|
||||||
|
return SHPhysicsRaycastResult{};
|
||||||
|
}
|
||||||
|
|
||||||
|
SHPhysicsRaycastResult SHPhysicsSystemInterface::Linecast(const SHVec3& start, const SHVec3& end) noexcept
|
||||||
|
{
|
||||||
|
auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>();
|
||||||
|
if (physicsSystem)
|
||||||
|
{
|
||||||
|
return physicsSystem->Linecast(start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
SHLOGV_WARNING("Failed to get the physics system. No ray was casted.");
|
||||||
|
return SHPhysicsRaycastResult{};
|
||||||
|
}
|
||||||
|
|
||||||
|
SHPhysicsRaycastResult SHPhysicsSystemInterface::ColliderRaycast(EntityID eid, const SHRay& ray, float distance) noexcept
|
||||||
|
{
|
||||||
|
auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>();
|
||||||
|
if (physicsSystem)
|
||||||
|
{
|
||||||
|
return physicsSystem->ColliderRaycast(eid, ray, distance);
|
||||||
|
}
|
||||||
|
|
||||||
|
SHLOGV_WARNING("Failed to get the physics system. No ray was casted.");
|
||||||
|
return SHPhysicsRaycastResult{};
|
||||||
|
}
|
||||||
|
|
||||||
|
SHPhysicsRaycastResult SHPhysicsSystemInterface::ColliderRaycast(EntityID eid, int shapeIndex, const SHRay& ray, float distance) noexcept
|
||||||
|
{
|
||||||
|
auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>();
|
||||||
|
if (physicsSystem)
|
||||||
|
{
|
||||||
|
return physicsSystem->ColliderRaycast(eid, shapeIndex, ray, distance);
|
||||||
|
}
|
||||||
|
|
||||||
|
SHLOGV_WARNING("Failed to get the physics system. No ray was casted.");
|
||||||
|
return SHPhysicsRaycastResult{};
|
||||||
|
}
|
||||||
|
|
||||||
|
SHPhysicsRaycastResult SHPhysicsSystemInterface::ColliderLinecast(EntityID eid, const SHVec3& start, const SHVec3& end) noexcept
|
||||||
|
{
|
||||||
|
auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>();
|
||||||
|
if (physicsSystem)
|
||||||
|
{
|
||||||
|
return physicsSystem->ColliderLinecast(eid, start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
SHLOGV_WARNING("Failed to get the physics system. No ray was casted.");
|
||||||
|
return SHPhysicsRaycastResult{};
|
||||||
|
}
|
||||||
|
|
||||||
|
SHPhysicsRaycastResult SHPhysicsSystemInterface::ColliderLinecast(EntityID eid, int shapeIndex, const SHVec3& start, const SHVec3& end) noexcept
|
||||||
|
{
|
||||||
|
auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>();
|
||||||
|
if (physicsSystem)
|
||||||
|
{
|
||||||
|
return physicsSystem->ColliderLinecast(eid, shapeIndex, start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
SHLOGV_WARNING("Failed to get the physics system. No ray was casted.");
|
||||||
|
return SHPhysicsRaycastResult{};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,12 +14,21 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
// STL Includes
|
// STL Includes
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
// Project Headers
|
||||||
|
#include "ECS_Base/Entity/SHEntity.h"
|
||||||
|
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/* Forward Declarations */
|
/* Forward Declarations */
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
class SHCollisionInfo;
|
class SHCollisionInfo;
|
||||||
|
class SHVec3;
|
||||||
|
struct SHRay;
|
||||||
|
struct SHPhysicsRaycastResult;
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/* Type Definitions */
|
/* Type Definitions */
|
||||||
|
@ -39,8 +48,16 @@ namespace SHADE
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Static Usage Functions */
|
/* Static Usage Functions */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
[[nodiscard]] static const std::vector<SHCollisionInfo>& GetCollisionInfo() noexcept;
|
[[nodiscard]] static const std::vector<SHCollisionInfo>& GetCollisionInfo() noexcept;
|
||||||
[[nodiscard]] static const std::vector<SHCollisionInfo>& GetTriggerInfo() noexcept;
|
[[nodiscard]] static const std::vector<SHCollisionInfo>& GetTriggerInfo () noexcept;
|
||||||
[[nodiscard]] static double GetFixedDT() noexcept;
|
[[nodiscard]] static double GetFixedDT () noexcept;
|
||||||
|
|
||||||
|
[[nodiscard]] static SHPhysicsRaycastResult Raycast (const SHRay& ray, float distance = std::numeric_limits<float>::infinity()) noexcept;
|
||||||
|
[[nodiscard]] static SHPhysicsRaycastResult Linecast (const SHVec3& start, const SHVec3& end) noexcept;
|
||||||
|
[[nodiscard]] static SHPhysicsRaycastResult ColliderRaycast (EntityID eid, const SHRay& ray, float distance = std::numeric_limits<float>::infinity()) noexcept;
|
||||||
|
[[nodiscard]] static SHPhysicsRaycastResult ColliderRaycast (EntityID eid, int shapeIndex, const SHRay& ray, float distance = std::numeric_limits<float>::infinity()) noexcept;
|
||||||
|
[[nodiscard]] static SHPhysicsRaycastResult ColliderLinecast (EntityID eid, const SHVec3& start, const SHVec3& end) noexcept;
|
||||||
|
[[nodiscard]] static SHPhysicsRaycastResult ColliderLinecast (EntityID eid, int shapeIndex, const SHVec3& start, const SHVec3& end) noexcept;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +1,37 @@
|
||||||
/************************************************************************************//*!
|
/****************************************************************************************
|
||||||
\file Ray.cxx
|
* \file Ray.cxx
|
||||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
* \author Diren D Bharwani, diren.dbharwani, 390002520
|
||||||
\par email: kahwei.tng\@digipen.edu
|
* \brief Implementation for the managed Ray struct.
|
||||||
\date Oct 20, 2022
|
*
|
||||||
\brief Contains the definitions of functions of the Vector2 struct.
|
* \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||||
|
* disclosure of this file or its contents without the prior written consent
|
||||||
|
* of DigiPen Institute of Technology is prohibited.
|
||||||
|
****************************************************************************************/
|
||||||
|
|
||||||
Note: This file is written in C++17/CLI.
|
|
||||||
|
|
||||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
|
||||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
|
||||||
of DigiPen Institute of Technology is prohibited.
|
|
||||||
*//*************************************************************************************/
|
|
||||||
// Precompiled Headers
|
|
||||||
#include "SHpch.h"
|
#include "SHpch.h"
|
||||||
|
|
||||||
// Primary Header
|
// Primary Header
|
||||||
#include "Math/Ray.hxx"
|
#include "Ray.hxx"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/* Constructors */
|
/* Constructor Definitions */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
Ray::Ray(Vector3 origin, Vector3 direction)
|
|
||||||
: Origin { origin }
|
Ray::Ray(Vector3 position, Vector3 direction)
|
||||||
, Direction{ direction }
|
{
|
||||||
{}
|
Position = position;
|
||||||
}
|
Direction = direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Function Member Definitions */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void Ray::LookAt(Vector3 target)
|
||||||
|
{
|
||||||
|
Direction = (target - Position).GetNormalised();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace SHADE
|
|
@ -1,50 +1,61 @@
|
||||||
/************************************************************************************//*!
|
/****************************************************************************************
|
||||||
\file Ray.hxx
|
* \file Ray.hxx
|
||||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
* \author Diren D Bharwani, diren.dbharwani, 390002520
|
||||||
\par email: kahwei.tng\@digipen.edu
|
* \brief Interface for the managed Ray struct.
|
||||||
\date Oct 20, 2021
|
*
|
||||||
\brief Contains the definitions of Vector2 struct.
|
* \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||||
|
* disclosure of this file or its contents without the prior written consent
|
||||||
|
* of DigiPen Institute of Technology is prohibited.
|
||||||
|
****************************************************************************************/
|
||||||
|
|
||||||
Note: This file is written in C++17/CLI.
|
|
||||||
|
|
||||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
|
||||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
|
||||||
of DigiPen Institute of Technology is prohibited.
|
|
||||||
*//*************************************************************************************/
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// Project Includes
|
// Project Includes
|
||||||
#include "Vector3.hxx"
|
#include "Math/Vector3.hxx"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
///<summary>
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/// CLR version of the the SHADE Engine's Ray class that represents a ray in
|
/* Type Definitions */
|
||||||
/// 3-Dimensional space.
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/// </summary>
|
|
||||||
public value struct Ray
|
public value struct Ray
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Public Members */
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
|
||||||
/// <summary>
|
|
||||||
/// The start point of the ray.
|
|
||||||
/// </summary>
|
|
||||||
Vector3 Origin;
|
|
||||||
/// <summary>
|
|
||||||
/// The direction that a ray travels in.
|
|
||||||
/// </summary>
|
|
||||||
Vector3 Direction;
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
|
||||||
/* Constructors */
|
/* Constructors */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a ray starting at origin along direction.
|
/// Constructor for a ray.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="origin">Source of the ray.</param>
|
/// <param name="position">The starting position of the ray.</param>
|
||||||
/// <param name="direction">Direction the ray travels in.</param>
|
/// <param name="direction">The direction of the ray.</param>
|
||||||
Ray(Vector3 origin, Vector3 direction);
|
Ray(Vector3 position, Vector3 direction);
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Properties */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The starting point of the Ray.
|
||||||
|
/// </summary>
|
||||||
|
property Vector3 Position;
|
||||||
|
/// <summary>
|
||||||
|
/// The direction of the ray. This should be a normalised vector.
|
||||||
|
/// </summary>
|
||||||
|
property Vector3 Direction;
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Function Members */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Rotates the ray's direction towards a target.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="target">The target to direct the ray towards.</param>
|
||||||
|
void LookAt(Vector3 target);
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
} // namespace SHADE
|
|
@ -0,0 +1,105 @@
|
||||||
|
/****************************************************************************************
|
||||||
|
* \file Physics.cxx
|
||||||
|
* \author Diren D Bharwani, diren.dbharwani, 390002520
|
||||||
|
* \brief Implementation for the managed Physics class.
|
||||||
|
*
|
||||||
|
* \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||||
|
* disclosure of this file or its contents without the prior written consent
|
||||||
|
* of DigiPen Institute of Technology is prohibited.
|
||||||
|
****************************************************************************************/
|
||||||
|
|
||||||
|
#include "SHpch.h"
|
||||||
|
|
||||||
|
// Primary Header
|
||||||
|
#include "Physics.hxx"
|
||||||
|
// External Dependencies
|
||||||
|
#include "Physics/System/SHPhysicsSystemInterface.h"
|
||||||
|
// Project Header
|
||||||
|
#include "Engine/GameObject.hxx"
|
||||||
|
#include "Utility/Convert.hxx"
|
||||||
|
#include "Utility/Debug.hxx"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Property Function Definitions */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
Vector3 Physics::Gravity::get()
|
||||||
|
{
|
||||||
|
// TODO(Diren)
|
||||||
|
|
||||||
|
return Vector3::Zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Physics::Gravity::set(Vector3 value)
|
||||||
|
{
|
||||||
|
(void)value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Raycast Function Member Definitions */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
RaycastHit Physics::Raycast(Ray ray)
|
||||||
|
{
|
||||||
|
return Convert::ToCLI(SHPhysicsSystemInterface::Raycast(Convert::ToNative(ray)));
|
||||||
|
}
|
||||||
|
|
||||||
|
RaycastHit Physics::Raycast(Ray ray, float distance)
|
||||||
|
{
|
||||||
|
return Convert::ToCLI(SHPhysicsSystemInterface::Raycast(Convert::ToNative(ray), distance));
|
||||||
|
}
|
||||||
|
|
||||||
|
RaycastHit Physics::Linecast(Vector3 start, Vector3 end)
|
||||||
|
{
|
||||||
|
return Convert::ToCLI(SHPhysicsSystemInterface::Linecast(Convert::ToNative(start), Convert::ToNative(end)));
|
||||||
|
}
|
||||||
|
|
||||||
|
RaycastHit Physics::ColliderRaycast(GameObject object, Ray ray)
|
||||||
|
{
|
||||||
|
return Convert::ToCLI(SHPhysicsSystemInterface::ColliderRaycast(object.EntityId, Convert::ToNative(ray)));
|
||||||
|
}
|
||||||
|
|
||||||
|
RaycastHit Physics::ColliderRaycast(GameObject object, Ray ray, float distance)
|
||||||
|
{
|
||||||
|
return Convert::ToCLI(SHPhysicsSystemInterface::ColliderRaycast(object.EntityId, Convert::ToNative(ray), distance));
|
||||||
|
}
|
||||||
|
|
||||||
|
RaycastHit Physics::ColliderRaycast(GameObject object, int shapeIndex, Ray ray)
|
||||||
|
{
|
||||||
|
return Convert::ToCLI(SHPhysicsSystemInterface::ColliderRaycast(object.EntityId, shapeIndex, Convert::ToNative(ray)));
|
||||||
|
}
|
||||||
|
|
||||||
|
RaycastHit Physics::ColliderRaycast(GameObject object, int shapeIndex, Ray ray, float distance)
|
||||||
|
{
|
||||||
|
return Convert::ToCLI(SHPhysicsSystemInterface::ColliderRaycast(object.EntityId, shapeIndex, Convert::ToNative(ray), distance));
|
||||||
|
}
|
||||||
|
|
||||||
|
RaycastHit Physics::ColliderLineCast(GameObject object, Vector3 start, Vector3 end)
|
||||||
|
{
|
||||||
|
return Convert::ToCLI(SHPhysicsSystemInterface::ColliderLinecast(object.EntityId, Convert::ToNative(start), Convert::ToNative(end)));
|
||||||
|
}
|
||||||
|
|
||||||
|
RaycastHit Physics::ColliderLineCast(GameObject object, int shapeIndex, Vector3 start, Vector3 end)
|
||||||
|
{
|
||||||
|
return Convert::ToCLI(SHPhysicsSystemInterface::ColliderLinecast(object.EntityId, shapeIndex, Convert::ToNative(start), Convert::ToNative(end)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Private Function Member Definitions */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
RaycastHit Physics::generateDefaultResult()
|
||||||
|
{
|
||||||
|
RaycastHit default;
|
||||||
|
default.Hit = false;
|
||||||
|
default.Other = System::Nullable<GameObject>();
|
||||||
|
default.Position = Vector3::Zero;
|
||||||
|
default.Normal = Vector3::Zero;
|
||||||
|
default.Distance = System::Single::PositiveInfinity;
|
||||||
|
default.CollisionShapeIndex = -1;
|
||||||
|
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
} // namespace SHADE
|
|
@ -0,0 +1,128 @@
|
||||||
|
/****************************************************************************************
|
||||||
|
* \file Physics.hxx
|
||||||
|
* \author Diren D Bharwani, diren.dbharwani, 390002520
|
||||||
|
* \brief Interface for the managed Physics class.
|
||||||
|
*
|
||||||
|
* \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||||
|
* disclosure of this file or its contents without the prior written consent
|
||||||
|
* of DigiPen Institute of Technology is prohibited.
|
||||||
|
****************************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Project Includes
|
||||||
|
#include "Math/Ray.hxx"
|
||||||
|
#include "RaycastHit.hxx"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Type Definitions */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
public ref class Physics abstract sealed
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Properties */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
static property Vector3 Gravity
|
||||||
|
{
|
||||||
|
Vector3 get();
|
||||||
|
void set(Vector3 value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(Diren): Add more properties for physics system settings.
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Raycast Function Members */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Casts an infinite ray into the world.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ray">The ray to cast.</param>
|
||||||
|
/// <returns>The result of the raycast.</returns>
|
||||||
|
static RaycastHit Raycast (Ray ray);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Casts a ray for a given distance into the world.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ray">The ray to cast.</param>
|
||||||
|
/// <param name="distance">The distance to cast the ray.</param>
|
||||||
|
/// <returns>The result of the raycast.</returns>
|
||||||
|
static RaycastHit Raycast (Ray ray, float distance);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Casts a bounded ray into the world.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="start">The start of the bounded ray.</param>
|
||||||
|
/// <param name="end">The end of the bounded ray.</param>
|
||||||
|
/// <returns>The result of the raycast.</returns>
|
||||||
|
static RaycastHit Linecast (Vector3 start, Vector3 end);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Casts an infinite ray w.r.t a GameObject.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="object">The GameObject to cast the ray to.</param>
|
||||||
|
/// <param name="ray">The ray to cast.</param>
|
||||||
|
/// <returns>The result of the raycast.</returns>
|
||||||
|
static RaycastHit ColliderRaycast (GameObject object, Ray ray);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Casts a ray for a given distance w.r.t a GameObject.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="object">The GameObject to cast the ray to.</param>
|
||||||
|
/// <param name="ray">The ray to cast.</param>
|
||||||
|
/// <param name="distance">The distance to cast the ray.</param>
|
||||||
|
/// <returns>The result of the raycast.</returns>
|
||||||
|
static RaycastHit ColliderRaycast (GameObject object, Ray ray, float distance);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Casts an infinite ray w.r.t a specific collider on a GameObject.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="object">The GameObject to cast the ray to.</param>
|
||||||
|
/// <param name="shapeIndex">The collision shape index on the collider to cast to.</param>
|
||||||
|
/// <param name="ray">The ray to cast.</param>
|
||||||
|
/// <returns>The result of the raycast.</returns>
|
||||||
|
static RaycastHit ColliderRaycast (GameObject object, int shapeIndex, Ray ray);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Casts a ray for a given distance w.r.t a specific collider on a GameObject.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="object">The GameObject to cast the ray to.</param>
|
||||||
|
/// <param name="shapeIndex">The collision shape index on the collider to cast to.</param>
|
||||||
|
/// <param name="ray">The ray to cast.</param>
|
||||||
|
/// <param name="distance">The distance to cast the ray.</param>
|
||||||
|
/// <returns>The result of the raycast.</returns>
|
||||||
|
static RaycastHit ColliderRaycast (GameObject object, int shapeIndex, Ray ray, float distance);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Casts a bounded ray w.r.t a GameObject.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="object">The GameObject to cast the ray to.</param>
|
||||||
|
/// <param name="start">The start of the bounded ray.</param>
|
||||||
|
/// <param name="end"></param>
|
||||||
|
/// <returns>The result of the raycast.</returns>
|
||||||
|
static RaycastHit ColliderLineCast (GameObject object, Vector3 start, Vector3 end);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Casts a bounded ray w.r.t a specific collider on a GameObject.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="object">The GameObject to cast the ray to.</param>
|
||||||
|
/// <param name="shapeIndex">The collision shape index on the collider to cast to.</param>
|
||||||
|
/// <param name="start">The start of the bounded ray.</param>
|
||||||
|
/// <param name="end">The end of the bounded ray.</param>
|
||||||
|
/// <returns>The result of the raycast.</returns>
|
||||||
|
static RaycastHit ColliderLineCast (GameObject object, int shapeIndex, Vector3 start, Vector3 end);
|
||||||
|
|
||||||
|
private:
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Function Members */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
static RaycastHit generateDefaultResult ();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace SHADE
|
|
@ -0,0 +1,19 @@
|
||||||
|
/****************************************************************************************
|
||||||
|
* \file RaycastHit.cxx
|
||||||
|
* \author Diren D Bharwani, diren.dbharwani, 390002520
|
||||||
|
* \brief Implementation for the managed RaycastHit struct.
|
||||||
|
*
|
||||||
|
* \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||||
|
* disclosure of this file or its contents without the prior written consent
|
||||||
|
* of DigiPen Institute of Technology is prohibited.
|
||||||
|
****************************************************************************************/
|
||||||
|
|
||||||
|
#include "SHpch.h"
|
||||||
|
|
||||||
|
// Primary Header
|
||||||
|
#include "RaycastHit.hxx"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
|
||||||
|
} // namespace SHADE
|
|
@ -0,0 +1,64 @@
|
||||||
|
/****************************************************************************************
|
||||||
|
* \file RaycastHit.hxx
|
||||||
|
* \author Diren D Bharwani, diren.dbharwani, 390002520
|
||||||
|
* \brief Interface for the managed RaycastHit struct.
|
||||||
|
*
|
||||||
|
* \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||||
|
* disclosure of this file or its contents without the prior written consent
|
||||||
|
* of DigiPen Institute of Technology is prohibited.
|
||||||
|
****************************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Project Includes
|
||||||
|
#include "Engine/GameObject.hxx"
|
||||||
|
#include "Math/Vector3.hxx"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Type Definitions */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Defines a struct that contains the information of a raycast.
|
||||||
|
/// </summary>
|
||||||
|
public value struct RaycastHit
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Properties */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether or not the raycast hit a collider.
|
||||||
|
/// </summary>
|
||||||
|
property bool Hit;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The other game object hit.
|
||||||
|
/// </summary>
|
||||||
|
property System::Nullable<GameObject> Other;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The position where the ray cast hit. Zero if not hit.
|
||||||
|
/// </summary>
|
||||||
|
property Vector3 Position;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The normal where the ray cast hit. Zero if not hit.
|
||||||
|
/// </summary>
|
||||||
|
property Vector3 Normal;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The distance the ray was cast. Infinity if not hit.
|
||||||
|
/// </summary>
|
||||||
|
property float Distance;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The index of the collision shape hit on the collider. -1 if not hit.
|
||||||
|
/// </summary>
|
||||||
|
property int CollisionShapeIndex;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace SHADE
|
|
@ -19,6 +19,8 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
// External Dependencies
|
// External Dependencies
|
||||||
#include <msclr/marshal_cppstd.h>
|
#include <msclr/marshal_cppstd.h>
|
||||||
#include "ECS_Base/Managers/SHEntityManager.h"
|
#include "ECS_Base/Managers/SHEntityManager.h"
|
||||||
|
// Project Headers
|
||||||
|
#include "Engine/GameObject.hxx"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -62,14 +64,14 @@ namespace SHADE
|
||||||
return Quaternion{ quat.x, quat.y, quat.z, quat.w };
|
return Quaternion{ quat.x, quat.y, quat.z, quat.w };
|
||||||
}
|
}
|
||||||
|
|
||||||
SHRay Convert::ToNative(Ray vec)
|
SHRay Convert::ToNative(Ray ray)
|
||||||
{
|
{
|
||||||
return SHRay(ToNative(vec.Origin), ToNative(vec.Direction));
|
return SHRay(ToNative(ray.Position), ToNative(ray.Direction));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ray Convert::ToCLI(const SHRay& vec)
|
Ray Convert::ToCLI(const SHRay& ray)
|
||||||
{
|
{
|
||||||
return Ray(ToCLI(vec.position), ToCLI(vec.direction));
|
return Ray(ToCLI(ray.position), ToCLI(ray.direction));
|
||||||
}
|
}
|
||||||
|
|
||||||
SHColour Convert::ToNative(Color col)
|
SHColour Convert::ToNative(Color col)
|
||||||
|
@ -95,6 +97,42 @@ namespace SHADE
|
||||||
return msclr::interop::marshal_as<System::String^>(str);
|
return msclr::interop::marshal_as<System::String^>(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Physics Conversions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
SHPhysicsRaycastResult Convert::ToNative(RaycastHit cli)
|
||||||
|
{
|
||||||
|
// This function shouldn't be used anyway, so we leave the entityHit empty.
|
||||||
|
|
||||||
|
SHPhysicsRaycastResult native;
|
||||||
|
|
||||||
|
native.hit = cli.Hit;
|
||||||
|
native.position = ToNative(cli.Position);
|
||||||
|
native.normal = ToNative(cli.Normal);
|
||||||
|
native.distance = cli.Distance;
|
||||||
|
native.shapeIndex = cli.CollisionShapeIndex;
|
||||||
|
|
||||||
|
return native;
|
||||||
|
}
|
||||||
|
|
||||||
|
RaycastHit Convert::ToCLI(const SHPhysicsRaycastResult& native)
|
||||||
|
{
|
||||||
|
RaycastHit cli;
|
||||||
|
|
||||||
|
cli.Hit = native.hit;
|
||||||
|
cli.Position = ToCLI(native.position);
|
||||||
|
cli.Normal = ToCLI(native.normal);
|
||||||
|
cli.Distance = native.distance;
|
||||||
|
cli.CollisionShapeIndex = native.shapeIndex;
|
||||||
|
|
||||||
|
cli.Other = SHEntityManager::IsValidEID(native.entityHit)
|
||||||
|
? GameObject(native.entityHit)
|
||||||
|
: System::Nullable<GameObject>();
|
||||||
|
|
||||||
|
return cli;
|
||||||
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Handle Conversions */
|
/* Handle Conversions */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -28,9 +28,11 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include "Math/Vector3.hxx"
|
#include "Math/Vector3.hxx"
|
||||||
#include "Math/Quaternion.hxx"
|
#include "Math/Quaternion.hxx"
|
||||||
#include "Math/Ray.hxx"
|
#include "Math/Ray.hxx"
|
||||||
|
#include "Physics/RaycastHit.hxx"
|
||||||
#include "Engine/GenericHandle.hxx"
|
#include "Engine/GenericHandle.hxx"
|
||||||
#include "Math/SHColour.h"
|
#include "Math/SHColour.h"
|
||||||
#include "Graphics/Color.hxx"
|
#include "Graphics/Color.hxx"
|
||||||
|
#include "Physics/Collision/SHPhysicsRaycastResult.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -95,22 +97,22 @@ namespace SHADE
|
||||||
/// <param name="quat">The native Quaternion to convert from.</param>
|
/// <param name="quat">The native Quaternion to convert from.</param>
|
||||||
/// <returns>Managed copy of a native Quaternion.</returns>
|
/// <returns>Managed copy of a native Quaternion.</returns>
|
||||||
static Quaternion ToCLI(const SHQuaternion& quat);
|
static Quaternion ToCLI(const SHQuaternion& quat);
|
||||||
/// Converts from a managed Vector2 to a native Vector2.
|
/// Converts from a managed Ray to a native Ray.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="vec">The managed Vector2 to convert from.</param>
|
/// <param name="ray">The managed Ray to convert from.</param>
|
||||||
/// <returns>Native copy of a managed Vector2.</returns>
|
/// <returns>Native copy of a managed Ray.</returns>
|
||||||
static SHRay ToNative(Ray vec);
|
static SHRay ToNative(Ray vec);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts from a native Vector2 to a managed Vector2.
|
/// Converts from a native Ray to a managed Ray.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="vec">The native Vector2 to convert from.</param>
|
/// <param name="ray">The native Ray to convert from.</param>
|
||||||
/// <returns>Managed copy of a native Vector2.</returns>
|
/// <returns>Managed copy of a native Ray.</returns>
|
||||||
static Ray ToCLI(const SHRay& vec);
|
static Ray ToCLI(const SHRay& ray);
|
||||||
/// Converts from a managed Color to a native Colour.
|
/// Converts from a managed Color to a native Colour.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="vec">The managed Color to convert from.</param>
|
/// <param name="vec">The managed Color to convert from.</param>
|
||||||
/// <returns>Native copy of a managed Color.</returns>
|
/// <returns>Native copy of a managed Color.</returns>
|
||||||
static SHColour ToNative(Color col);
|
static SHColour ToNative(Color ray);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts from a native Colour to a managed Color.
|
/// Converts from a native Colour to a managed Color.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -134,6 +136,24 @@ namespace SHADE
|
||||||
/// <returns>Managed copy of a native std::string.</returns>
|
/// <returns>Managed copy of a native std::string.</returns>
|
||||||
static System::String^ ToCLI(const std::string& str);
|
static System::String^ ToCLI(const std::string& str);
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Physics Conversions */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts from a managed RaycastHit to a native SHPhysicsRaycastResult
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="raycastHit">The managed RaycastHit to convert from.</param>
|
||||||
|
/// <returns>Native copy of a managed RaycastHit.</returns>
|
||||||
|
static SHPhysicsRaycastResult ToNative(RaycastHit cli);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts from native SHPhysicsRaycastResult to a managed RaycastHit.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="raycastResult">The native SHPhysicsRaycastResult to convert from.</param>
|
||||||
|
/// <returns>Managed copy of a native SHPhysicsRaycastResult.</returns>
|
||||||
|
static RaycastHit ToCLI(const SHPhysicsRaycastResult& native);
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Handle Conversions */
|
/* Handle Conversions */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
|
Loading…
Reference in New Issue