Skip to content

Commit cfa6590

Browse files
committed
fixed depth camera
1 parent 88feb63 commit cfa6590

File tree

8 files changed

+35
-31
lines changed

8 files changed

+35
-31
lines changed

Editor/CustomEditors/ZOSpotControllerEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace ZO.Editor {
1212

13-
[CustomEditor(typeof(ZOSpotController))]
13+
[CustomEditor(typeof(ZOSpotROSController))]
1414
public class ZOSpotControllerEditor : UnityEditor.Editor {
1515

1616
/// <summary>

Runtime/Scripts/Controllers/Robots/Spot/ZOSpotJoystickCmdVel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace ZO {
55
public class ZOSpotJoystickCmdVel : MonoBehaviour {
66

7-
public ZOSpotCharacterController _spotCharacterController;
7+
public ZOSpotUnityCharacterController _spotCharacterController;
88

99

1010
// Start is called before the first frame update

Runtime/Scripts/Controllers/Robots/Spot/ZOSpotJoystickCmdVel.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Scripts/Controllers/Robots/Spot/ZOSpotController.cs renamed to Runtime/Scripts/Controllers/Robots/Spot/ZOSpotROSController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
namespace ZO.Controllers {
1717

1818
[RequireComponent(typeof(ZOROSJointStatesPublisher))]
19-
[RequireComponent(typeof(ZOSpotCharacterController))]
20-
public class ZOSpotController : ZOROSUnityGameObjectBase {
19+
[RequireComponent(typeof(ZOSpotUnityCharacterController))]
20+
public class ZOSpotROSController : ZOROSUnityGameObjectBase {
2121

2222

2323
public string _TwistTopicSubscription = "/cmd_vel";

Runtime/Scripts/Controllers/Robots/Spot/ZOSpotCharacterController.cs.meta renamed to Runtime/Scripts/Controllers/Robots/Spot/ZOSpotROSController.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Scripts/Controllers/Robots/Spot/ZOSpotCharacterController.cs renamed to Runtime/Scripts/Controllers/Robots/Spot/ZOSpotUnityCharacterController.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ namespace ZO {
77
/// <summary>
88
/// Handles all the Unity specific "Character Control" stuff like movement and animation.
99
/// </summary>
10-
public class ZOSpotCharacterController : MonoBehaviour {
10+
public class ZOSpotUnityCharacterController : MonoBehaviour {
1111

12-
public Rigidbody _rigidBody;
12+
public Rigidbody _torsoRigidBody;
1313
public Transform _frontCollider = null;
1414

1515
public CapsuleCollider FrontColliderCapsule {
@@ -114,25 +114,25 @@ public enum StateEnum {
114114
Error
115115
}
116116

117-
public ZOSpotCharacterController.StateEnum State {
117+
public ZOSpotUnityCharacterController.StateEnum State {
118118
get;
119119
private set;
120-
} = ZOSpotCharacterController.StateEnum.Off;
120+
} = ZOSpotUnityCharacterController.StateEnum.Off;
121121

122122
public enum ErrorEnum {
123123
Ok,
124124
GeneralError,
125125
ErrorShutdown
126126
}
127127

128-
public ZOSpotCharacterController.ErrorEnum Error {
128+
public ZOSpotUnityCharacterController.ErrorEnum Error {
129129
get;
130130
private set;
131-
} = ZOSpotCharacterController.ErrorEnum.Ok;
131+
} = ZOSpotUnityCharacterController.ErrorEnum.Ok;
132132

133133

134134

135-
public delegate void SpotControllerStatusDelegate(ZOSpotCharacterController thisClass, Vector2 linearVelocity, float turnVelocityDegreesPerSecond, float orientationDegrees, ZOSpotCharacterController.StateEnum state, ZOSpotCharacterController.ErrorEnum error);
135+
public delegate void SpotControllerStatusDelegate(ZOSpotUnityCharacterController thisClass, Vector2 linearVelocity, float turnVelocityDegreesPerSecond, float orientationDegrees, ZOSpotUnityCharacterController.StateEnum state, ZOSpotUnityCharacterController.ErrorEnum error);
136136
private event SpotControllerStatusDelegate _spotControllerStatusDelegate;
137137
public event SpotControllerStatusDelegate SpotControllerStatus {
138138
add {
@@ -162,22 +162,22 @@ void FixedUpdate() {
162162

163163
if (IsFrontGrounded || IsRearGrounded) {
164164

165-
Vector3 angularVelocity = _rigidBody.angularVelocity;
165+
Vector3 angularVelocity = _torsoRigidBody.angularVelocity;
166166
float torqueYaw = (_targetTurnVelocityDegreesPerSecond * Mathf.Deg2Rad) - angularVelocity.y;
167-
_rigidBody.AddRelativeTorque(new Vector3(0, torqueYaw, 0), ForceMode.VelocityChange);
167+
_torsoRigidBody.AddRelativeTorque(new Vector3(0, torqueYaw, 0), ForceMode.VelocityChange);
168168

169-
Vector3 localVelocity = _rigidBody.transform.InverseTransformDirection(_rigidBody.velocity);
169+
Vector3 localVelocity = _torsoRigidBody.transform.InverseTransformDirection(_torsoRigidBody.velocity);
170170
Vector3 targetVelocity = new Vector3(_targetVelocity.x, 0, _targetVelocity.y);
171171
Vector3 deltaVelocity = targetVelocity - localVelocity;
172-
deltaVelocity = _rigidBody.transform.TransformDirection(deltaVelocity);
173-
_rigidBody.AddForce(deltaVelocity, ForceMode.VelocityChange);
172+
deltaVelocity = _torsoRigidBody.transform.TransformDirection(deltaVelocity);
173+
_torsoRigidBody.AddForce(deltaVelocity, ForceMode.VelocityChange);
174174

175175

176176
}
177177

178178

179179
if (_spotControllerStatusDelegate != null) {
180-
_spotControllerStatusDelegate.Invoke(this, new Vector2(_rigidBody.velocity.x, _rigidBody.velocity.z), _rigidBody.angularVelocity.y * Mathf.Rad2Deg, transform.rotation.eulerAngles.y, State, Error);
180+
_spotControllerStatusDelegate.Invoke(this, new Vector2(_torsoRigidBody.velocity.x, _torsoRigidBody.velocity.z), _torsoRigidBody.angularVelocity.y * Mathf.Rad2Deg, transform.rotation.eulerAngles.y, State, Error);
181181

182182
}
183183

@@ -210,25 +210,25 @@ public void TurnOn() {
210210
}
211211

212212
public void Stand() {
213-
if (State == ZOSpotCharacterController.StateEnum.Sitting) {
213+
if (State == ZOSpotUnityCharacterController.StateEnum.Sitting) {
214214
FrontColliderCapsule.height = FrontColliderCapsule.height * (1.0f / _lieDownScale);
215215
RearColliderCapsule.height = RearColliderCapsule.height * (1.0f / _lieDownScale);
216-
State = ZOSpotCharacterController.StateEnum.UpAndReady;
216+
State = ZOSpotUnityCharacterController.StateEnum.UpAndReady;
217217
}
218218
}
219219

220220
public void Sit() {
221-
if (State == ZOSpotCharacterController.StateEnum.UpAndReady || State == ZOSpotCharacterController.StateEnum.Off) {
221+
if (State == ZOSpotUnityCharacterController.StateEnum.UpAndReady || State == ZOSpotUnityCharacterController.StateEnum.Off) {
222222
FrontColliderCapsule.height = FrontColliderCapsule.height * _lieDownScale;
223223
RearColliderCapsule.height = RearColliderCapsule.height * _lieDownScale;
224-
State = ZOSpotCharacterController.StateEnum.Sitting;
224+
State = ZOSpotUnityCharacterController.StateEnum.Sitting;
225225
}
226226

227227
}
228228

229229

230230
public void Move(Vector2 targetVelocity, float targetTurnVelocityDegreesPerSecond) {
231-
if (State == ZOSpotCharacterController.StateEnum.UpAndReady) {
231+
if (State == ZOSpotUnityCharacterController.StateEnum.UpAndReady) {
232232
_targetVelocity = targetVelocity;
233233
_targetTurnVelocityDegreesPerSecond = targetTurnVelocityDegreesPerSecond;
234234
}

Runtime/Scripts/Controllers/Robots/Spot/ZOSpotController.cs.meta renamed to Runtime/Scripts/Controllers/Robots/Spot/ZOSpotUnityCharacterController.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Samples~/ZeroSimSamples/Sensors/Camera/DepthCamera/Resources/ZORGBDShader.shader

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@
3737
struct appdata
3838
{
3939
float4 vertex : POSITION;
40-
float2 uv : TEXCOORD0;
40+
float2 uv : TEXCOORD0;
4141
};
4242

4343
struct v2f
4444
{
4545
float2 uv : TEXCOORD0;
4646
float4 vertex : SV_POSITION;
47+
float4 viewDir : TEXCOORD1;
4748
};
4849

4950
sampler2D _MainTex;
@@ -66,7 +67,9 @@
6667

6768
#ifdef FLIP_X
6869
o.uv.x = 1.0 - o.uv.x;
69-
#endif
70+
#endif
71+
72+
o.viewDir = mul (unity_CameraInvProjection, float4 (o.uv * 2.0 - 1.0, 1.0, 1.0));
7073

7174
return o;
7275
}
@@ -75,12 +78,13 @@
7578
{
7679
fixed4 col = tex2D(_MainTex, i.uv);
7780
//get depth from depth texture
78-
float depth = tex2D(_CameraDepthTexture, i.uv).r;
81+
float depth01 = tex2D(_CameraDepthTexture, i.uv).r;
7982
// //linear depth between camera and far clipping plane
80-
depth = Linear01Depth(depth);
83+
depth01 = Linear01Depth(depth01);
8184
//depth as distance from camera in units
82-
depth = depth * _ProjectionParams.z;
83-
col.a = depth;
85+
// depth = depth * _ProjectionParams.z;
86+
float3 viewPos = (i.viewDir.xyz / i.viewDir.w) * depth01;
87+
col.a = length(viewPos);
8488
return col;
8589
}
8690
ENDCG

0 commit comments

Comments
 (0)