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

📄 brushtemplate.c

📁 3D游戏场景编辑器
💻 C
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************************/
/*  BrushTemplate.c                                                                     */
/*                                                                                      */
/*  Author:       Jim Mischel, Ken Baird, Jeff Lomax, John Pollard, John Moore          */
/*  Description:  Geometric generation of template brushes                              */
/*                                                                                      */
/*  The contents of this file are subject to the Genesis3D Public License               */
/*  Version 1.01 (the "License"); you may not use this file except in                   */
/*  compliance with the License. You may obtain a copy of the License at                */
/*  http://www.genesis3d.com                                                            */
/*                                                                                      */
/*  Software distributed under the License is distributed on an "AS IS"                 */
/*  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See                */
/*  the License for the specific language governing rights and limitations              */
/*  under the License.                                                                  */
/*                                                                                      */
/*  The Original Code is Genesis3D, released March 25, 1999.                            */
/*Genesis3D Version 1.1 released November 15, 1999                            */
/*  Copyright (C) 1999 WildTangent, Inc. All Rights Reserved           */
/*                                                                                      */
/*  Modified by Tom Morris for GenEdit-Classic ver. 0.5, Dec. 15, 2000					*/
/****************************************************************************************/
#include "BrushTemplate.h"
#include "units.h"
#include "facelist.h"
#include "ram.h"

Brush *BrushTemplate_CreateArch (const BrushTemplate_Arch *pTemplate)
{
	Brush		*b, *b2;
	BrushList	*MBList	=BrushList_Create();
	FaceList	*fl;
	Face		*f;
	geVec3d		FaceVerts[4];

	int		i, NumSlits			=pTemplate->NumSlits;
	int		NumCrossSections	=NumSlits + 2;
	geFloat	Thickness			=pTemplate->Thickness;
	geFloat	Width				=pTemplate->Width;
	geFloat	InnerRadius			=pTemplate->Radius;
//	geFloat	WallSize			=pTemplate->WallSize;
	double	StartAngleDegrees	=pTemplate->StartAngle;
	double	EndAngleDegrees		=pTemplate->EndAngle;
	double	AngleDelta			=0;
	double	CurAngle			=0;
	double	StartAngle			=Units_DegreesToRadians (StartAngleDegrees);
	double	EndAngle			=Units_DegreesToRadians (EndAngleDegrees);
	double	Temp;
	geVec3d	TopInnerPoint;
	geVec3d	TopOuterPoint;
	geVec3d	FinalTopInnerPoint;
	geVec3d	FinalTopOuterPoint;
	geVec3d	FinalBottomInnerPoint;
	geVec3d	FinalBottomOuterPoint;
	geVec3d	OldTopInner;
	geVec3d	OldTopOuter;
	geVec3d	OldBottomInner;
	geVec3d	OldBottomOuter;

	//If angles are equal, we have an empty shape...
	if(StartAngle==EndAngle)
	{
		return	NULL;
	}

	//	Put the angles in order...
	if(StartAngle > EndAngle)
	{
		Temp		=StartAngle;
		StartAngle	=EndAngle;
		EndAngle	=Temp;
	}

	geVec3d_Set(&TopInnerPoint, (float)InnerRadius, 0.0, (float)(Width / 2));
	geVec3d_Set(&TopOuterPoint, (float)(InnerRadius + Thickness), 0.0, (float)(Width / 2));

	AngleDelta	=(EndAngle - StartAngle)/(NumCrossSections - 1);
	CurAngle	=StartAngle + AngleDelta;

	//	Create first cross section of 4 vertices ( outer face @ start angle)...
	geVec3d_Set
	(
		&FinalTopInnerPoint,
		(float)(( TopInnerPoint.X * cos( StartAngle ) ) - ( TopInnerPoint.Y * sin( StartAngle ) )),
		(float)(( TopInnerPoint.X * sin( StartAngle ) ) + ( TopInnerPoint.Y * cos( StartAngle ) )),
		TopInnerPoint.Z
	);
	geVec3d_Set
	(
		&FinalTopOuterPoint,
		(float)(( TopOuterPoint.X * cos( StartAngle ) ) - ( TopInnerPoint.Y * sin( StartAngle ) )),
		(float)(( TopOuterPoint.X * sin( StartAngle ) ) + ( TopInnerPoint.Y * cos( StartAngle ) )),
		TopOuterPoint.Z
	);
	FinalBottomInnerPoint	=FinalTopInnerPoint;
	FinalBottomInnerPoint.Z	=-FinalTopInnerPoint.Z;
	FinalBottomOuterPoint	=FinalTopOuterPoint;
	FinalBottomOuterPoint.Z	=-FinalTopOuterPoint.Z;
	OldTopInner				=FinalTopInnerPoint;
	OldTopOuter				=FinalTopOuterPoint;
	OldBottomInner			=FinalBottomInnerPoint;
	OldBottomOuter			=FinalBottomOuterPoint;

	//Create the other cross sections and assign verts to polys after each...
	for(i=0;i < (NumCrossSections-1);i++)
	{
		geVec3d_Set
		(
			&FinalTopInnerPoint,
			(float)(( TopInnerPoint.X * cos( CurAngle ) ) - ( TopInnerPoint.Y * sin( CurAngle ) )),
			(float)(( TopInnerPoint.X * sin( CurAngle ) ) + ( TopInnerPoint.Y * cos( CurAngle ) )),
			TopInnerPoint.Z
		);
		geVec3d_Set
		(
			&FinalTopOuterPoint,
			(float)(( TopOuterPoint.X * cos( CurAngle ) ) - ( TopInnerPoint.Y * sin( CurAngle ) )),
			(float)(( TopOuterPoint.X * sin( CurAngle ) ) + ( TopInnerPoint.Y * cos( CurAngle ) )),
			TopOuterPoint.Z
		);
		FinalBottomInnerPoint = FinalTopInnerPoint;
		FinalBottomInnerPoint.Z = -FinalTopInnerPoint.Z;

		FinalBottomOuterPoint = FinalTopOuterPoint;
		FinalBottomOuterPoint.Z = -FinalTopOuterPoint.Z;

		CurAngle += AngleDelta;

		fl	=FaceList_Create(6);

		//Assign points to the 4 outer poly faces...

		//Top face...
		FaceVerts[0]	=FinalTopInnerPoint;
		FaceVerts[1]	=FinalTopOuterPoint;
		FaceVerts[2]	=OldTopOuter;
		FaceVerts[3]	=OldTopInner;
		f				=Face_Create(4, FaceVerts, 0);
		if(f)
		{
			FaceList_AddFace(fl, f);
		}

		//	Bottom face...
		FaceVerts[3]	=FinalBottomInnerPoint;
		FaceVerts[2]	=FinalBottomOuterPoint;
		FaceVerts[1]	=OldBottomOuter;
		FaceVerts[0]	=OldBottomInner;
		f				=Face_Create(4, FaceVerts, 0);
		if(f)
		{
			FaceList_AddFace(fl, f);
		}

		//	Inner side face...
		FaceVerts[0]	=FinalTopInnerPoint;
		FaceVerts[1]	=OldTopInner;
		FaceVerts[2]	=OldBottomInner;
		FaceVerts[3]	=FinalBottomInnerPoint;
		f				=Face_Create(4, FaceVerts, 0);
		if(f)
		{
			FaceList_AddFace(fl, f);
		}

		//	Outer side face...
		FaceVerts[3]	=FinalTopOuterPoint;
		FaceVerts[2]	=OldTopOuter;
		FaceVerts[1]	=OldBottomOuter;
		FaceVerts[0]	=FinalBottomOuterPoint;
		f				=Face_Create(4, FaceVerts, 0);
		if(f)
		{
			FaceList_AddFace(fl, f);
		}

		//make the end faces
		FaceVerts[0]	=OldTopOuter;
		FaceVerts[1]	=OldBottomOuter;
		FaceVerts[2]	=OldBottomInner;
		FaceVerts[3]	=OldTopInner;
		f				=Face_Create(4, FaceVerts, 0);

		if(f)
		{
			if(pTemplate->Style < 2)	//default to hollow (if they make hollow later)
			{
				if(i)
				{
					Face_SetFixedHull(f, GE_TRUE);
				}
			}
			else
			{
				Face_SetFixedHull(f, GE_TRUE);
			}
			FaceList_AddFace(fl, f);
		}

		FaceVerts[3]	=FinalTopOuterPoint;
		FaceVerts[2]	=FinalBottomOuterPoint;
		FaceVerts[1]	=FinalBottomInnerPoint;
		FaceVerts[0]	=FinalTopInnerPoint;
		f				=Face_Create(4, FaceVerts, 0);

		if(f)
		{
			if(pTemplate->Style < 2)	//default to hollow (if they make hollow later)
			{
				if(i < (NumCrossSections-2))
				{
					Face_SetFixedHull(f, GE_TRUE);
				}
			}
			else
			{
				Face_SetFixedHull(f, GE_TRUE);
			}
			FaceList_AddFace(fl, f);
		}

		if(!pTemplate->Style)
		{
			b2	=Brush_Create(BRUSH_LEAF, fl, NULL);
			if(b2)
			{
				Brush_SetSubtract(b2, pTemplate->TCut);
			}
			BrushList_Append(MBList, b2);
		}
		else
		{
			BrushList	*bl	=BrushList_Create();
			Brush		*bh, *bm;

			b2	=Brush_Create(BRUSH_LEAF, fl, NULL);
			if(b2)
			{
				Brush_SetHollow(b2, GE_TRUE);
				Brush_SetHullSize(b2, pTemplate->WallSize);
				bh	=Brush_CreateHollowFromBrush(b2);
				if(bh)
				{
					Brush_SetHollowCut(bh, GE_TRUE);
					BrushList_Append(bl, b2);
					BrushList_Append(bl, bh);

					bm	=Brush_Create(BRUSH_MULTI, NULL, bl);
					if(bm)
					{
						Brush_SetHollow(bm, GE_TRUE);
						Brush_SetSubtract(bm, pTemplate->TCut);
						Brush_SetHullSize(bm, pTemplate->WallSize);

						BrushList_Append(MBList, bm);
					}
				}
				else
				{
					Brush_Destroy(&b2);
					BrushList_Destroy(&bl);
				}
			}
			else
			{
				BrushList_Destroy(&bl);
			}
		}

		//	Set old points...
		OldTopInner		=FinalTopInnerPoint;
		OldTopOuter		=FinalTopOuterPoint;
		OldBottomInner	=FinalBottomInnerPoint;
		OldBottomOuter	=FinalBottomOuterPoint;

	}
	b	=Brush_Create(BRUSH_MULTI, NULL, MBList);

	if(b)
	{
		Brush_SetSubtract(b, pTemplate->TCut);
	}

	return	b;
}


Brush *BrushTemplate_CreateBox (const BrushTemplate_Box *pTemplate)
{
	//revisit for error handling when merged
	geVec3d		Verts[8];
	geVec3d		FaceVerts[4];
	FaceList	*fl;
	Face		*f;
	Brush		*b;

	fl	=FaceList_Create(6);

	// Vertices 0 to 3 are the 4 corners of the top face
	geVec3d_Set (&Verts[0], (float)-(pTemplate->XSizeTop/2), (float)(pTemplate->YSize/2), (float)-(pTemplate->ZSizeTop/2));
	geVec3d_Set (&Verts[1], (float)-(pTemplate->XSizeTop/2), (float)(pTemplate->YSize/2), (float)(pTemplate->ZSizeTop/2));
	geVec3d_Set (&Verts[2], (float)(pTemplate->XSizeTop/2), (float)(pTemplate->YSize/2), (float)(pTemplate->ZSizeTop/2));
	geVec3d_Set (&Verts[3], (float)(pTemplate->XSizeTop/2), (float)(pTemplate->YSize/2), (float)-(pTemplate->ZSizeTop/2));

	// Vertices 4 to 7 are the 4 corners of the bottom face
	geVec3d_Set (&Verts[4], (float)-(pTemplate->XSizeBot/2), (float)-(pTemplate->YSize/2), (float)-(pTemplate->ZSizeBot/2));
	geVec3d_Set (&Verts[5], (float)(pTemplate->XSizeBot/2), (float)-(pTemplate->YSize/2), (float)-(pTemplate->ZSizeBot/2));
	geVec3d_Set (&Verts[6], (float)(pTemplate->XSizeBot/2), (float)-(pTemplate->YSize/2), (float)(pTemplate->ZSizeBot/2));
	geVec3d_Set (&Verts[7], (float)-(pTemplate->XSizeBot/2), (float)-(pTemplate->YSize/2), (float)(pTemplate->ZSizeBot/2));

	FaceVerts[3]	=Verts[0];
	FaceVerts[2]	=Verts[1];
	FaceVerts[1]	=Verts[2];
	FaceVerts[0]	=Verts[3];

	f	=Face_Create(4, FaceVerts, 0);
	if(f)
	{
		FaceList_AddFace(fl, f);
	}

	FaceVerts[3]	=Verts[4];
	FaceVerts[2]	=Verts[5];
	FaceVerts[1]	=Verts[6];
	FaceVerts[0]	=Verts[7];

	f	=Face_Create(4, FaceVerts, 0);
	if(f)
	{
		FaceList_AddFace(fl, f);
	}

	FaceVerts[3]	=Verts[1];
	FaceVerts[2]	=Verts[7];
	FaceVerts[1]	=Verts[6];
	FaceVerts[0]	=Verts[2];

	f	=Face_Create(4, FaceVerts, 0);
	if(f)
	{
		FaceList_AddFace(fl, f);
	}

	FaceVerts[3]	=Verts[0];
	FaceVerts[2]	=Verts[3];
	FaceVerts[1]	=Verts[5];
	FaceVerts[0]	=Verts[4];

	f	=Face_Create(4, FaceVerts, 0);
	if(f)
	{
		FaceList_AddFace(fl, f);
	}

	FaceVerts[3]	=Verts[0];
	FaceVerts[2]	=Verts[4];
	FaceVerts[1]	=Verts[7];
	FaceVerts[0]	=Verts[1];

	f	=Face_Create(4, FaceVerts, 0);
	if(f)
	{
		FaceList_AddFace(fl, f);
	}

	FaceVerts[3]	=Verts[3];
	FaceVerts[2]	=Verts[2];
	FaceVerts[1]	=Verts[6];
	FaceVerts[0]	=Verts[5];

	f	=Face_Create(4, FaceVerts, 0);
	if(f)
	{
		FaceList_AddFace(fl, f);
	}

	if(!pTemplate->Solid)
	{
		b	=Brush_Create(BRUSH_LEAF, fl, NULL);
		if(b)
		{
			Brush_SetSubtract(b, pTemplate->TCut);
			Brush_SetSheet (b, pTemplate->TSheet);
		}
		return	b;
	}
	else
	{
		// hollow brush
		BrushList	*bl	=BrushList_Create();
		Brush		*bh, *bm;

		b	=Brush_Create(BRUSH_LEAF, fl, NULL);
		if(b)
		{
			Brush_SetHollow(b, GE_TRUE);
			Brush_SetHullSize(b, (float)pTemplate->Thickness);
			bh	=Brush_CreateHollowFromBrush(b);
			if(bh)
			{
				Brush_SetHollowCut(bh, GE_TRUE);
				BrushList_Append(bl, b);
				BrushList_Append(bl, bh);

				bm	=Brush_Create(BRUSH_MULTI, NULL, bl);
				if(bm)
				{
					Brush_SetHollow(bm, GE_TRUE);
					Brush_SetSubtract(bm, pTemplate->TCut);
					Brush_SetHullSize(bm, (float)pTemplate->Thickness);
					return	bm;
				}
			}
			else
			{
				Brush_Destroy(&b);
				BrushList_Destroy(&bl);
			}
		}
		else
		{
			BrushList_Destroy(&bl);
		}
	}

	return	NULL;
}


Brush *BrushTemplate_CreateCone (const BrushTemplate_Cone *pTemplate)
{
	int			index, BottomCount;
	geVec3d		StartPoint, CurPoint, OldPoint, OuterFocus;
	geVec3d		FaceVerts[3], *BottomVerts;
	FaceList	*fl;
	Face		*f;
	Brush		*b;

	double CurAngle;
	double AngleDeltaDegrees = 360.0f/(float)pTemplate->VerticalStrips;
	double AngleDelta = UNITS_DEGREES_TO_RADIANS (AngleDeltaDegrees);


	fl	=FaceList_Create(pTemplate->VerticalStrips + 1);
	

⌨️ 快捷键说明

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