Compare commits
No commits in common. "82b5852625f6ee4c7d8864029030c087c0b993bb" and "6e2f9688ed8a438f1f5a4ad0790a769768fb557c" have entirely different histories.
82b5852625
...
6e2f9688ed
@ -3,8 +3,6 @@ using System.Collections.Generic;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
|
|
||||||
@ -102,20 +100,18 @@ public class RT3script : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
//encode into pixels this camera's coordinates
|
//encode into pixels this camera's coordinates
|
||||||
var encodedTransform = new Color[32];
|
var encodedTransform = new Color[256];
|
||||||
var tr = cameraList[i].transform.localToWorldMatrix;
|
var tr = cameraList[i].transform.localToWorldMatrix;
|
||||||
uint floatbits = FloatToIntBits(tr[1,1]);
|
for (int j = 0; j < 256; j++) {
|
||||||
for (int j = 0; j < 32; j++) {
|
|
||||||
//this logic does a bitwise check on the length value at bit j
|
//this logic does a bitwise check on the length value at bit j
|
||||||
// use little-endian (ends with least significant bit on the right)
|
if ((((int)tr[0,0] >> j) & 1)==1) {
|
||||||
if (((floatbits >> ((31)-j)) & 1)==1) {
|
|
||||||
encodedTransform[j] = Color.white;
|
encodedTransform[j] = Color.white;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
encodedTransform[j] = Color.black;
|
encodedTransform[j] = Color.black;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
outputImage.SetPixels((256*i), outputImage.height-2,32,1, encodedTransform);
|
outputImage.SetPixels((256*i),outputImage.height-2,256,1, encodedTransform);
|
||||||
|
|
||||||
//encode into pixels transform matrix for this camera
|
//encode into pixels transform matrix for this camera
|
||||||
outputImage.Apply();
|
outputImage.Apply();
|
||||||
@ -130,30 +126,6 @@ public class RT3script : MonoBehaviour
|
|||||||
|
|
||||||
frameCount += 1;
|
frameCount += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
// inverse in javascript of this:
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32
|
|
||||||
// // Create an ArrayBuffer with 32bits (4 bytes)
|
|
||||||
// const buffer = new ArrayBuffer(4);
|
|
||||||
// const view = new DataView(buffer);
|
|
||||||
// view.setUint32(0, 1057279852); // Max unsigned 32-bit integer
|
|
||||||
// console.log(view.getFloat32(0));
|
|
||||||
|
|
||||||
// Based on this: https://stackoverflow.com/a/16822144
|
|
||||||
[StructLayout(LayoutKind.Explicit)]
|
|
||||||
private struct FloatAndUIntUnion {
|
|
||||||
// The memort layout of this struct looks like this
|
|
||||||
// but both pointers refer to the same memory address.
|
|
||||||
// UInt32Bits: IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
|
|
||||||
// FloatValue: SEEEEEEEEFFFFFFFFFFFFFFFFFFFFFFF
|
|
||||||
[FieldOffset(0)] public uint UInt32Bits;
|
|
||||||
[FieldOffset(0)] public float FloatValue;
|
|
||||||
}
|
|
||||||
public static uint FloatToIntBits(float value) {
|
|
||||||
FloatAndUIntUnion f2i = default(FloatAndUIntUnion);
|
|
||||||
f2i.FloatValue = value; // write as float
|
|
||||||
return f2i.UInt32Bits; // read back as int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnDestroy()
|
void OnDestroy()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user