Skip to content

Commit

Permalink
Merge pull request #15 from lge-ros2/develop
Browse files Browse the repository at this point in the history
Fix camera buffer data
  • Loading branch information
hyunseok-yang authored Jul 20, 2020
2 parents 6fb4693 + 1c0640a commit 7d01e95
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
12 changes: 10 additions & 2 deletions Assets/Scripts/Devices/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ public partial class Camera : Device
protected RenderTextureReadWrite targetRTrwmode;
protected TextureFormat readbackDstFormat;

void OnPreRender()
{
GL.invertCulling = true;
}

void OnPostRender()
{
GL.invertCulling = false;
}

protected override void OnAwake()
{
cam = gameObject.AddComponent<UnityEngine.Camera>();
Expand Down Expand Up @@ -169,9 +179,7 @@ private IEnumerator CameraWorker()
{
cam.enabled = true;

GL.invertCulling = !GL.invertCulling;
cam.Render();
GL.invertCulling = !GL.invertCulling;

var readback = AsyncGPUReadback.Request(cam.targetTexture, 0, readbackDstFormat);

Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Devices/Lidar.LaserCameraData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void SetBufferData(in NativeArray<byte> buffer)

public float GetDepthData(in float horizontalAngle, in float verticalAngle = 0)
{
var horizontalAngleInCamData = horizontalAngle * Mathf.Deg2Rad;
var horizontalAngleInCamData = (horizontalAngle - centerAngle) * Mathf.Deg2Rad;
var verticalAngleInCamData = verticalAngle * Mathf.Deg2Rad;

var maxAngleTangent = Mathf.Tan(laserCameraHFovHalf * Mathf.Deg2Rad);
Expand Down
11 changes: 5 additions & 6 deletions Assets/Scripts/Devices/Lidar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,8 @@ private void SetupLaserCameraData()

private IEnumerator LaserCameraWorker()
{
var ScanningPeriod = (UpdatePeriod/numberOfLaserCamData);
var axisRotation = Vector3.zero;
var waitForSeconds = new WaitForSeconds(ScanningPeriod * adjustWaitingPeriod);
var waitForSeconds = new WaitForSeconds(UpdatePeriod * adjustWaitingPeriod);

while (true)
{
Expand Down Expand Up @@ -217,9 +216,9 @@ private IEnumerator LaserCameraWorker()
// Debug.Assert(readback.done);

data.SetBufferData(readback.GetData<byte>());

yield return waitForSeconds;
}

yield return waitForSeconds;
}
}

Expand Down Expand Up @@ -253,10 +252,10 @@ protected override void GenerateMessage()

var convertedRayAngleH = (rayAngleH >= -laserCameraHFovHalf) ? rayAngleH : (360 + rayAngleH);
var dataIndexByAngle = (uint)Mathf.Round(convertedRayAngleH / laserCameraHFov);

var laserScanData = laserCamData[dataIndexByAngle];
var centerAngleInCamData = laserScanData.CenterAngle;

var depthData = laserScanData.GetDepthData(convertedRayAngleH - centerAngleInCamData);
var depthData = laserScanData.GetDepthData(convertedRayAngleH);

var rayDistance = (depthData > 0) ? depthData * (float)rangeMax : Mathf.Infinity;

Expand Down
2 changes: 1 addition & 1 deletion ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ PlayerSettings:
16:10: 1
16:9: 1
Others: 1
bundleVersion: 1.3.0
bundleVersion: 1.3.2
preloadedAssets: []
metroInputSource: 0
wsaTransparentSwapchain: 0
Expand Down

0 comments on commit 7d01e95

Please sign in to comment.