⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shadow.cpp

📁 是3D游戏一书中所讲的游戏引擎fly3D 包括fly3D引擎的源码及应用此引擎开发出来的游戏实例 有fly3D引擎的教程,易于step by step跟学
💻 CPP
字号:
#include "..\..\lib\Fly3D.h"
#include "gamelib.h"

void shadow::reposition(bsp_object *obj)
{
	curobj=obj;
	flyengine->excludecollision=obj;
	hit=flyengine->collision_bsp(flyengine->bsp,obj->pos,obj->pos+vector(0,0,-flyengine->bboxdiag),TYPE_STATIC_MESH);
	flyengine->excludecollision=0;
	if(hit)
	{
		pos=flyengine->hitip+flyengine->hitmesh->faces[flyengine->hitface]->normal;
		align_z(flyengine->hitmesh->faces[flyengine->hitface]->normal);
	}
}

void shadow::draw_simple_shadow()
{
	glDepthMask(GL_FALSE);
	glBlendFunc(GL_ZERO,GL_ONE_MINUS_SRC_COLOR);
	glDisable(GL_DEPTH_TEST);

	glColor3f(
		1.0f-flyengine->shadowcolor.x,
		1.0f-flyengine->shadowcolor.y,
		1.0f-flyengine->shadowcolor.z);

	tc->use(texture);

	static vector x,y;
	x=X*sizex;
	y=Y*sizey;

	glBegin(GL_QUADS);

	glTexCoord2f(1,0);
	glVertex3f(pos.x+x.x-y.x, pos.y+x.y-y.y, pos.z+x.z-y.z);

	glTexCoord2f(1,1);
	glVertex3f(pos.x+x.x+y.x, pos.y+x.y+y.y, pos.z+x.z+y.z);

	glTexCoord2f(0,1);
	glVertex3f(pos.x+y.x-x.x, pos.y+y.y-x.y, pos.z+y.z-x.z);

	glTexCoord2f(0,0);
	glVertex3f(pos.x-x.x-y.x, pos.y+-x.y-y.y, pos.z-x.z-y.z);

	glEnd();

	glEnable(GL_DEPTH_TEST);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
	glDepthMask(GL_TRUE);
}

void shadow::draw()
{
	flyengine->excludecollision=curobj;
	if (flyengine->collision_test(flyengine->bsp,flyengine->cam->pos,pos))
	if (flyengine->hitobj!=flyengine->cam)
		{
		flyengine->excludecollision=0;
		return;
		}
	flyengine->excludecollision=0;

	if(hit)
		draw_simple_shadow();
}

int shadow::get_custom_param_desc(int i,param_desc *pd)
{
	if (pd!=0)
	switch(i)
	{
	case 0:
		pd->type='p';
		pd->data=&texture;
		strcpy(pd->name,"texture");
		break;
	case 1: 
		pd->type='f';
		pd->data=&sizex;
		strcpy(pd->name,"sizex");
		break;
	case 2: 
		pd->type='f';
		pd->data=&sizey;
		strcpy(pd->name,"sizey");
		break;
	}
	return 3;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -