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

📄 geneditdoc.cpp

📁 3D游戏场景编辑器
💻 CPP
📖 第 1 页 / 共 5 页
字号:
			entityScaleFactor = pDoc->GetEntityScaleInView();

		// Draw an X at the entity's position...
		TopLeft.x = EntPosView.x - EntSizeView.x*entityScaleFactor;	//	post 0.57
		TopLeft.y = EntPosView.y - EntSizeView.y*entityScaleFactor;	//	post 0.57
		BottomRight.x = EntPosView.x + EntSizeView.x*entityScaleFactor;	//	post 0.57
		BottomRight.y = EntPosView.y + EntSizeView.y*entityScaleFactor;	//	post 0.57
		TopRight.x = BottomRight.x;
		TopRight.y = TopLeft.y;
		BottomLeft.x = TopLeft.x;
		BottomLeft.y = BottomRight.y;

		pDC->MoveTo (TopLeft);
		pDC->LineTo (BottomRight);
		pDC->MoveTo (TopRight);
		pDC->LineTo (BottomLeft);

		// g3dc experiment draws a square around entity.
		// do not change pen characteristics in this function
		// it is called by all template, brush and entity types
		pDC->LineTo(TopLeft);
		pDC->LineTo(TopRight);
		pDC->LineTo(BottomRight);
		pDC->LineTo(BottomLeft);
		// end g3dc experiment
	}

	// and then show the aiming arrow and arc stuff...
	if( bShowUI )
	{
		POINT		ArcTopLeft, ArcBottomRight;
		POINT		ptDirSlope ;		// Slope of the "Direction" line
		POINT		ptRotationPoint ;	// Point near end of "Direction" line we rotate to get arrowhead points
		POINT		ptRelRotatePoint ;	// Rotation points about zero
		POINT		ptPlus45 ;			// Final Arrowhead point
		POINT		ptMinus45 ;			// Final Arrowhead point
		POINT		ptStart ;			// Start point for Arc
		POINT		ptEnd ;				// End point of Arc
		float		fPercentIntoLine ;	// Distance into Direction line for rotation point
		float		fDirLength ;		// Direction line length
		float		fEntityLength ;		// Entity length
		float		fAngleToTarget ;	// Radians of arc midpoint
		geFloat		fRadius ;
		geVec3d		Angles ;
		geXForm3d	Xfm ;
		geVec3d		VecTarg ;
		float		fArc ;
		POINT		LineEndView;
		geBoolean	bUIAvailable ;

		// Get the Radius and the Angle  ONE of these must be present to show UI
		bUIAvailable = GE_FALSE ;
		if( pEnt->GetRadius( &fRadius, pEntityDefs ) == GE_FALSE )
			fRadius = 100.0f ;
		else
			bUIAvailable = GE_TRUE ;

		if( pEnt->GetAngles( &Angles, pEntityDefs ) == GE_FALSE )
			geVec3d_Clear( &Angles ) ;
		else
			bUIAvailable = GE_TRUE ;

		if( bUIAvailable == GE_FALSE )
			return ;

		// The camera angles are given in camera coordinates rather than
		// world coordinates (don't ask).
		// So we convert them here.
		if (pEnt->IsCamera ())
		{
			geVec3d_Set(&Angles, Angles.Z, (-Angles.Y-M_PI/2.0f), Angles.X);
		}

		geXForm3d_SetEulerAngles( &Xfm, &Angles ) ;
		geVec3d_Set( &VecTarg, fRadius, 0.0f, 0.0f ) ;
		geXForm3d_Transform( &Xfm, &VecTarg, &VecTarg ) ;
		geVec3d_Add( &(pEnt->mOrigin), &VecTarg, &VecTarg ) ;

		LineEndView = Render_OrthoWorldToView ( v, &VecTarg );

		// Draw to the end point
		pDC->MoveTo( EntPosView ) ;
		pDC->LineTo( LineEndView ) ;

		ptDirSlope.x = LineEndView.x - EntPosView.x ;	// Slope of Direction line
		ptDirSlope.y = LineEndView.y - EntPosView.y ;
				
		fDirLength = (float)sqrt( (ptDirSlope.x*ptDirSlope.x) + (ptDirSlope.y*ptDirSlope.y)) ;	// Length of Direction line
		fEntityLength = (float)sqrt( (EntSizeView.x*EntSizeView.x)+(EntSizeView.y*EntSizeView.y)) ;
		fEntityLength *= 2 ;	// Arrow 2x entity size
		fPercentIntoLine = 1.0f - (fEntityLength / fDirLength ) ;
		ptRotationPoint.x = (long)(ptDirSlope.x * fPercentIntoLine) ;
		ptRotationPoint.y = (long)(ptDirSlope.y * fPercentIntoLine) ;
		ptRotationPoint.x += EntPosView.x ;
		ptRotationPoint.y += EntPosView.y ;

		ptRelRotatePoint.x = ptRotationPoint.x - LineEndView.x ;
		ptRelRotatePoint.y = ptRotationPoint.y - LineEndView.y ;

		ptPlus45.x = (long)(ptRelRotatePoint.x * COS45 - ptRelRotatePoint.y * SIN45 ) ;
		ptPlus45.y = (long)(ptRelRotatePoint.y * COS45 + ptRelRotatePoint.x * SIN45 ) ;
		ptMinus45.x = (long)(ptRelRotatePoint.x * MCOS45 - ptRelRotatePoint.y * MSIN45 ) ;
		ptMinus45.y = (long)(ptRelRotatePoint.y * MCOS45 + ptRelRotatePoint.x * MSIN45 ) ;

		ptPlus45.x += LineEndView.x ;
		ptPlus45.y += LineEndView.y ;
		ptMinus45.x += LineEndView.x ;
		ptMinus45.y += LineEndView.y ;

		pDC->LineTo( ptPlus45 ) ;
		pDC->LineTo( ptMinus45 ) ;
		pDC->LineTo( LineEndView ) ;

		if( pEnt->GetArc( &fArc, pEntityDefs ) == GE_FALSE )
		{
			fArc = 0.0f ;	// All Directions
		}
		if( fArc != 0.0f )			// Draw the arc
		{
			fArc = 2*M_PI - fArc;
			fArc /= 2.0f ;	// We need half the angle
			EntSizeView.x *= 3; 
			EntSizeView.y *= 3;
			EntWidthHeight.x *= 3 ;
			EntWidthHeight.y *= 3 ;
			// Arc BB is an enlarged Entity BB
			ArcTopLeft.x		= EntPosView.x - EntSizeView.x;
			ArcTopLeft.y		= EntPosView.y - EntSizeView.y;
			ArcBottomRight.x	= EntPosView.x + EntSizeView.x;
			ArcBottomRight.y	= EntPosView.y + EntSizeView.y;
		
			fAngleToTarget = (float)atan2( ptDirSlope.y, ptDirSlope.x ) ;	// Angle line leaves
			fAngleToTarget += M_PI ;	// The other side is where the angle starts
			
			ptStart.x = (long)((EntWidthHeight.x) * cos( fAngleToTarget + fArc )) ;
			ptStart.y = (long)((EntWidthHeight.y) * sin( fAngleToTarget + fArc )) ;
			ptEnd.x = (long)((EntWidthHeight.x) * cos( fAngleToTarget - fArc )) ;
			ptEnd.y = (long)((EntWidthHeight.y) * sin( fAngleToTarget - fArc )) ;
			ptStart.x += EntPosView.x ;
			ptStart.y += EntPosView.y ;
			ptEnd.x += EntPosView.x ;
			ptEnd.y += EntPosView.y ;

			// If Start and end point are different
			if( !(ptStart.x == ptEnd.x && ptStart.y == ptEnd.y) )
			{
				pDC->Arc
				( 
					ArcTopLeft.x, ArcTopLeft.y, ArcBottomRight.x, ArcBottomRight.y, 
					ptStart.x, ptStart.y, 
					ptEnd.x, ptEnd.y
				);
			}

			// Draw the two rays out the same distance as the Direction
			ptStart.x = (long)((fDirLength) * cos( fAngleToTarget + fArc )) ;
			ptStart.y = (long)((fDirLength) * sin( fAngleToTarget + fArc )) ;
			ptStart.x += EntPosView.x ;
			ptStart.y += EntPosView.y ;
			pDC->MoveTo( EntPosView ) ;
			pDC->LineTo( ptStart ) ;

			ptEnd.x = (long)((fDirLength) * cos( fAngleToTarget - fArc )) ;
			ptEnd.y = (long)((fDirLength) * sin( fAngleToTarget - fArc )) ;
			ptEnd.x += EntPosView.x ;
			ptEnd.y += EntPosView.y ;
			pDC->MoveTo( EntPosView ) ;
			pDC->LineTo( ptEnd ) ;
		}// Arc for this entity exists
	}
}/* fdocDrawEntity */


// ENUMERATION FUNCTIONS (File Scope)


	
static geBoolean fdocBrushCSGCallback (const Brush *pBrush, void *lParam)
{
	CGenEditDoc *pDoc = (CGenEditDoc *)lParam;

	return (pDoc->BrushIsVisible (pBrush) && (!Brush_IsHint(pBrush)) && (!Brush_IsClip(pBrush)));
}



typedef struct
{
	BOOL Select;
	int WhichGroup;
	CGenEditDoc *pDoc;
} BrushSelectCallbackData;

// ::BrushList_CB Enumeration function to select/deselect brushes
static geBoolean BrushSelect( Brush *pBrush, void *lParam)
{
	BrushSelectCallbackData *pData;

	pData = (BrushSelectCallbackData *)lParam;

	// select/deselect all group brushes
	if( Brush_GetGroupId( pBrush ) == pData->WhichGroup )
	{
		if( pData->Select )
		{	// add this brush to the selected list
			SelBrushList_Add (pData->pDoc->pSelBrushes, pBrush);
		}
		else
		{
			// remove this brush from the selection list
			SelBrushList_Remove (pData->pDoc->pSelBrushes, pBrush);
		}
	}
	return GE_TRUE ;	// Continue enumeration
}/* ::BrushSelect */

// ::EntityList_CB Enumeration function to select/deselect brushes
static geBoolean EntitySelect( CEntity& Entity, void * lParam )
{
	BrushSelectCallbackData *pData;
	CGenEditDoc *pDoc;

	pData = (BrushSelectCallbackData *)lParam;
	pDoc = pData->pDoc;

	if( Entity.GetGroupId () == pData->WhichGroup )
	{
		if( pData->Select )
		{
			pDoc->SelectEntity( &Entity );
		}
		else
		{
			pDoc->DeselectEntity( &Entity );
		}
	}
	return GE_TRUE ;	// Continue enumeration
}/* ::EntitySelect */

#define fdoc_SHOW_ALL_GROUPS -1

typedef struct tagBrushDrawData
{
	const Box3d	*	pViewBox ;
	CDC *		pDC ;
	ViewVars *	v ;
	int GroupId;
	CGenEditDoc *pDoc;
	BrushFlagTest FlagTest;
	uint32		Color;
} BrushDrawData ;

static geBoolean BrushDraw( Brush *pBrush, void *lParam)
{
	BrushDrawData * pData = (BrushDrawData*)lParam ;
	CGenEditDoc * pDoc = pData->pDoc;

	if ((pData->GroupId == fdoc_SHOW_ALL_GROUPS) || (Brush_GetGroupId (pBrush) == pData->GroupId))
	{
		if ((pData->FlagTest == NULL) || pData->FlagTest (pBrush))
		{
			if (pDoc->fdocShowBrush (pBrush, pData->pViewBox))
			{
				Render_RenderBrushFacesOrtho(pData->v, pBrush, pData->pDC->m_hDC);
			}
		}
	}
	return GE_TRUE ;
}/* ::BrushDraw */


static geBoolean BrushDrawSelFacesOrtho(Brush *pBrush, void *lParam)
{
	BrushDrawData	*pData;

	pData	=(BrushDrawData *)lParam;

	Render_RenderBrushSelFacesOrtho(pData->v, pBrush, pData->pDC->m_hDC);

	return	GE_TRUE;
}

static geBoolean BrushDrawSheetFacesOrtho(Brush *pBrush, void *lParam)
{
	BrushDrawData	*pData;

	if(Brush_IsSheet(pBrush))
	{
		pData	=(BrushDrawData *)lParam;

		Render_RenderBrushSheetFacesOrtho(pData->v, pBrush, pData->pDC->m_hDC);
	}
	return	GE_TRUE;
}

static geBoolean EntityDraw( CEntity& Entity, void * lParam )
{
	BrushDrawData *pData;

	pData = (BrushDrawData *)lParam;

	if( Entity.GetGroupId () != pData->GroupId )
		return GE_TRUE ;

	if ( (Entity.IsSelected() == GE_FALSE ) && pData->pDoc->EntityIsVisible( &Entity ) )
	{
		fdocDrawEntity (&Entity, pData->v, pData->pDC, Level_GetEntityDefs (pData->pDoc->pLevel), GE_FALSE );
	}
	return GE_TRUE ;
}/* ::EntityDraw */

static geBoolean	BrushDrawWire3dCB(Brush *pBrush, void *lParam)
{
	BrushDrawData *pData = (BrushDrawData *)lParam;
	CGenEditDoc *pDoc = pData->pDoc;

	if ((pData->GroupId == fdoc_SHOW_ALL_GROUPS) || (Brush_GetGroupId (pBrush) == pData->GroupId))
	{
		if ((pData->FlagTest == NULL) || pData->FlagTest (pBrush))
		{
			if (pDoc->BrushIsVisible (pBrush))
			{
				Render_RenderBrushFaces (pData->v, pBrush, pData->Color);
			}
		}
	}
	return	GE_TRUE ;
}

static geBoolean	BrushDrawWire3dZBufferCB(Brush *pBrush, void *lParam)
{
	BrushDrawData *pData = (BrushDrawData *)lParam;
	CGenEditDoc *pDoc = pData->pDoc;

	if ((pData->GroupId == fdoc_SHOW_ALL_GROUPS) || (Brush_GetGroupId (pBrush) == pData->GroupId))
	{
		if ((pData->FlagTest == NULL) || pData->FlagTest (pBrush))
		{
			if (pDoc->BrushIsVisible (pBrush))
			{
				Render_RenderBrushFacesZBuffer(pData->v, pBrush, pData->Color);
			}
		}
	}
	return	GE_TRUE ;
}

static geBoolean	BrushDrawWireSel3dCB(Brush *b, void *lParam)
{
	BrushDrawData *pData;

	pData = (BrushDrawData *)lParam;
	Render_RenderBrushSelFaces(pData->v, b, pData->Color);
	return	GE_TRUE ;
}

// END ENUMERATION FUNCTIONS


geBoolean CGenEditDoc::fdocShowBrush
	(
	  Brush const *b,
	  Box3d const *ViewBox
	)
{
	return (BrushIsVisible (b) && Brush_TestBoundsIntersect(b, ViewBox));
}/* CGenEditDoc::fdocShowBrush */


BOOL CGenEditDoc::OnNewDocument()
{
	if(!CDocument::OnNewDocument())
	{
		return FALSE;
	}

	SetupDefaultFilename ();

	UpdateGridInformation();

	//	Be very careful when speccing flags for UpdateAllViews()
	//	The wrong flags at the wrong time will totally screw things up
	UpdateAllViews( UAV_ALL3DVIEWS, NULL );
	return TRUE;
}


geBoolean CGenEditDoc::Save(const char *FileName)
{
	{
		// update view information in level
		ViewStateInfo *pViewStateInfo;
		POSITION		pos;
		CGenEditView	*	pView;
		int iView;

		pos = GetFirstViewPosition();
		while( pos != NULL )
		{
			pView = (CGenEditView*)GetNextView(pos) ;
			switch (Render_GetViewType (pView->VCam))
			{
				case VIEWSOLID :
				case VIEWTEXTURE :
				case VIEWWIRE :
					iView = 0;
					break;
				case VIEWTOP :
					iView = 1;
					break;
				case VIEWFRONT :
					iView = 2;
					break;
				case VIEWSIDE :
					iView = 3;
					break;
				default :
					iView = -1;
			}
			if (iView != -1)
			{
				pViewStateInfo = Level_GetViewStateInfo (pLevel, iView);
				pViewStateInfo->IsValid = GE_TRUE;
				pViewStateInfo->ZoomFactor = Render_GetZoom (pView->VCam);
				Render_GetPitchRollYaw (pView->VCam, &pViewStateInfo->PitchRollYaw);
				Render_GetCameraPos (pView->VCam, &pViewStateInfo->CameraPos);
			}
		}
	}

	// and then write the level info to the file
	return Level_WriteToFile (pLevel, FileName);
}

static geBoolean fdocSetEntityVisibility (CEntity &Ent, void *lParam)
{
	EntityViewEntry *pEntry = (EntityViewEntry *)lParam;

	if (Ent.GetClassname () == pEntry->pName)
	{
		Ent.SetVisible (pEntry->IsVisible);
	}
	return GE_TRUE;
}

/*
	Load file versions later than 1.0
*/
geBoolean CGenEditDoc::Load(const char *FileName)
{
	const char		*Errmsg, *WadPath;
	int				i;
	Level			*NewLevel;
	EntityViewList	*pEntityView;
	const Prefs *pPrefs = GetPrefs ();

	{
		char WorkingDir[MAX_PATH];

		FilePath_GetDriveAndDir (FileName, WorkingDir);
		::SetCurrentDirectory (WorkingDir);
	}

	NewLevel = Level_CreateFromFile (FileName, &Errmsg, Prefs_GetHeadersList (pPrefs));
	if (NewLevel == NULL)
	{
		goto LoadError;

⌨️ 快捷键说明

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