コード例 #1
0
ファイル: robotarm.cpp プロジェクト: billytotochan/anime
// We are going to override (is that the right word?) the draw()
// method of ModelerView to draw out RobotArm
void RobotArm::draw()
{
	/* pick up the slider values */

	float theta = VAL( BASE_ROTATION );
	float phi = VAL( LOWER_TILT );
	float psi = VAL( UPPER_TILT );
	float cr = VAL( CLAW_ROTATION );
	float h1 = VAL( BASE_LENGTH );
	float h2 = VAL( LOWER_LENGTH );
	float h3 = VAL( UPPER_LENGTH );
	float pc = VAL( PARTICLE_COUNT );


    // This call takes care of a lot of the nasty projection 
    // matrix stuff
	ModelerView::draw();
	static GLfloat lmodel_ambient[] = { 0.4, 0.4, 0.4, 1.0 };
	Mat4f temp = getModelViewMatrix();

	// define the model

	ground(-0.2);
	
	if (true) {
		Ariou();
	} else {
		base(0.8);

	    glTranslatef( 0.0, 0.8, 0.0 );			// move to the top of the base
	    glRotatef( theta, 0.0, 1.0, 0.0 );		// turn the whole assembly around the y-axis. 
		rotation_base(h1);						// draw the rotation base

	    glTranslatef( 0.0, h1, 0.0 );			// move to the top of the base
	    glRotatef( phi, 0.0, 0.0, 1.0 );		// rotate around the z-axis for the lower arm
		glTranslatef( -0.1, 0.0, 0.4 );
		lower_arm(h2);							// draw the lower arm

	    glTranslatef( 0.0, h2, 0.0 );			// move to the top of the lower arm
	    glRotatef( psi, 0.0, 0.0, 1.0 );		// rotate  around z-axis for the upper arm
		upper_arm(h3);							// draw the upper arm

		glTranslatef( 0.0, h3, 0.0 );
		glRotatef(cr, 0.0, 0.0, 1.0);
		claw(1.0);
		SpawnParticles(temp);
	}

	//*** DON'T FORGET TO PUT THIS IN YOUR OWN CODE **/
	endDraw();
}
コード例 #2
0
/**
 *	Spawn particles for this instance
 *
 *	@param	OldLeftover		The leftover time from the last spawn
 *	@param	Rate			The rate at which particles should be spawned
 *	@param	DeltaTime		The time slice to spawn over
 *	@param	Burst			The number of burst particle
 *	@param	BurstTime		The burst time addition (faked time slice)
 *
 *	@return	float			The leftover fraction of spawning
 */
float FParticleBeam2EmitterInstance::SpawnBeamParticles(float OldLeftover, float Rate, float DeltaTime, int32 Burst, float BurstTime)
{
	SCOPE_CYCLE_COUNTER(STAT_BeamSpawnTime);

	float SafetyLeftover = OldLeftover;
	float	NewLeftover = OldLeftover + DeltaTime * Rate;

	// Ensure continous spawning... lots of fiddling.
	int32		Number		= FMath::FloorToInt(NewLeftover);
	float	Increment	= 1.f / Rate;
	float	StartTime	= DeltaTime + OldLeftover * Increment - Increment;
	NewLeftover			= NewLeftover - Number;

	// Always match the burst at a minimum
	if (Number < Burst)
	{
		Number = Burst;
	}

	// Account for burst time simulation
	if (BurstTime > KINDA_SMALL_NUMBER)
	{
		NewLeftover -= BurstTime / Burst;
		NewLeftover	= FMath::Clamp<float>(NewLeftover, 0, NewLeftover);
	}

	// Force a beam
	bool bNoLivingParticles = false;
	if (ActiveParticles == 0)
	{
		bNoLivingParticles = true;
		if (Number == 0)
			Number = 1;
	}

	// Don't allow more than BeamCount beams...
	if (Number + ActiveParticles > BeamCount)
	{
		Number	= BeamCount - ActiveParticles;
	}

	// Handle growing arrays.
	bool bProcessSpawn = true;
	int32 NewCount = ActiveParticles + Number;
	if (NewCount >= MaxActiveParticles)
	{
		if (DeltaTime < 0.25f)
		{
			bProcessSpawn = Resize(NewCount + FMath::TruncToInt(FMath::Sqrt((float)NewCount)) + 1);
		}
		else
		{
			bProcessSpawn = Resize((NewCount + FMath::TruncToInt(FMath::Sqrt((float)NewCount)) + 1), false);
		}
	}

	if (bProcessSpawn == true)
	{
		UParticleLODLevel* LODLevel = SpriteTemplate->GetCurrentLODLevel(this);
		check(LODLevel);

		// Spawn particles.
		SpawnParticles( Number, StartTime, Increment, Location, FVector::ZeroVector, NULL );

		if (ForceSpawnCount > 0)
		{
			ForceSpawnCount = 0;
		}

		INC_DWORD_STAT_BY(STAT_BeamParticles, ActiveParticles);

		return NewLeftover;
	}

	INC_DWORD_STAT_BY(STAT_BeamParticles, ActiveParticles);

	return SafetyLeftover;
}
コード例 #3
0
ファイル: robotarm.cpp プロジェクト: billytotochan/anime
void Ariou() {
	Mat4f temp = getModelViewMatrix();
	ModelerApplication::Instance()->Swing(LEFT_UPPER_ARM_ROTATE_X, 3.1);
	//ModelerApplication::Instance()->Swing(LEFT_UPPER_ARM_ROTATE_Y, 2.5);

	ModelerApplication::Instance()->Swing(HEAD_ROTATE, 1);

	ModelerApplication::Instance()->Swing(RIGHT_UPPER_ARM_ROTATE_X, 1.1);
	ModelerApplication::Instance()->Swing(RIGHT_UPPER_ARM_ROTATE_Y, 4.5);

	ModelerApplication::Instance()->Swing(LEFT_LEG_ROTATE_X, 6.1);
	ModelerApplication::Instance()->Swing(RIGHT_LEG_ROTATE_X, 6.1);
	glPushMatrix();
		glTranslated(VAL(XPOS), VAL(YPOS), VAL(ZPOS));
		glScaled(VAL(XSCALE), VAL(YSCALE), VAL(ZSCALE));
		glRotated(VAL(ROTATE), 0, 1, 0);
		setDiffuseColor(COLOR_YELLOW);

		// Torus
		if (VAL(DETAIL_LEVEL) > 1) {
			glPushMatrix();
				glTranslated(.0f, 6, .0f);
				drawTorus(VAL(TORUS_R), VAL(TORUS_r));
			glPopMatrix();
		}
		
		//head
		glPushMatrix();
			glTranslated(0, VAL(LEG_LENGTH) + 0.05 + VAL(HEIGHT) + 0.05 + VAL(HEAD_SIZE), 0);
			glRotated(VAL(HEAD_ROTATE), 0.0, 1.0, 0.0);
			drawSphere(VAL(HEAD_SIZE));
			if (VAL(DETAIL_LEVEL) > 2) {

				// Nose
				drawRoundCylinder(VAL(HEAD_SIZE) * 1.1, 0.2, 0.2);

				// Ear
				glPushMatrix();
				glTranslated(0.9 / sqrt(0.9*0.9 + 1.1*1.1) * VAL(HEAD_SIZE), 1.1 / sqrt(0.9*0.9 + 1.1*1.1) * VAL(HEAD_SIZE), 0);
				glRotated(-20, 0, 0, 1);
				SpawnParticles(temp);
				drawPyramid(VAL(EAR_SIZE));
				glPopMatrix();

				glPushMatrix();
				glTranslated(-0.9 / sqrt(0.9*0.9 + 1.1*1.1) * VAL(HEAD_SIZE), 1.1 / sqrt(0.9*0.9 + 1.1*1.1) * VAL(HEAD_SIZE), 0);
				glRotated(20, 0, 0, 1);
				SpawnParticles(temp);
				drawPyramid(VAL(EAR_SIZE));
				glPopMatrix();
				
				// Eyes
				glPushMatrix();
				setDiffuseColor(COLOR_RED);
				glTranslated(-0.5 / sqrt(0.5*0.5 * 2) * VAL(HEAD_SIZE) * 0.5, 0.5 / sqrt(0.5*0.5 * 2) * VAL(HEAD_SIZE) * 0.5, VAL(HEAD_SIZE) - 0.9);
					drawRoundCylinder( 0.9, 0.2, 0.2);
				glPopMatrix();
				glPushMatrix();
				setDiffuseColor(COLOR_RED);
				glTranslated( 0.5 / sqrt(0.5*0.5 * 2) * VAL(HEAD_SIZE) * 0.5, 0.5 / sqrt(0.5*0.5 * 2) * VAL(HEAD_SIZE) * 0.5, VAL(HEAD_SIZE) - 0.9);
					drawRoundCylinder( 0.9, 0.2, 0.2);
				glPopMatrix();
			}
		glPopMatrix();

		if (VAL(DETAIL_LEVEL) > 1) {
			//body
			// a.k.a. torso/trunk
			glPushMatrix();
			setDiffuseColor(COLOR_YELLOW);
			glTranslated(0, 0.05 + VAL(LEG_LENGTH), 0);
			glRotated(-90, 1.0, 0.0, 0.0);
			drawRoundCylinder(VAL(HEIGHT), 0.7, 0.6);
			glPushMatrix();
			glTranslated(-0.8, 0, VAL(HEIGHT) - 0.4);
			glRotated(90, 0, 1, 0);
			// the shoulder
			if (VAL(DETAIL_LEVEL) > 2) {
				drawRoundCylinder(1.6, 0.2, 0.2);
			}
			glPopMatrix();

			// the waist
			if (VAL(DETAIL_LEVEL) > 3) {
				glPushMatrix();
				glTranslated(0, 0, 0.5);
				glRotated(90, 1, 0, 0);
				drawTorus(0.7, 0.08);
				glPopMatrix();
			}

			glPopMatrix();

			if (VAL(DETAIL_LEVEL) > 2) {
				//right arm
				glPushMatrix();
				glTranslated(-0.7 - 0.20, VAL(LEG_LENGTH) + 0.05 + VAL(HEIGHT) * 0.9f, 0);
				glTranslated(0.15, 0, 0);
				glRotated(VAL(RIGHT_UPPER_ARM_ROTATE_X), 1.0, 0.0, 0.0);
				glRotated(VAL(RIGHT_UPPER_ARM_ROTATE_Y), 0.0, 1.0, 0.0);
				glTranslated(-0.15, 0, 0);
				drawRoundCylinder(VAL(UPPER_ARM_LENGTH), 0.22, 0.15);

				// lower arm
				glTranslated(0, 0, VAL(UPPER_ARM_LENGTH) - 0.1);
				glRotated(VAL(RIGHT_LOWER_ARM_ROTATE) - 180, 1, 0, 0);
				drawRoundCylinder(VAL(LOWER_ARM_LENGTH), 0.15, 0.20);

				// hand
				glPushMatrix();
				glTranslated(-0.03, -0.15, VAL(LOWER_ARM_LENGTH) - 0.1);
				glRotated(VAL(RIGHT_HAND_ANGLE), 0, 1, 0);
				drawCylinder(0.8, 0.15, 0.0001);
				glPopMatrix();

				glPushMatrix();
				glTranslated(0.03, -0.15, VAL(LOWER_ARM_LENGTH) - 0.1);
				glRotated(-VAL(RIGHT_HAND_ANGLE), 0, 1, 0);
				drawCylinder(0.8, 0.15, 0.0001);
				glPopMatrix();

				glPopMatrix();

				//left arm
				glPushMatrix();
				glTranslated(0.7 + 0.20, VAL(LEG_LENGTH) + 0.05 + VAL(HEIGHT) * 0.9f, 0);
				glTranslated(-0.15, 0, 0);
				glRotated(VAL(LEFT_UPPER_ARM_ROTATE_X), 1.0, 0.0, 0.0);
				glRotated(VAL(LEFT_UPPER_ARM_ROTATE_Y), 0.0, 1.0, 0.0);
				glTranslated(0.15, 0, 0);
				drawRoundCylinder(VAL(UPPER_ARM_LENGTH), 0.22, 0.15);

				glTranslated(0, 0, VAL(UPPER_ARM_LENGTH) - 0.1);
				glRotated(VAL(LEFT_LOWER_ARM_ROTATE) - 180, 1, 0, 0);
				drawRoundCylinder(VAL(LOWER_ARM_LENGTH), 0.15, 0.20);

				// hand
				glPushMatrix();
				glTranslated(-0.03, 0, VAL(LOWER_ARM_LENGTH) - 0.1);
				glRotated(VAL(LEFT_HAND_ANGLE), 0, 1, 0);
				drawBox(0.03, 0.25, 0.5);
				glPopMatrix();

				glPushMatrix();
				glTranslated(0.03, 0, VAL(LOWER_ARM_LENGTH) - 0.1);
				glRotated(-VAL(LEFT_HAND_ANGLE), 0, 1, 0);
				drawBox(0.03, 0.25, 0.5);
				if (VAL(DETAIL_LEVEL) > 3) {
					glRotated(90, 0, 0, 1);
					drawCylinder(5, 0.02, 0.02);
					if (VAL(DETAIL_LEVEL) > 4) {
						glTranslated(0, 0, 4);

						glPushMatrix();
						setDiffuseColor(COLOR_GREEN);
						glTranslated(0, -0.5, 1);
						//SpawnParticles(temp);
						glPushMatrix();
						glRotated(90, 1.0, 0.0, 0.0);
						glPopMatrix();
						glPopMatrix();
					}
				}
				glPopMatrix();

				glPopMatrix();
			}

			//right leg
			glPushMatrix();
			setDiffuseColor(COLOR_YELLOW);
			glTranslated(-0.5, VAL(LEG_LENGTH), 0);
			glRotated(VAL(RIGHT_LEG_ROTATE_X), 1.0, 0.0, 0.0);
			glRotated(VAL(RIGHT_LEG_ROTATE_Y), 0.0, 1.0, 0.0);
			drawRoundCylinder(VAL(LEG_LENGTH) - 0.15, 0.3, 0.4);
			glTranslated(0, 0, VAL(LEG_LENGTH) * 0.85f);
			glRotated(70, 1, 0, 0);
			drawTorus(VAL(FEET_SIZE), VAL(FEET_SIZE) / 4);

			glPopMatrix();

			//left leg
			glPushMatrix();
			glTranslated(0.5, VAL(LEG_LENGTH), 0);
			glRotated(VAL(LEFT_LEG_ROTATE_X), 1.0, 0.0, 0.0);
			glRotated(VAL(LEFT_LEG_ROTATE_Y), 0.0, 1.0, 0.0);
			drawRoundCylinder(VAL(LEG_LENGTH) - 0.15, 0.3, 0.4);
			glTranslated(0, 0, VAL(LEG_LENGTH) * 0.85f);
			glRotated(70, 1, 0, 0);
			drawTorus(VAL(FEET_SIZE), VAL(FEET_SIZE) / 4);

			glPopMatrix();
		}
	glPopMatrix();
}