Compare commits

..

No commits in common. "82b5852625f6ee4c7d8864029030c087c0b993bb" and "6e2f9688ed8a438f1f5a4ad0790a769768fb557c" have entirely different histories.

View File

@ -3,8 +3,6 @@ using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
using System.Runtime.InteropServices;
using System.IO;
@ -102,20 +100,18 @@ public class RT3script : MonoBehaviour
}
//encode into pixels this camera's coordinates
var encodedTransform = new Color[32];
var encodedTransform = new Color[256];
var tr = cameraList[i].transform.localToWorldMatrix;
uint floatbits = FloatToIntBits(tr[1,1]);
for (int j = 0; j < 32; j++) {
for (int j = 0; j < 256; 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 (((floatbits >> ((31)-j)) & 1)==1) {
if ((((int)tr[0,0] >> j) & 1)==1) {
encodedTransform[j] = Color.white;
}
else {
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
outputImage.Apply();
@ -130,30 +126,6 @@ public class RT3script : MonoBehaviour
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()