Jump to content

  • Log In with Google      Sign In   
  • Create Account


kurlyak

Member Since 14 Nov 2008
Offline Last Active Apr 26 2013 11:49 AM
-----

Posts I've Made

In Topic: Software rendering and Camera - problem

24 April 2013 - 12:14 AM

Hi guys! Very thanks for you attention.

 

For example I have front poly of cube 1st tri:

 

2-3

| /

1

 

and second tri:

   2

 /  |

1-3

 

Then run program, and move cube left behind left edge of screen. My code write log file:

 







num_tri=1 : tri=0 : y1=-9.166122 : y2=9.166122 : y3=1.458612
num_tri=2 : tri=1 : y1=-9.166122 : y2=1.458612 : y3=-1.458612
num_tri=1 : tri=0 : y1=-9.166122 : y2=9.166122 : y3=1.458612
num_tri=2 : tri=1 : y1=-9.166122 : y2=1.458612 : y3=-1.458612
num_tri=1 : tri=0 : y1=-13.575529 : y2=13.575529 : y3=1.483807
num_tri=2 : tri=1 : y1=-13.575529 : y2=1.483807 : y3=-1.483807
num_tri=1 : tri=0 : y1=-26.473291 : y2=26.473291 : y3=1.513117
num_tri=2 : tri=1 : y1=-26.473291 : y2=1.513117 : y3=-1.513117
num_tri=1 : tri=0 : y1=-670.692383 : y2=670.692383 : y3=1.546930
num_tri=2 : tri=1 : y1=-670.692383 : y2=1.546930 : y3=-1.546930
num_tri=1 : tri=0 : y1=-670.692383 : y2=670.692383 : y3=1.546930
num_tri=2 : tri=1 : y1=-670.692383 : y2=1.546930 : y3=-1.546930
num_tri=1 : tri=0 : y1=-670.692383 : y2=670.692383 : y3=1.546930
num_tri=2 : tri=1 : y1=-670.692383 : y2=1.546930 : y3=-1.546930
num_tri=1 : tri=0 : y1=28.466400 : y2=-28.466400 : y3=1.585725
num_tri=2 : tri=1 : y1=28.466400 : y2=1.585725 : y3=-1.585725
num_tri=1 : tri=0 : y1=13.883531 : y2=-13.883531 : y3=1.630078


 

where num_tri = is count of triangle to draw presently, tri = number of triangle (front face cube tri 0 and 1) and y1, y2, y3 - is Y coord of vert 1,2,3. This records log file before fault. As you can see y1 coord was y1=-670.692383 (vert1 - y1 is located below screen and left) and next record abrupt y1 = y1=28.466400 (that means vert1- y1 is located in range screen).

 

I think my clipping OK because in rendering process draw only triangle 0 and 1 (front face of cuble) and this show log file. But code:

 







for(int i = 0; i < 12; i++)
{
My3DVector3 v1 = My3DVector3(pMy3DTriangle_Original[i].v1.x,
		pMy3DTriangle_Original[i].v1.y,
		pMy3DTriangle_Original[i].v1.z);

My3DVector3 v2 = My3DVector3(pMy3DTriangle_Original[i].v2.x,
		pMy3DTriangle_Original[i].v2.y,
		pMy3DTriangle_Original[i].v2.z);

My3DVector3 v3 = My3DVector3(pMy3DTriangle_Original[i].v3.x,
		pMy3DTriangle_Original[i].v3.y,
		pMy3DTriangle_Original[i].v3.z);


My3DVector3 m_BoundsMin, m_BoundsMax;

m_BoundsMin = My3DVector3( 999999.0f, 999999.0f, 999999.0f );
m_BoundsMax = My3DVector3( -999999.0f, -999999.0f, -999999.0f );

if ( v1.x < m_BoundsMin.x ) m_BoundsMin.x = v1.x;
if ( v1.y < m_BoundsMin.y ) m_BoundsMin.y = v1.y;
if ( v1.z < m_BoundsMin.z ) m_BoundsMin.z = v1.z;
if ( v1.x > m_BoundsMax.x ) m_BoundsMax.x = v1.x;
if ( v1.y > m_BoundsMax.y ) m_BoundsMax.y = v1.y;
if ( v1.z > m_BoundsMax.z ) m_BoundsMax.z = v1.z;

if ( v2.x < m_BoundsMin.x ) m_BoundsMin.x = v2.x;
if ( v2.y < m_BoundsMin.y ) m_BoundsMin.y = v2.y;
if ( v2.z < m_BoundsMin.z ) m_BoundsMin.z = v2.z;
if ( v2.x > m_BoundsMax.x ) m_BoundsMax.x = v2.x;
if ( v2.y > m_BoundsMax.y ) m_BoundsMax.y = v2.y;
if ( v2.z > m_BoundsMax.z ) m_BoundsMax.z = v2.z;

if ( v3.x < m_BoundsMin.x ) m_BoundsMin.x = v3.x;
if ( v3.y < m_BoundsMin.y ) m_BoundsMin.y = v3.y;
if ( v3.z < m_BoundsMin.z ) m_BoundsMin.z = v3.z;
if ( v3.x > m_BoundsMax.x ) m_BoundsMax.x = v3.x;
if ( v3.y > m_BoundsMax.y ) m_BoundsMax.y = v3.y;
if ( v3.z > m_BoundsMax.z ) m_BoundsMax.z = v3.z;

		
if (!BoundsInFrustum(m_BoundsMin, m_BoundsMax, mRes))
pMy3DTriangle_Transformed[i].TriState_Clipped = CLIPPED;	
else
pMy3DTriangle_Transformed[i].TriState_Clipped = NOTCLIPPED;
}

And render proc:

 







DDraw_Lock_Back_Surface();

myTRI = 0;
myNumTri = 0;
	
for ( int i = 0; i < 12; i++)
{
if(pMy3DTriangle_Transformed[i].TriState_Cull == CULL) continue;
if(pMy3DTriangle_Transformed[i].TriState_Clipped == CLIPPED) continue;
			
			
myTRI = i;
myNumTri++;

FILE *f;
f = fopen("log.txt", "at");
char szBuff[256];
sprintf_s(szBuff,256, "num_tri=%d : tri=%d : y1=%f : y2=%f : y3=%f\n", myNumTri,
myTRI, pMy3DTriangle_Transformed[i].v1.y, pMy3DTriangle_Transformed[i].v2.y, pMy3DTriangle_Transformed[i].v3.y);
fwrite((void*)szBuff, strlen(szBuff), 1, f);
fclose(f);

			
Draw_Textured_Triangle(pMy3DTriangle_Transformed[i], back_buffer, back_lpitch);
		}
DDraw_Unlock_Back_Surface();

DDraw_Flip();






void CMy3DApp::Draw_Textured_Triangle(My3DTriangle tri,
		UCHAR *dest_buffer,   // pointer to video buffer
		int mem_pitch)        // bytes per line, 320, 640 etc.
{
int side;
float x1, x2, x3;
float y1, y2, y3;
float iz1, uiz1, viz1, iz2, uiz2, viz2, iz3, uiz3, viz3;
float tempf;
int y1i, y2i, y3i;
float dxdy1, dxdy2, dxdy3;
float dy;
float dyl, dyr;

x1 = tri.vScreen1.x + 0.5f;
y1 = tri.vScreen1.y + 0.5f;
x2 = tri.vScreen2.x + 0.5f;
y2 = tri.vScreen2.y + 0.5f;
x3 = tri.vScreen3.x + 0.5f;
y3 = tri.vScreen3.y + 0.5f;

iz1 = 1.0f / tri.v1.z;
iz2 = 1.0f / tri.v2.z;
iz3 = 1.0f / tri.v3.z;

uiz1 = tri.v1.tu * iz1;
viz1 = tri.v1.tv * iz1;
uiz2 = tri.v2.tu * iz2;
viz2 = tri.v2.tv * iz2;
uiz3 = tri.v3.tu * iz3;
viz3 = tri.v3.tv * iz3;

#define swapfloat(x, y) tempf = x; x = y; y = tempf;

if (y1 > y2)
{
swapfloat(x1, x2);
swapfloat(y1, y2);
swapfloat(iz1, iz2);
swapfloat(uiz1, uiz2);
swapfloat(viz1, viz2);
}
if (y1 > y3)
{
swapfloat(x1, x3);
swapfloat(y1, y3);
swapfloat(iz1, iz3);
swapfloat(uiz1, uiz3);
swapfloat(viz1, viz3);
}
if (y2 > y3)
{
swapfloat(x2, x3);
swapfloat(y2, y3);
swapfloat(iz2, iz3);
swapfloat(uiz2, uiz3);
swapfloat(viz2, viz3);
}
	
#undef swapfloat

//variables for log file
myY1 = y1;
myY2 = y2;
myY3 = y3;
	

y1i = (int) y1;
y2i = (int) y2;
y3i = (int) y3;

if ((y1i == y2i && y1i == y3i) || ((int) x1 == (int) x2 && (int) x1 == (int) x3))
return;


dxdy1 = 0.0;
dxdy2 = 0.0;
dxdy3 = 0.0;

if (y2 > y1)
dxdy1 = (x2 - x1) / (y2 - y1);
if (y3 > y1)
dxdy2 = (x3 - x1) / (y3 - y1);
if (y3 > y2)
dxdy3 = (x3 - x2) / (y3 - y2);

// Determine which side of the poly the longer edge is on
	
side = dxdy2 > dxdy1;

if (y1 == y2)
side = x1 > x2;
if (y2 == y3)
	side = x3 > x2;

int nMinClipY = nViewY;
int nMaxClipY = nViewHeight;

int nMinClipX = nViewX;
int nMaxClipX = nViewWidth;
	
if(y1i> nMaxClipY) y1i = 599;
if(y2i> nMaxClipY) y2i = 599;
if(y3i> nMaxClipY) y3i = 599;

if(y1i< nMinClipY) y1i = 0;
if(y2i< nMinClipY) y2i = 0;
if(y3i< nMinClipY) y3i = 0;


if (!side)	// Longer edge is on the left side
{
	
dyl = y3 - y1;
dxdyl = (x3 - x1) / dyl;
dudyl = (uiz3 - uiz1) / dyl;
dvdyl = (viz3 - viz1) / dyl;
dzdyl = (iz3 - iz1) / dyl;
	
dy = 1 - (y1 - y1i);
xl = x1 + dy * dxdyl;
ul = uiz1 + dy * dudyl;
vl = viz1 + dy * dvdyl;
zl = iz1 + dy * dzdyl;

if(y1 < nMinClipY)
{
dy = nMinClipY - y1;
xl = x1 + dy * dxdyl;
ul = uiz1 + dy * dudyl;
vl = viz1 + dy * dvdyl;
zl = iz1 + dy * dzdyl;

}

if (y1 < y2)	// Draw upper segment if possibly visible
{
		
dyr = y2 - y1;
dxdyr = (x2 - x1) / dyr;
dudyr = (uiz2 - uiz1) / dyr;
dvdyr = (viz2 - viz1) / dyr;
dzdyr = (iz2 - iz1) / dyr;

xr = x1 + dy * dxdyr;
ur = uiz1 + dy * dudyr;
vr = viz1 + dy * dvdyr;
zr = iz1 + dy * dzdyr;

if(y1 < nMinClipY)
{
dy = nMinClipY - y1;
xr = x1 + dy * dxdyr;
ur = uiz1 + dy * dudyr;
vr = viz1 + dy * dvdyr;
zr = iz1 + dy * dzdyr;

}


Draw_Textured_Poly(y1i, y2i, back_buffer, back_lpitch);

}
if (y2 < y3)	// Draw lower segment if possibly visible
{

dyr = y3 - y2;
dxdyr = (x3 - x2) / dyr;
dudyr = (uiz3 - uiz2) / dyr;
dvdyr = (viz3 - viz2) / dyr;
dzdyr = (iz3 - iz2) / dyr;

xr = x2 + (1 - (y2 - y2i)) * dxdyr;
ur = uiz2 + (1 - (y2 - y2i)) * dudyr;
vr = viz2 + (1 - (y2 - y2i)) * dvdyr;
zr = iz2 + (1 - (y2 - y2i)) * dzdyr;

if(y2 < nMinClipY)
{
dy = nMinClipY - y2;
xr = x2 + dy * dxdyr;
ur = uiz2 + dy * dudyr;
vr = viz2 + dy * dvdyr;
zr = iz2 + dy * dzdyr;

}

Draw_Textured_Poly(y2i, y3i, back_buffer, back_lpitch);

}
}

else // Longer edge is on the right side
{
dyr = y3 - y1;
dxdyr = (x3 - x1) / dyr;
dudyr = (uiz3 - uiz1) / dyr;
dvdyr = (viz3 - viz1) / dyr;
dzdyr = (iz3 - iz1) / dyr;

dy = 1 - (y1 - y1i);
xr = x1 + dy * dxdyr;
ur = uiz1 + dy * dudyr;
vr = viz1 + dy * dvdyr;
zr = iz1 + dy * dzdyr;

if(y1 < nMinClipY)
{
dy = nMinClipY - y1;
xr = x1 + dy * dxdyr;
ur = uiz1 + dy * dudyr;
vr = viz1 + dy * dvdyr;
zr = iz1 + dy * dzdyr;
}

if (y1 < y2)	// Draw upper segment if possibly visible
{
dyl = y2 - y1;
dxdyl = (x2 - x1) / dyl;
dudyl = (uiz2 - uiz1) / dyl;
dvdyl = (viz2 - viz1) / dyl;
dzdyl = (iz2 - iz1) / dyl;

xl = x1 + dy * dxdyl;
ul = uiz1 + dy * dudyl;
vl = viz1 + dy * dvdyl;
zl = iz1 + dy * dzdyl;

if(y1 < nMinClipY)
{	
dy = nMinClipY - y1;
xl = x1 + dy * dxdyl;
ul = uiz1 + dy * dudyl;
vl = viz1 + dy * dvdyl;
zl = iz1 + dy * dzdyl;
}

Draw_Textured_Poly(y1i, y2i, back_buffer, back_lpitch);
			
}
if (y2 < y3)	// Draw lower segment if possibly visible
{
		
dyl = y3 - y2;
dxdyl = (x3 - x2) / dyl;
dudyl = (uiz3 - uiz2) / dyl;
dvdyl = (viz3 - viz2) / dyl;
dzdyl = (iz3 - iz2) / dyl;

			
dy = 1 - (y2 - y2i);
xl = x2 + dy * dxdyl;
ul = uiz2 + dy * dudyl;
vl = viz2 + dy * dvdyl;
zl = iz2 + dy * dzdyl;

if(y2 < nMinClipY)
{
dy = nMinClipY - y2;
xl = x2 + dy * dxdyl;
ul = uiz2 + dy * dudyl;
vl = viz2 + dy * dvdyl;
zl = iz2 + dy * dzdyl;

}

Draw_Textured_Poly(y2i, y3i, back_buffer, back_lpitch);

}
}

	
	
} // end Draw_Textured_Triangle

void CMy3DApp::Draw_Textured_Poly(int y1, int y2,
			UCHAR *dest_buffer,   
			int mem_pitch)        
{
int x1, x2;
int dx;
float ui, vi, zi;
float du, dv, dz;

int nMinClipX = nViewX;
int nMaxClipX = nViewWidth;
	

UCHAR *screen_ptr  = NULL;
screen_ptr = dest_buffer + (y1 * mem_pitch);
			
for (int yi = y1; yi<y2; yi++)
{
				
x1 = (int) xl;
x2   = (int) xr;

ui = ul;
vi = vl;
zi = zl;

if ((dx = (x2 - x1))>0)
{
du = (ur - ul)/dx;
dv = (vr - vl)/dx;
dz = (zr - zl)/dx;
}
else
{
du = (ur - ul);
dv = (vr - vl);
dz = (zr - zl);
}
				
if(x1 < nMinClipX)
{
dx = nMinClipX-x1;
ui+=dx * du;
vi+=dx * dv;
zi+=dx * dz;
x1 = nMinClipX;
}

				
if(x1 == 0 && x2 == 0) return;

if(x2> nMaxClipX) x2 = 799;

int indx =  x1 * 4;

for (int xi=x1; xi<x2; xi++)
{

float z = 1.0/zi;
float u = ui  * z;
float v = vi  * z;

int t = (int)u  + (((int)v) << 6);
					

t= t*3;

screen_ptr[indx] = pRes[t];
indx++;

screen_ptr[indx] = pRes[t+1];
indx++;

screen_ptr[indx] = pRes[t+2];
indx++;

screen_ptr[indx] = 0;
indx++;

ui+=du;
vi+=dv;
zi+=dz;
}

xl+=dxdyl;
ul+=dudyl;
vl+=dvdyl;
zl+=dzdyl;

xr+=dxdyr;
ur+=dudyr;
vr+=dvdyr;
zr+=dzdyr;

screen_ptr+=mem_pitch;

				
}
}

 

Run time error occurs in code:

 







int t = (int)u  + (((int)v) << 6);
					
t= t*3;

screen_ptr[indx] = pRes[t]; // HERE ERROR !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
indx++;

screen_ptr[indx] = pRes[t+1];
indx++;

screen_ptr[indx] = pRes[t+2];
indx++;

screen_ptr[indx] = 0;
indx++;

 

And another screenshot. When I move whole cube behind left edge of screen appears this screenshot and next runtime error:

 

44766596.jpg

 

And in normal state without error (no moving, no rotation) cube render fine:

 

60259675.jpg

 

51864110.jpg


In Topic: Direct3DCreate9 issues

10 August 2012 - 06:37 AM

When I set hook, and run exe file of game, my hook procedure LoadLibrary() load:


C:\WINDOWS\system32\ole32.dll
user32.dll
dsound.dll
WINTRUST.dll
advapi32.dll
kernel32.dll
advapi32.dll
WINTRUST.dll
WINTRUST.dll
WINTRUST.dll
WINTRUST.dll
CLBCATQ.DLL
CLBCATQ.DLL
WINTRUST.dll
xinput9_1_0.dll
xinput9_1_0.dll
user32.dll
C:\WINDOWS\system32\ole32.dll
UxTheme.dll
IMM32.dll

Hook proc LoadLibrary() wrote log.txt. And in log.txt not present any d3d9_xxxx.dll. Why?

In Topic: Inheritance IDirectDrawSurface

08 August 2012 - 12:21 PM

All is fine. One function was predetermined wrong (wrong parameters).
Thank you.

In Topic: Inheritance IDirectDrawSurface

08 August 2012 - 09:11 AM

Thank you for your interest.
I trying to write FPS counter for DirectDraw game. I want set hook on DirectDrawCreate() and IDirectDraw, IDirectDrawSurface. Furthermore I run my Launcher.exe, and run my DLL hook procedure, then run my DirectDraw game. And the end - my hook procedure from DLL will itercept Flip() and show FPS in game window.

In Topic: 3dsMax plugin export to .X

23 June 2011 - 12:49 PM

I found that the vert of my model need to multiple with SkinTM matrix. I rewrote the code:

[source lang="cpp"]struct FatVertAll{ int origVert; //index of vertex Point3 pos; //position of vert Point3 normal; Point2 uv[4];};ISkin *skin = GetSkin(node);ISkinContextData *skinData;Matrix3 initTM;if(skin){ skinData = skin->GetContextInterface(node); skin->GetSkinInitTM(node, initTM);}.................FatVertAll fv;for (int i = 0; i < numFace; i++){ Point3 p; for (int k = 0; k < 3; k++) { fv.origVert = TObj->mesh.faces[i].getVert(k); p = TObj->mesh.getVert(fv.origVert); if(skin) { p = initTM.PointTransform(p); } AdjustPoint(p); fv.pos =p;.................. [/source]

This is screenshot:

http://img534.imageshack.us/img534/917/10208485.jpg

Here is a screenshot of what should be a model:

http://img803.imageshack.us/img803/319/39207539.jpg

What I am doing wrong?

P.S. numMax - this is number maximum of afected bones.



PARTNERS