chrrox
12-05-2009, 01:27 PM
Could anyone tell me how to build a function from this dotnet code into max.
namespace EndianReverser {
class Class1 {
static void Main(string[] args) {
Console.WriteLine("0xAABBCCDD = 0x{0}",
EndianReverse(0xAABBCCDD).ToString("X"));
Console.WriteLine("0xFF000000 = 0x{0}",
EndianReverse(0xFF000000).ToString("X"));
Console.WriteLine("0xFF = 0x{0}", EndianReverse(0xFF).ToString("X"))
;
}
static uint EndianReverse(uint x) {
return ((x<<24) | ((x & 0xff00)<<8) | ((x & 0xff0000)> >8) | (x>>24))
;
}
}
}
this is what I want to accomplish using dotnet in max instead of needing a plugin also in max.
the plugin code does this function.
// -- floatSwap ---------------------------------------------------
//
float FloatSwap( float f )
{
union
{
float f;
unsigned char b[4];
} dat1, dat2;
dat1.f = f;
dat2.b[0] = dat1.b[3];
dat2.b[1] = dat1.b[2];
dat2.b[2] = dat1.b[1];
dat2.b[3] = dat1.b[0];
return dat2.f;
}
Value *Ext_FloatSwap_cf(Value **arg_list, int count)
{
// Check the function receives one argument
check_arg_count(Ext_FloatSwap, 1, count);
// Check the function argument is a Float
type_check(arg_list[0], Float, "argument");
float intern = FloatSwap(arg_list[0]->to_float());
return new Float(FloatSwap(arg_list[0]->to_float()));
}
// ----------------------------------------------------------------
so in max I can do floatswap() and it will change the endian order of that variable float
namespace EndianReverser {
class Class1 {
static void Main(string[] args) {
Console.WriteLine("0xAABBCCDD = 0x{0}",
EndianReverse(0xAABBCCDD).ToString("X"));
Console.WriteLine("0xFF000000 = 0x{0}",
EndianReverse(0xFF000000).ToString("X"));
Console.WriteLine("0xFF = 0x{0}", EndianReverse(0xFF).ToString("X"))
;
}
static uint EndianReverse(uint x) {
return ((x<<24) | ((x & 0xff00)<<8) | ((x & 0xff0000)> >8) | (x>>24))
;
}
}
}
this is what I want to accomplish using dotnet in max instead of needing a plugin also in max.
the plugin code does this function.
// -- floatSwap ---------------------------------------------------
//
float FloatSwap( float f )
{
union
{
float f;
unsigned char b[4];
} dat1, dat2;
dat1.f = f;
dat2.b[0] = dat1.b[3];
dat2.b[1] = dat1.b[2];
dat2.b[2] = dat1.b[1];
dat2.b[3] = dat1.b[0];
return dat2.f;
}
Value *Ext_FloatSwap_cf(Value **arg_list, int count)
{
// Check the function receives one argument
check_arg_count(Ext_FloatSwap, 1, count);
// Check the function argument is a Float
type_check(arg_list[0], Float, "argument");
float intern = FloatSwap(arg_list[0]->to_float());
return new Float(FloatSwap(arg_list[0]->to_float()));
}
// ----------------------------------------------------------------
so in max I can do floatswap() and it will change the endian order of that variable float
