めいくりぷとのブログ

技術的なことやゲームのことやら・・・

cso ogl

  • o-
#define MODEL_SPAGNA	1984	// スペツナズ
#define MODEL_GIGN		2007	// GIAN
#define MODEL_ELITE		2065	// エリート要因

#define IS_MODEL_SPAGNA(VertexCount)	(VertexCount == MODEL_SPAGNA)
#define IS_MODEL_GIGN(VertexCount)		(VertexCount == MODEL_GIGN)
#define IS_MODEL_ELITE(VertexCount)		(VertexCount == MODEL_ELITE)

/////////////////////////////////////////////////////////////////////////////////

typedef struct _ENTITIES 
{
	BOOL Visible;
	POINT Head;
}ENTITIES, *PENTITIES, *LPENTITIES;

GLint Viewport[4];
GLint VertexCount3f = 0;
GLint MaxEnts = 0;
GLfloat fHighestVertex[3], fLowestVertex[3];
GLfloat fLastPosition[3];
GLdouble Depthcheck[3];
ENTITIES Entities[33] = { NULL };

void glVertex3fv_hook(__in CONST GLfloat *v)
{
	_glVertex3fv(v);

	VertexCount3f++;

	fLastPosition[0] = v[0];
	fLastPosition[1] = v[1];
	fLastPosition[2] = v[2];

	if (v[2] > fHighestVertex[2] || VertexCount3f == 1)
	{
		fHighestVertex[0] = fLastPosition[0];
		fHighestVertex[1] = fLastPosition[1];
		fHighestVertex[2] = fLastPosition[2];
	}

	if (v[2] < fLowestVertex[2] || VertexCount3f == 1)
	{
		fLowestVertex[0] = fLastPosition[0];
		fLowestVertex[1] = fLastPosition[1];
		fLowestVertex[2] = fLastPosition[2];
	}
}

void glPopMatrix_hook()
{
	_glPopMatrix();

	COpenGL *pOpenGL = COpenGL::GetInstance();

	if (VertexCount3f > pOpenGL->GetTargetModelContext() && GetDistance(fHighestVertex, fCamera) > 50.0f
		&& (fHighestVertex[2] - fLowestVertex[2]) > 30.0f)
	{
		if (pOpenGL->IsAimTarget())
		{
			switch (pOpenGL->GetAimTarget())
			{
				case 0:	// TR
				{
					if (!IS_MODEL_ELITE(VertexCount3f)) return;
					break;
				}
				case 1:	// CT
				{
					if (!IS_MODEL_GIGN(VertexCount3f)) return;
					break;
				}
				default:
					break;
			}
		}

		GLfloat pix;
		GLdouble ModelView[16];
		GLdouble ProjView[16];
		GLdouble View2D[3];

		glGetDoublev(GL_MODELVIEW_MATRIX, ModelView);
		glGetDoublev(GL_PROJECTION_MATRIX, ProjView);

		if (gluProject(fHighestVertex[0], fHighestVertex[1], fHighestVertex[2] - 4, ModelView, ProjView,
			Viewport, &View2D[0], &View2D[1], &View2D[2]) == GL_TRUE)
		{
			Head[0] = (float)View2D[0];
			Head[1] = (int)Viewport[3] - (float)View2D[1];

			if (gluProject(fHighestVertex[0], fHighestVertex[1], fHighestVertex[2] + 1, ModelView, ProjView, Viewport, &Depthcheck[0], &Depthcheck[1], &Depthcheck[2]) == GL_TRUE)
			{
				glReadPixels((int)Depthcheck[0], (int)Depthcheck[1], 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &pix);

				if (MaxEnts > 32)
					MaxEnts = 0;

				if (pix >= Depthcheck[2])
					Entities[MaxEnts].Visible = 0x1;

				Entities[MaxEnts].Head.x = (LONG)Head[0];
				Entities[MaxEnts].Head.y = (LONG)Head[1];

				MaxEnts++;
			}
		}
	}
}

void glViewport_hook(__in GLint x, __in GLint y, __in GLsizei width, __in GLsizei height)
{
	Viewport[0] = x;
	Viewport[1] = y;
	Viewport[2] = width;
	Viewport[3] = height;

	_glViewport(x, y, width, height);
};

後はwglSwapBuffersかDrvSwapBuffersフックして...

TDMで壁抜き出来るように戻ったらまたやろうかな...

cso2はもういいかなっていう...