dom's untested FloatToIntBits
This commit is contained in:
parent
6e2f9688ed
commit
fa9fb27a98
@ -3,6 +3,8 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using UnityEngine;
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using System.IO;
|
||||
|
||||
|
||||
@ -100,18 +102,19 @@ 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) {
|
||||
if (((floatbits >> 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 +129,23 @@ public class RT3script : MonoBehaviour
|
||||
|
||||
frameCount += 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 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