www.pudn.com > 3dsMFCRender.rar > TriList.cpp, change:1998-05-23,size:3851b


////////////////////////////////////////////////////////////////////// 
// 
//	TriList.cpp: implementation of the TriList class. 
//	TriList class version 1.5 
//	(C) 1998 - Sivert L. Nielsen (sivni@qeocities.com) 
//	This code may be freely distributed and used in programs so long 
//	as this notice appears in the code. 
// 
//	One world, one mind. 
//	 
// 
////////////////////////////////////////////////////////////////////// 
 
 
#include "stdafx.h" 
#include "3ds.h" 
#include "TriObject.h" 
#include "TriList.h" 
 
#ifdef _DEBUG 
#undef THIS_FILE 
static char THIS_FILE[]=__FILE__; 
#define new DEBUG_NEW 
#endif 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
TriList::TriList() 
{ 
	free = 0; 
	numobjects = 0; 
	maxobjects = 100; 
	animstart = 0; 
	animend = 0; 
	currentframe = 0; 
} 
 
TriList::~TriList() 
{ 
	for (int i=0; i <numobjects; i++) 
	{ 
		delete objects[i]; 
	} 
} 
 
BOOL TriList::add(TriObject * _object) 
{ 
	if (numobjects = maxobjects) 
	{ 
		objects[free] = _object; 
		free ++; 
		numobjects++; 
		return TRUE; 
	} 
	else return FALSE; 
} 
 
void TriList::drawGL() 
{ 
	for (int i=0; i <numobjects; i++) 
	{ 
		objects[i]->drawGL(); 
	}	 
} 
 
void TriList::drawGLBbox() 
{ 
	for (int i=0; i <numobjects; i++) 
	{ 
		objects[i]->drawGLBbox(); 
	}	 
} 
 
void TriList::Init() 
{ 
	free = 0; 
	numobjects = 0; 
	maxobjects = 100; 
} 
 
void TriList::doAfterMath() 
{ 
	for (int i=0; i <numobjects; i++) 
	{ 
		objects[i]->applyNormals(); 
		objects[i]->applyBbox(); 
		objects[i]->applyOffset(); 
		objects[i]->compileDisplayList(); 
		objects[i]->buildSplineAnimation(); 
	} 
} 
 
void TriList::removeAllObjects() 
{ 
	for (int i=0; i <numobjects; i++) 
	{ 
		delete objects[i]; 
	} 
	numobjects = 0; 
	free = 0; 
} 
 
TriObject* TriList::getObjectByName(char * name) 
{ 
	char* objname; 
	for (int i=0; i <numobjects; i++) 
	{ 
		objects[i]->getName(objname); 
		if(strcmp(name, objname) == 0) return objects[i]; 
	} 
	 
	return NULL; 
} 
 
long TriList::advanceFrame(int step, int direction, long frame) 
{ 
	// 
	//check if we want to go to the start or the end 
	// 
	if( (frame == -2) || (frame == -3)) 
	{ 
		for (int i=0; i <numobjects; i++) 
		{ 
			currentframe = objects[i]->advanceFrame(step, direction, frame); 
		} 
		return currentframe; 
	} 
 
	// 
	//go to the end if we are moving backwards and we are at the last frame 
	// 
	if( (currentframe = animstart) && (direction == -1)) 
	{ 
		for (int i=0; i <numobjects; i++) 
		{ 
			currentframe = objects[i]->advanceFrame(step, direction, -3); 
		} 
	} 
	 
	// 
	//go to the start if we are moving forward and we are at the last frame 
	// 
	else if( (currentframe >= animend) && (direction ==  1))  
	{ 
		for (int i=0; i <numobjects; i++) 
		{ 
			currentframe = objects[i]->advanceFrame(step, direction, -2); 
		} 
	} 
 
	// 
	//normal advance. Forward or backwards ... I don't care. 
	// 
	else 
	{ 
		for (int i=0; i <numobjects; i++) 
		{ 
			currentframe = objects[i]->advanceFrame(step, direction, frame); 
		} 
	} 
	 
	return currentframe; 
} 
 
void TriList::setAnim(long start, long end) 
{ 
	for (int i=0; i <numobjects; i++) 
	{ 
		objects[i]->setAnim(start,end); 
	} 
	animstart = start; 
	animend   = end; 
	currentframe = start; 
} 
 
void TriList::compileDisplayList() 
{ 
	for (int i=0; i <numobjects; i++) 
	{ 
		objects[i]->compileDisplayList(); 
	} 
} 
 
void TriList::drawGLDispList() 
{ 
	for (int i=0; i <numobjects; i++) 
	{ 
		objects[i]->drawGLDispList(); 
	} 
} 
 
void TriList::buildSplineAnimation() 
{ 
	for (int i=0; i <numobjects; i++) 
	{ 
		objects[i]->buildSplineAnimation(); 
	} 
} 
 
void TriList::getAnimRange(long & start, long & end) 
{ 
	start = animstart; 
	end = animend; 
}