Ständige Probleme mit C++ !
-
Hallo liebe Community
Leider habe ich oft Probleme mit C++ und weiß nicht, ob mein Code schuld ist. Klar sagt man natürlich, es muss am Code liegen, aber schaut es euch selbst an.
( Achtet nicht darauf, was die Funktion macht oder wie es programmiert ist )
Hier der Ablauf, falls der Code umständlich ist:
TextureSize.x = 512.0f;
TextureSize.y = 512.0f;
TextureEnd.x = 512.0f;
TextureEnd.y = 512.0f;
PixelToTexel( TextureEnd , TextureSize )
(
FLOAT TexelX = ( 1.0F / pSize->x );
FLOAT TexelY = ( 1.0F / pSize->y );
return D3DXVECTOR2( ( TexelX * pPixel->x ) , ( TexelY * pPixel->y ) );
}
nunja aber es kommt dann das dabei raus:
Input
X:512.000000
Y:512.000000
Output
X:512.000000
Y:512.000000dabei müsste beim Output 1.0f rauskommen!
wieso?float TexelX = 1.0f / 512.0f; // = 0.001953125F
float TexelY = 1.0f / 512.0f; // = 0.001953125F
D3DXVECTOR2( 1.0F ( 0.001953125F * 512.0F ) , 1.0F ( 0.001953125F * 512.0F ) );D3DXVECTOR2 PixelToTexel( LPD3DXVECTOR2 pPixel , LPD3DXVECTOR2 pSize ) { FLOAT TexelX = ( 1.0F / pSize->x ); FLOAT TexelY = ( 1.0F / pSize->y ); return D3DXVECTOR2( ( TexelX * pPixel->x ) , ( TexelY * pPixel->y ) ); } TCHAR szOutput[100]; sprintf(szOutput,"Input\nX:%f\nY:%f\n",TextureEnd.x,TextureEnd.y); OutputDebugString(szOutput); PixelToTexel( &TextureEnd , &TextureSize ); sprintf(szOutput,"Output\nX:%f\nY:%f\n",TextureEnd.x,TextureEnd.y); OutputDebugString(szOutput);
-
Ich fürchte, Du hast den Return-Wert gar nicht verarbeitet.
TCHAR szOutput[100]; sprintf(szOutput,"Input\nX:%f\nY:%f\n",TextureEnd.x,TextureEnd.y); OutputDebugString(szOutput); D3DXVECTOR2 out=PixelToTexel( &TextureEnd , &TextureSize ); sprintf(szOutput,"Output\nX:%f\nY:%f\n",out.x,out.y); OutputDebugString(szOutput);