Compare commits
3 Commits
6e2f9688ed
...
82b5852625
Author | SHA1 | Date | |
---|---|---|---|
![]() |
82b5852625 | ||
![]() |
bda3fd3b37 | ||
![]() |
fa9fb27a98 |
@ -3,6 +3,8 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using UnityEngine;
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using System.IO;
|
||||
|
||||
|
||||
@ -100,18 +102,20 @@ public class RT3script : MonoBehaviour
|
||||
}
|
||||
|
||||
//encode into pixels this camera's coordinates
|
||||
var encodedTransform = new Color[256];
|
||||
var encodedTransform = new Color[32];
|
||||
var tr = cameraList[i].transform.localToWorldMatrix;
|
||||
for (int j = 0; j < 256; j++) {
|
||||
uint floatbits = FloatToIntBits(tr[1,1]);
|
||||
for (int j = 0; j < 32; j++) {
|
||||
//this logic does a bitwise check on the length value at bit j
|
||||
if ((((int)tr[0,0] >> j) & 1)==1) {
|
||||
// use little-endian (ends with least significant bit on the right)
|
||||
if (((floatbits >> ((31)-j)) & 1)==1) {
|
||||
encodedTransform[j] = Color.white;
|
||||
}
|
||||
else {
|
||||
encodedTransform[j] = Color.black;
|
||||
}
|
||||
}
|
||||
outputImage.SetPixels((256*i),outputImage.height-2,256,1, encodedTransform);
|
||||
outputImage.SetPixels((256*i), outputImage.height-2,32,1, encodedTransform);
|
||||
|
||||
//encode into pixels transform matrix for this camera
|
||||
outputImage.Apply();
|
||||
@ -126,6 +130,30 @@ 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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user