コード例 #1
0
void Window2_Render(Win32Window* window, float alpha, float elapsedtime)
{
	static float time = 0;
	float world[16];

	time += elapsedtime;

	DrawingItem* drawingitem = window->GetDrawingItem();
	DrawingLayer& bottomlayer = drawingitem->GetBottomLayer();
	{
		NativeContext context = bottomlayer.GetContext();

		GLMatrixRotationAxis(world, -fmodf(time * 20.0f, 360.0f) * (3.14152f / 180.0f), 0, 0, 1);

		context.Clear(OpenGLColor(0.0f, 0.125f, 0.3f, 1.0f));
		context.SetWorldTransform(world);
		context.SetColor(OpenGLColor(1, 1, 1, 1));

		context.MoveTo(-120, 120);
		context.LineTo(120, 120);
		context.LineTo(120, -120);
		context.LineTo(-120, -120);
		context.LineTo(-120, 120);
	}

	drawingitem->RecomposeLayers();
}
コード例 #2
0
void Window1_Render(Win32Window* window, float alpha, float elapsedtime)
{
    static float time = 0;
    float world[16];

    time += elapsedtime;

    DrawingItem* drawingitem = window->GetDrawingItem();
    DrawingLayer& bottomlayer = drawingitem->GetBottomLayer();
    {
        NativeContext	context		= bottomlayer.GetContext();
        float			bigradius	= 150;
        float			smallradius	= 80;
        float			m2pi		= 6.293185f;
        int				segments	= 16;

        GLMatrixRotationAxis(world, fmodf(time * 20.0f, 360.0f) * (3.14152f / 180.0f), 0, 0, 1);

        context.Clear(OpenGLColor(0.0f, 0.125f, 0.3f, 1.0f));
        context.SetWorldTransform(world);
        context.MoveTo(0, bigradius);

        for( int i = 1; i <= segments; ++i )
        {
            if( i % 2 == 1 )
            {
                context.LineTo(
                    sinf((m2pi / segments) * i) * smallradius,
                    cosf((m2pi / segments) * i) * smallradius);
            }
            else
            {
                context.LineTo(
                    sinf((m2pi / segments) * i) * bigradius,
                    cosf((m2pi / segments) * i) * bigradius);
            }
        }
    }

    DrawingLayer& feedbacklayer = drawingitem->GetFeedbackLayer();
    {
        NativeContext context = feedbacklayer.GetContext();

        GLMatrixRotationAxis(world, -fmodf(time * 20.0f, 360.0f) * (3.14152f / 180.0f), 0, 0, 1);

        context.Clear(OpenGLColor(0, 0, 0, 0));
        context.SetWorldTransform(world);
        context.SetColor(OpenGLColor(0, 1, 0, 1));

        context.MoveTo(-120, 120);
        context.LineTo(120, 120);
        context.LineTo(120, -120);
        context.LineTo(-120, -120);
        context.LineTo(-120, 120);
    }

    drawingitem->RecomposeLayers();
}
コード例 #3
0
void THREAD_Run()
{
	float world[16];
	float time = 0;

	while( true )
	{
		if( !glwindow )
			continue;

		DrawingItem* drawingitem = glwindow->GetDrawingItem();
		DrawingLayer& feedbacklayer = drawingitem->GetFeedbackLayer();
		{
			NativeContext	context		= feedbacklayer.GetContext();
			float			bigradius	= 150;
			float			smallradius	= 80;
			float			m2pi		= 6.293185f;
			int				segments	= 16;

			GLMatrixRotationAxis(world, fmodf(time * 20.0f, 360.0f) * (3.14152f / 180.0f), 0, 0, 1);

			context.Clear(OpenGLColor(0, 0, 0, 0));
			context.SetWorldTransform(world);
			context.SetColor(OpenGLColor(0, 1, 0, 1));
			context.MoveTo(0, bigradius);

			for( int i = 1; i <= segments; ++i )
			{
				if( i % 2 == 1 )
				{
					context.LineTo(
						sinf((m2pi / segments) * i) * smallradius,
						cosf((m2pi / segments) * i) * smallradius);
				}
				else
				{
					context.LineTo(
						sinf((m2pi / segments) * i) * bigradius,
						cosf((m2pi / segments) * i) * bigradius);
				}
			}
		}

		time += 0.5f;
		Sleep(500); // 34
	}
}
コード例 #4
0
ファイル: main.cpp プロジェクト: asylum2010/Asylum_Tutorials
OpenGLAABox			scenebox;

GLuint				white;
GLuint				headbuffer		= 0;
GLuint				nodebuffer		= 0;
GLuint				counterbuffer	= 0;

short				mousedx			= 0;
short				mousedy			= 0;
short				mousedown		= 0;

array_state<float, 2> cameraangle;

SceneObject objects[] =
{
	{ 0, { 0, -0.35f, 0 }, { 15, 0.5f, 15 }, 0, OpenGLColor(1, 1, 0, 0.75f) },

	{ 1, { -1, -0.1f, 2.5f }, { 0.3f, 0.3f, 0.3f }, -M_PI / 8, OpenGLColor(1, 0, 1, 0.5f) },
	{ 1, { 2.5f, -0.1f, 0 }, { 0.3f, 0.3f, 0.3f }, M_PI / -2 + M_PI / -6, OpenGLColor(0, 1, 1, 0.5f) },
	{ 1, { -2, -0.1f, -2 }, { 0.3f, 0.3f, 0.3f }, M_PI / -4, OpenGLColor(1, 0, 0, 0.5f) },

	{ 2, { 0, -1.15f, 0 }, { 20, 20, 20 }, M_PI, OpenGLColor(0, 1, 0, 0.5f) },
};

const int numobjects = sizeof(objects) / sizeof(SceneObject);

static void APIENTRY ReportGLError(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userdata)
{
	if( type >= GL_DEBUG_TYPE_ERROR && type <= GL_DEBUG_TYPE_PERFORMANCE )
	{
		if( source == GL_DEBUG_SOURCE_API )
コード例 #5
0
//const char* TOWER_BASE_POWER = "../Towers/Power/TowerPowerBase";
//const char* TOWER_BASE_SPEED = "../Towers/Speed/TowerSpeedBase";
//const char* TOWER_BASE_UTILITY = "../Towers/Utility/TowerUtilityBase";
//
//const char* TOWER_UPGRADE_1_POWER = "../Towers/Power/Upgrade1Power";
//const char* TOWER_UPGRADE_2_POWER = "../Towers/Power/Upgrade2Power";
//const char* TOWER_UPGRADE_3_POWER = "../Towers/Power/Upgrade3Power";
//
//const char* TOWER_UPGRADE_1_SPEED = "../Towers/Speed/Upgrade1Speed";
//const char* TOWER_UPGRADE_2_SPEED = "../Towers/Speed/Upgrade2Speed";
//const char* TOWER_UPGRADE_3_SPEED = "../Towers/Speed/Upgrade3Speed";
//
//const char* TOWER_UPGRADE_1_UTILITY = "../Towers/Utility/Upgrade1Utility";
//const char* TOWER_UPGRADE_2_UTILITY = "../Towers/Utility/Upgrade2Utility";
//const char* TOWER_UPGRADE_3_UTILITY = "../Towers/Utility/Upgrade3Utility";

//Player Constants
const int PLAYER_SIZE = 24;
const float PLAYER_SPEED = 250.0f;
const OpenGLColor PLAYER_INSIDE_COLOR = OpenGLColor(0.0f, 0.0f, 0.0f, 1.0f);
const OpenGLColor PLAYER_OUTLINE_COLOR = OpenGLColor(1.0f, 1.0f, 1.0f, 1.0f);

//Player Constants
const char* HERO_TYPE = "Hero";

//EnemyConstants
const char* ENEMY_TYPE = "Enemy";
const int ENEMY_COUNT = 10;

//Pickup Constants
const char* AMMO_PICKUP_TYPE = "AmmoPickup";
コード例 #6
0
ファイル: main.cpp プロジェクト: asylum2010/Asylum_Tutorials
void UpdateParticles(float dt, bool generate)
{
	// NOTE: runs on 10 fps

	OpenGLAABox tmpbox = scenebox;
	float center[3];

	if( lightbuffer == 0 )
		return;

	glBindBuffer(GL_SHADER_STORAGE_BUFFER, lightbuffer);
	LightParticle* particles = (LightParticle*)glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_READ_WRITE);

	tmpbox.GetCenter(center);

	if( generate )
	{
		int segments = GLISqrt(NUM_LIGHTS);
		float theta, phi;

		OpenGLColor randomcolors[3] =
		{
			OpenGLColor(1, 0, 0, 1),
			OpenGLColor(0, 1, 0, 1),
			OpenGLColor(0, 0, 1, 1)
		};

		for( int i = 0; i < segments; ++i )
		{
			for( int j = 0; j < segments; ++j )
			{
				LightParticle& p = particles[i * segments + j];

				theta = ((float)j / (segments - 1)) * M_PI;
				phi = ((float)i / (segments - 1)) * M_2PI;

				p.previous[0] = center[0];
				p.previous[1] = center[1];
				p.previous[2] = center[2];
				p.previous[3] = 1;

				p.velocity[0] = sinf(theta) * cosf(phi) * 2;
				p.velocity[1] = cosf(theta) * 2;
				p.velocity[2] = sinf(theta) * sinf(phi) * 2;

				p.current[0] = p.previous[0];
				p.current[1] = p.previous[1];
				p.current[2] = p.previous[2];
				p.current[3] = 1;

				p.radius = LIGHT_RADIUS;
				p.color = randomcolors[(i + j) % 3];
			}
		}
	}
	else
	{
		float vx[3], vy[3], vz[3];
		float b[3];
		float A[16], Ainv[16];
		float planes[6][4];
		float denom, energy;
		float toi, besttoi;
		float impulse, noise;
		float (*bestplane)[4];
		bool pastcollision;

		tmpbox.GetPlanes(planes);

		for( int i = 0; i < NUM_LIGHTS; ++i )
		{
			LightParticle& p = particles[i];

			// integrate
			p.previous[0] = p.current[0];
			p.previous[1] = p.current[1];
			p.previous[2] = p.current[2];

			p.current[0] += p.velocity[0] * dt;
			p.current[1] += p.velocity[1] * dt;
			p.current[2] += p.velocity[2] * dt;

			// detect collision
			besttoi = 2;

			b[0] = p.current[0] - p.previous[0];
			b[1] = p.current[1] - p.previous[1];
			b[2] = p.current[2] - p.previous[2];

			for( int j = 0; j < 6; ++j )
			{
				// use radius == 0.5
				denom = GLVec3Dot(b, planes[j]);
				pastcollision = (GLVec3Dot(p.previous, planes[j]) + planes[j][3] < 0.5f);

				if( denom < -1e-4f )
				{
					toi = (0.5f - GLVec3Dot(p.previous, planes[j]) - planes[j][3]) / denom;

					if( ((toi <= 1 && toi >= 0) ||		// normal case
						(toi < 0 && pastcollision)) &&	// allow past collision
						toi < besttoi )
					{
						besttoi = toi;
						bestplane = &planes[j];
					}
				}
			}

			if( besttoi <= 1 )
			{
				// resolve constraint
				p.current[0] = (1 - besttoi) * p.previous[0] + besttoi * p.current[0];
				p.current[1] = (1 - besttoi) * p.previous[1] + besttoi * p.current[1];
				p.current[2] = (1 - besttoi) * p.previous[2] + besttoi * p.current[2];

				impulse = -GLVec3Dot(*bestplane, p.velocity);

				// perturb normal vector
				noise = ((rand() % 100) / 100.0f) * M_PI * 0.333333f - M_PI * 0.166666f; // [-pi/6, pi/6]

				b[0] = cosf(noise + M_PI * 0.5f);
				b[1] = cosf(noise);
				b[2] = 0;

				GLVec3Normalize(vy, (*bestplane));
				GLGetOrthogonalVectors(vx, vz, vy);

				A[0] = vx[0];	A[1] = vy[0];	A[2] = vz[0];	A[3] = 0;
				A[4] = vx[1];	A[5] = vy[1];	A[6] = vz[1];	A[7] = 0;
				A[8] = vx[2];	A[9] = vy[2];	A[10] = vz[2];	A[11] = 0;
				A[12] = 0;		A[13] = 0;		A[14] = 0;		A[15] = 1;

				GLMatrixInverse(Ainv, A);
				GLVec3Transform(vy, b, Ainv);

				energy = GLVec3Length(p.velocity);

				p.velocity[0] += 2 * impulse * vy[0];
				p.velocity[1] += 2 * impulse * vy[1];
				p.velocity[2] += 2 * impulse * vy[2];

				// must conserve energy
				GLVec3Normalize(p.velocity, p.velocity);

				p.velocity[0] *= energy;
				p.velocity[1] *= energy;
				p.velocity[2] *= energy;
			}

#ifdef _DEBUG
			// test if a light fell through
			tmpbox.GetCenter(center);

			if( GLVec3Distance(p.current, center) > tmpbox.Radius() )
				::_CrtDbgBreak();
#endif
		}
	}

	glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
	glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
}