Hi, could someone please help me with following code? I want to make a 3D simulation of solar system, therefore I need to calculate julian date from time. My function CalcJulianDate works fine until I create the Direct3DDevice9, then it returns numbers rounded to 2 or less digits. Does someone know why and how to fix it?
This is my code:
#include <windows.h>
#include <d3d9.h>
#include <stdio.h>
// declaration of my function
double CalcJulianDate( SYSTEMTIME );
int WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, int )
{
// some variables
HWND hWnd;
SYSTEMTIME st;
char Buf[255];
double JD;
IDirect3D9* pD3D;
IDirect3DDevice9* pd3dDevice;
// getting current time in UTC
GetSystemTime( &st );
// creating the window and Direct3D9
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, DefWindowProc, 0L, 0L,
hInst, NULL, NULL, NULL, NULL, "DX9", NULL };
RegisterClassEx( &wc );
hWnd = CreateWindow( "DX9", "DX9",
WS_OVERLAPPEDWINDOW, 100, 100, 300, 300, GetDesktopWindow(),
NULL, wc.hInstance, NULL );
if( NULL == ( pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
{
MessageBox( NULL, "Direct3DCreate9", NULL, 0 );
return E_FAIL;
}
// setting parameters for Direct3DDevice9
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
// calculating and displaying the julian date before creating the device
// returns what i need
JD = CalcJulianDate( st );
sprintf( Buf, "%f", JD );
MessageBox( NULL, Buf, NULL, 0 );
// creating the Direct3DDevice9
if( FAILED( pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &pd3dDevice ) ) )
{
MessageBox( NULL, "CreateDevice", NULL, 0 );
return E_FAIL;
}
// calculating and displaying the julian date after creating the device
// now it returns rounded number, but I need full double resolution
JD = CalcJulianDate( st );
sprintf( Buf, "%f", JD );
MessageBox( NULL, Buf, NULL, 0);
// releasing DX objects
if( pd3dDevice != NULL )
pd3dDevice->Release();
if( pD3D != NULL )
pD3D->Release();
return 0;
}
// this function calculates the julian date using very simple algorithm
double CalcJulianDate( SYSTEMTIME st )
{
if( st.wMonth > 2 )
{
st.wMonth += 1;
}
else
{
st.wYear -= 1;
st.wMonth += 13;
}
double dJD;
dJD = 1720981.5 + 365.25 * st.wYear + 30.6 * st.wMonth + st.wDay +
st.wHour / 24.0 + st.wMinute / 1440.0 + st.wSecond / 86400.0;
return dJD;
}
This is my code:
#include <windows.h>
#include <d3d9.h>
#include <stdio.h>
// declaration of my function
double CalcJulianDate( SYSTEMTIME );
int WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, int )
{
// some variables
HWND hWnd;
SYSTEMTIME st;
char Buf[255];
double JD;
IDirect3D9* pD3D;
IDirect3DDevice9* pd3dDevice;
// getting current time in UTC
GetSystemTime( &st );
// creating the window and Direct3D9
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, DefWindowProc, 0L, 0L,
hInst, NULL, NULL, NULL, NULL, "DX9", NULL };
RegisterClassEx( &wc );
hWnd = CreateWindow( "DX9", "DX9",
WS_OVERLAPPEDWINDOW, 100, 100, 300, 300, GetDesktopWindow(),
NULL, wc.hInstance, NULL );
if( NULL == ( pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
{
MessageBox( NULL, "Direct3DCreate9", NULL, 0 );
return E_FAIL;
}
// setting parameters for Direct3DDevice9
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
// calculating and displaying the julian date before creating the device
// returns what i need
JD = CalcJulianDate( st );
sprintf( Buf, "%f", JD );
MessageBox( NULL, Buf, NULL, 0 );
// creating the Direct3DDevice9
if( FAILED( pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &pd3dDevice ) ) )
{
MessageBox( NULL, "CreateDevice", NULL, 0 );
return E_FAIL;
}
// calculating and displaying the julian date after creating the device
// now it returns rounded number, but I need full double resolution
JD = CalcJulianDate( st );
sprintf( Buf, "%f", JD );
MessageBox( NULL, Buf, NULL, 0);
// releasing DX objects
if( pd3dDevice != NULL )
pd3dDevice->Release();
if( pD3D != NULL )
pD3D->Release();
return 0;
}
// this function calculates the julian date using very simple algorithm
double CalcJulianDate( SYSTEMTIME st )
{
if( st.wMonth > 2 )
{
st.wMonth += 1;
}
else
{
st.wYear -= 1;
st.wMonth += 13;
}
double dJD;
dJD = 1720981.5 + 365.25 * st.wYear + 30.6 * st.wMonth + st.wDay +
st.wHour / 24.0 + st.wMinute / 1440.0 + st.wSecond / 86400.0;
return dJD;
}