RE: [SDK]Double to long in c++ ?

Date : Thu, 7 Jun 2007 07:33:08 +0100
To : <XSI(at)Softimage.COM>
From : "Kim Aldis" <XSI(at)kim-aldis.co.uk>
Subject : RE: [SDK]Double to long in c++ ?

This is just a guess, but sometimes frames have been known to return as not quite an integer. Possibly, you getting, say 4.0, 3.99999 in a sequence and the cast to LONG is rounding down. Use a round function or add 0.5 before casting. Double check this is the case by logging out the value of T.

 

From: owner-xsi(at)Softimage.COM [mailto:owner-xsi(at)Softimage.COM] On Behalf Of Ahmidou Lyazidi
Sent: 06 June 2007 20:20
To: xsi(at)Softimage.COM
Subject: [SDK]Double to long in c++ ?

 

Hi
In an Operator,we are trying to convert the datas passed by OperatorContex.GetTime to a long.The thing that is strange is when I log the value
it seems good, but when I mutiply it with a fixed value it seems to round it and give me 2 equal values for 2 differant frame
here is the code and the log:

long oOffset = oOp.GetParameterValue(L"TimeOffset");

CTime T = ctxt.GetTime();
Application().LogMessage(L"Current operator Time " + T.GetAsText());

double t = double(T) + oOffset;
long id = (long) t * 3 * nbPoints;

Application().LogMessage( (CString)t +L"* 3 * "+(CString) nbPoints +L" = "+(CString)id);

if(t>=startFrame && t<=endFrame)
{
    Application().LogMessage(L"Reading Frame "+ (CString) t);
    for(long a=0;a<nbPoints;a++)
    {
        inPos[a].Set(position[id],position[id+1],position[id+2]);
        id += 3;
    }
}    


//-----------------------------------------
1* 3 * 4 = 11
NextFrame();
// INFO : Current operator Time 00:00:00:02
// INFO : 2* 3 * 4 = 23
// INFO : Reading Frame 2
NextFrame();
// INFO : Current operator Time 00:00:00:03
// INFO : 3* 3 * 4 = 36
// INFO : Reading Frame 3
NextFrame();
NextFrame();
// INFO : Current operator Time 00:00:00:05
// INFO : 5* 3 * 4 = 60
// INFO : Reading Frame 5
 
Any ideas?
Thanks
A.


Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available.
This site supposedly brought to you by Benjamin Grosser and the Imaging Technology Group.