コード例 #1
0
ファイル: Scene Lighting.cpp プロジェクト: Sand3r-/gltut
//Called to update the display.
//You should call glutSwapBuffers after all of your rendering to display what you rendered.
//If you need continuous updates of the screen, call glutPostRedisplay() at the end of the function.
void display()
{
	g_lights.UpdateTime();

	glm::vec4 bkg = g_lights.GetBackgroundColor();

	glClearColor(bkg[0], bkg[1], bkg[2], bkg[3]);
	glClearDepth(1.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glutil::MatrixStack modelMatrix;
	modelMatrix.SetMatrix(g_viewPole.CalcMatrix());

	const glm::mat4 &worldToCamMat = modelMatrix.Top();
	LightBlock lightData = g_lights.GetLightInformation(worldToCamMat);

	glBindBuffer(GL_UNIFORM_BUFFER, g_lightUniformBuffer);
	glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(lightData), &lightData);
	glBindBuffer(GL_UNIFORM_BUFFER, 0);

	if(g_pScene)
	{
		glutil::PushStack push(modelMatrix);

		g_pScene->Draw(modelMatrix, g_materialBlockIndex, g_lights.GetTimerValue("tetra"));
	}

	{
		glutil::PushStack push(modelMatrix);
		//Render the sun
		{
			glutil::PushStack push(modelMatrix);

			glm::vec3 sunlightDir(g_lights.GetSunlightDirection());
			modelMatrix.Translate(sunlightDir * 500.0f);
			modelMatrix.Scale(30.0f, 30.0f, 30.0f);

			glUseProgram(g_Unlit.theProgram);
			glUniformMatrix4fv(g_Unlit.modelToCameraMatrixUnif, 1, GL_FALSE,
				glm::value_ptr(modelMatrix.Top()));

			glm::vec4 lightColor = g_lights.GetSunlightIntensity();
			glUniform4fv(g_Unlit.objectColorUnif, 1, glm::value_ptr(lightColor));
			g_pScene->GetSphereMesh()->Render("flat");
		}

		//Render the lights
		if(g_bDrawLights)
		{
			for(int light = 0; light < g_lights.GetNumberOfPointLights(); light++)
			{
				glutil::PushStack push(modelMatrix);

				modelMatrix.Translate(g_lights.GetWorldLightPosition(light));

				glUseProgram(g_Unlit.theProgram);
				glUniformMatrix4fv(g_Unlit.modelToCameraMatrixUnif, 1, GL_FALSE,
					glm::value_ptr(modelMatrix.Top()));

				glm::vec4 lightColor = g_lights.GetPointLightIntensity(light);
				glUniform4fv(g_Unlit.objectColorUnif, 1, glm::value_ptr(lightColor));
				g_pScene->GetCubeMesh()->Render("flat");
			}
		}

		if(g_bDrawCameraPos)
		{
			glutil::PushStack push(modelMatrix);

			modelMatrix.SetIdentity();
			modelMatrix.Translate(glm::vec3(0.0f, 0.0f, -g_viewPole.GetView().radius));

			glDisable(GL_DEPTH_TEST);
			glDepthMask(GL_FALSE);
			glUseProgram(g_Unlit.theProgram);
			glUniformMatrix4fv(g_Unlit.modelToCameraMatrixUnif, 1, GL_FALSE,
				glm::value_ptr(modelMatrix.Top()));
			glUniform4f(g_Unlit.objectColorUnif, 0.25f, 0.25f, 0.25f, 1.0f);
			g_pScene->GetCubeMesh()->Render("flat");
			glDepthMask(GL_TRUE);
			glEnable(GL_DEPTH_TEST);
			glUniform4f(g_Unlit.objectColorUnif, 1.0f, 1.0f, 1.0f, 1.0f);
			g_pScene->GetCubeMesh()->Render("flat");
		}
	}

	glutPostRedisplay();
	glutSwapBuffers();
}
コード例 #2
0
 void
 modify(const_reference r_old, const_reference r_new)
 {
   erase(r_old);
   push(r_new);
 }
コード例 #3
0
ファイル: Dijkstra.hpp プロジェクト: Plantain/XCSoar
/** 
 * Constructor
 * 
 * @param n Node to start
 * @param is_min Whether this algorithm will search for min or max distance
 */
  Dijkstra(const Node &n, const bool is_min=true):
    m_min(is_min) { 
    push(n, n, 0); 
  }
コード例 #4
0
ファイル: Dijkstra.hpp プロジェクト: galippi/xcsoar
  /**
   * Add an edge (node-node-distance) to the search
   *
   * @param n Destination node to add
   * @param pn Predecessor of destination node
   * @param e Edge distance
   */
  void link(const Node &node, const Node &parent, const unsigned &edge_value = 1) {
#ifdef INSTRUMENT_TASK
    count_dijkstra_links++;
#endif
    push(node, parent, cur->second + adjust_edge_value(edge_value)); 
  }
コード例 #5
0
ファイル: Dijkstra.hpp プロジェクト: galippi/xcsoar
 /**
  * Resets as if constructed afresh
  *
  * @param n Node to start
  */
 void restart(const Node &node) {
   clear();
   push(node, node, 0);
 }
コード例 #6
0
ファイル: counter.hpp プロジェクト: flixster/mesos
 // 'name' is the unique name for the instance of Counter being constructed.
 // This is what will be used as the key in the JSON endpoint.
 // 'window' is the amount of history to keep for this Metric.
 Counter(const std::string& name, const Option<Duration>& window = None())
   : Metric(name, window),
     data(new Data())
 {
   push(data->v);
 }
コード例 #7
0
ファイル: counter.hpp プロジェクト: flixster/mesos
 Counter& operator += (int64_t v)
 {
   push(__sync_add_and_fetch(&data->v, v));
   return *this;
 }
コード例 #8
0
ファイル: ex4-4.c プロジェクト: AskDrCatcher/kernighanC
/* reverse Polish calculator */
int main()
{
    int type;
    double op2;
    char s[MAXOP];

    while ((type = getop(s)) != EOF)
    {
        switch(type)
        {
            case NUMBER:
                push(atof(s));
                break;
            case NEGATIVE_NUMBER:
                push(-1 * atof(s));
                break;
            case '+':
                push(pop() + pop());
                break;
            case '*':
                push(pop() * pop());
                break;
            case '-':
                op2 = pop();
                push(pop() - op2);
                break;
            case '/':
                op2 = pop();
                if (op2 != 0.0)
                    push(pop() / op2);
                else
                    printf("error: zero divisor\n");
                break;
            case '%':
                op2 = pop();
                push((int)pop() % (int)op2);
                break;
            case '\n':
                //do nothing
                break;
            case POP:
                printf("\t%.8g\n", pop());
                break;
            case PEEK:
                printf("\t%.8g\n", peek());
                break;
            case DUPLICATE:
                dup();
                break;
            case SWAP:
                swap();
                break;
            case CLEAR:
                clear();
                break;
            default:
                printf("error: unknown command %s\n", s);
                break;  
        }
    }

    return 0; //return SUCCESS
}
コード例 #9
0
int mg_write(struct mg_connection *conn, const void *buf, size_t len) {
  return (int) push(NULL, conn->client.sock, (const char *) buf, (int64_t) len);
}
コード例 #10
0
int main(void)
{
	int *a = malloc(sizeof(int)), *b = malloc(sizeof(int)), *c = malloc(sizeof(int));
	Stack s = NULL;
    Elem* temp = NULL;
	*a = 12;
    *b = 15;
    *c = 4;

    s = create_stack((void*)a);
    temp = (Elem*) calloc(1, sizeof(Elem));

	printf("1 - create_stack\tLength: %d\n", length_of(s));
    print_list_of_int(s);

	if(!is_empty(s))
	{
		s  = push(s, (void*)b);
	    printf("\n2 - push\tLength: %d\n", length_of(s));
        print_list_of_int(s);
    }
	else
	{
		printf("Unable to allocate a new stack\n");
		return 0;
	}

    s = push(s, (void*)c);
	printf("\n3 - push\tLength: %d\n", length_of(s));
    print_list_of_int(s);

    temp = pop(&s);
    printf("\n4 - pop\tLength: %d\n", length_of(s));
    if(!is_empty(temp))
        printf("temp->data = %d\n", *(int*)temp->data);
    print_list_of_int(s);
    free(temp);
    temp = NULL;

    temp = pop(&s);
    printf("\n5 - pop\tLength: %d\n", length_of(s));
    if(!is_empty(temp));
        printf("temp->data = %d\n", *(int*)temp->data);
    print_list_of_int(s);
    free(temp);
    temp = NULL;

    temp = pop(&s);
    printf("\n6 - pop\tLength: %d\n", length_of(s));
    if(!is_empty(temp));
        printf("temp->data = %d\n", *(int*)temp->data);
    print_list_of_int(s);
    free(temp);
    temp = NULL;

	s  = push(s, (void*)b);
	printf("\n7 - push\tLength: %d\n", length_of(s));
    print_list_of_int(s);

    delete_stack(s);
	free(a);
    free(b);
    free(c);
	return 0;
}
コード例 #11
0
ファイル: ex4-4.c プロジェクト: AskDrCatcher/kernighanC
/* dup : duplicate top element and push it in the stack */
void dup(void)
{
    push(peek());
}
コード例 #12
0
ファイル: split.c プロジェクト: JamesLinus/LiteBSD-Ports
int
split_quoted (const char *s, int *argc, char *argv[], int argv_sz)
{
    char arg_buff[MAX_ARG_LEN]; /* current argument buffer */
    char *ap, *ae;              /* arg_buff current ptr & end-guard */
    const char *c;              /* current input charcter ptr */
    char qc;                    /* current quote character */
    enum states state;          /* current state */
    enum err_codes err;         /* error end-code */
    int flags;                  /* warning flags */

    ap = &arg_buff[0];
    ae = &arg_buff[MAX_ARG_LEN - 1];
    c = &s[0];
    state = ST_DELIM;
    err = ERR_OK;
    flags = 0;
    qc = SQ; /* silence compiler waring */

    while ( state != ST_END ) {
        switch (state) {
        case ST_DELIM:
            while ( is_delim(*c) ) c++;
            if ( *c == SQ || *c == DQ ) {
                qc = *c; c++; state = ST_QUOTE; 
                break;
            }
            if ( *c == EOS ) {
                state = ST_END;
                break;
            }
            if ( *c == BS ) {
                c++;
                if ( *c == NL ) {
                    c++;
                    break;
                }
                if ( *c == EOS ) {
                    state = ST_END; err = ERR_BS_AT_EOS;
                    break;
                }
            }
            /* All other cases incl. character after BS */
            save(); c++; state = ST_ARG;
            break;
        case ST_QUOTE:
            while ( *c != qc && ( *c != BS || qc == SQ ) && *c != EOS ) {
                save(); c++;
            }
            if ( *c == qc ) {
                c++; state = ST_ARG;
                break;
            }
            if ( *c == BS ) {
                assert (qc == DQ);
                c++;
                if ( *c == NL) {
                    c++;
                    break;
                }
                if (*c == EOS) {
                    state = ST_END; err = ERR_BS_AT_EOS;
                    break;
                }
                if ( ! is_dq_escapable(*c) ) {
                    c--; save(); c++;
                }
                save(); c++;
                break;
            }
            if ( *c == EOS ) {
                state = ST_END; err = ERR_SQ_OPEN_AT_EOS;
                break;
            }
            assert(0);
        case ST_ARG:
            if ( *c == SQ || *c == DQ ) {
                qc = *c; c++; state = ST_QUOTE;
                break;
            }
            if ( is_delim(*c) || *c == EOS ) {
                push();
                state = (*c == EOS) ? ST_END : ST_DELIM;
                c++;
                break;
            }
            if ( *c == BS ) {
                c++;
                if ( *c == NL ) {
                    c++;
                    break;
                }
                if ( *c == EOS ) {
                    state = ST_END; err = ERR_BS_AT_EOS;
                    break;
                }
            }
            /* All other cases, incl. character after BS */
            save(); c++;
            break;
        default:
            assert(0);
        }
    }
    
    return ( err != ERR_OK ) ? -1 : flags;
}
コード例 #13
0
ファイル: Scene.cpp プロジェクト: Sand3r-/gltut
void Scene::Draw( glutil::MatrixStack &modelMatrix, int materialBlockIndex, float alphaTetra )
{
	//Render the ground plane.
	{
		glutil::PushStack push(modelMatrix);
		modelMatrix.RotateX(-90);

		DrawObject(m_pTerrainMesh.get(), GetProgram(LP_VERT_COLOR_DIFFUSE), materialBlockIndex, 0,
			modelMatrix);
	}

	//Render the tetrahedron object.
	{
		glutil::PushStack push(modelMatrix);
		modelMatrix.Translate(75.0f, 5.0f, 75.0f);
		modelMatrix.RotateY(360.0f * alphaTetra);
		modelMatrix.Scale(10.0f, 10.0f, 10.0f);
		modelMatrix.Translate(0.0f, sqrtf(2.0f), 0.0f);
		modelMatrix.Rotate(glm::vec3(-0.707f, 0.0f, -0.707f), 54.735f);

		DrawObject(m_pTetraMesh.get(), "lit-color", GetProgram(LP_VERT_COLOR_DIFFUSE_SPECULAR),
			materialBlockIndex, 1, modelMatrix);
	}

	//Render the monolith object.
	{
		glutil::PushStack push(modelMatrix);
		modelMatrix.Translate(88.0f, 5.0f, -80.0f);
		modelMatrix.Scale(4.0f, 4.0f, 4.0f);
		modelMatrix.Scale(4.0f, 9.0f, 1.0f);
		modelMatrix.Translate(0.0f, 0.5f, 0.0f);

		DrawObject(m_pCubeMesh.get(), "lit", GetProgram(LP_MTL_COLOR_DIFFUSE_SPECULAR),
			materialBlockIndex, 2, modelMatrix);
	}

	//Render the cube object.
	{
		glutil::PushStack push(modelMatrix);
		modelMatrix.Translate(-52.5f, 14.0f, 65.0f);
		modelMatrix.RotateZ(50.0f);
		modelMatrix.RotateY(-10.0f);
		modelMatrix.Scale(20.0f, 20.0f, 20.0f);

		DrawObject(m_pCubeMesh.get(), "lit-color", GetProgram(LP_VERT_COLOR_DIFFUSE_SPECULAR),
			materialBlockIndex, 3, modelMatrix);
	}

	//Render the cylinder.
	{
		glutil::PushStack push(modelMatrix);
		modelMatrix.Translate(-7.0f, 30.0f, -14.0f);
		modelMatrix.Scale(15.0f, 55.0f, 15.0f);
		modelMatrix.Translate(0.0f, 0.5f, 0.0f);

		DrawObject(m_pCylMesh.get(), "lit-color", GetProgram(LP_VERT_COLOR_DIFFUSE_SPECULAR),
			materialBlockIndex, 4, modelMatrix);
	}

	//Render the sphere.
	{
		glutil::PushStack push(modelMatrix);
		modelMatrix.Translate(-83.0f, 14.0f, -77.0f);
		modelMatrix.Scale(20.0f, 20.0f, 20.0f);

		DrawObject(m_pSphereMesh.get(), "lit", GetProgram(LP_MTL_COLOR_DIFFUSE_SPECULAR),
			materialBlockIndex, 5, modelMatrix);
	}
}
コード例 #14
0
ファイル: e06.c プロジェクト: kokosabu/exercises
int main()
{
    int type;
    double op1, op2;
    char s[MAXOP];

    while ((type = getop(s)) != EOF) {
        switch (type) {
        case NUMBER:
            push(atof(s));
            break;
        case '+':
            push(pop() + pop());
            break;
        case '*':
            push(pop() * pop());
            break;
        case '-':
            op2 = pop();
            op1 = pop();
            if (op1 == 0.0)
                push(op2 * -1);
            else
                push(op1 - op2);
            break;
        case '/':
            op2 = pop();
            if (op2 != 0.0)
                push(pop() / op2);
            else
                printf("error: zero divisor\n");
            break;
        case '%':
            op2 = pop();
            push(fmod(pop(), op2));
            break;
        case 'c':
            op2 = pop();
            op1 = pop();
/**********************************************/
            v = op2;
/**********************************************/
            printf("%f\n", op2);
            push(op2);
            push(op1);
            break;
        case 's':
            push(sin(pop())); 
            break;
        case 'e':
            push(exp(pop()));
            break;
        case 'p':
            op2 = pop();
            push(pow(pop(), op2));
            break;
/*****************************************************/
        case 'v':
            push(v);
            break;
        case '\n':
            v = pop();
            printf("\t%.8g\n", v);
            break;
/*****************************************************/
        default:
            printf("error: unknown command %s\n", s);
            break;
        }
    }
    return 0;
}
コード例 #15
0
void DrawParthenon(glutil::MatrixStack &modelMatrix)
{
	//Draw base.
	{
		glutil::PushStack push(modelMatrix);

		modelMatrix.Scale(glm::vec3(g_fParthenonWidth, g_fParthenonBaseHeight, g_fParthenonLength));
		modelMatrix.Translate(glm::vec3(0.0f, 0.5f, 0.0f));

		glUseProgram(UniformColorTint.theProgram);
		glUniformMatrix4fv(UniformColorTint.modelToWorldMatrixUnif, 1, GL_FALSE, glm::value_ptr(modelMatrix.Top()));
		glUniform4f(UniformColorTint.baseColorUnif, 0.9f, 0.9f, 0.9f, 0.9f);
		g_pCubeTintMesh->Render();
		glUseProgram(0);
	}

	//Draw top.
	{
		glutil::PushStack push(modelMatrix);

		modelMatrix.Translate(glm::vec3(0.0f, g_fParthenonColumnHeight + g_fParthenonBaseHeight, 0.0f));
		modelMatrix.Scale(glm::vec3(g_fParthenonWidth, g_fParthenonTopHeight, g_fParthenonLength));
		modelMatrix.Translate(glm::vec3(0.0f, 0.5f, 0.0f));

		glUseProgram(UniformColorTint.theProgram);
		glUniformMatrix4fv(UniformColorTint.modelToWorldMatrixUnif, 1, GL_FALSE, glm::value_ptr(modelMatrix.Top()));
		glUniform4f(UniformColorTint.baseColorUnif, 0.9f, 0.9f, 0.9f, 0.9f);
		g_pCubeTintMesh->Render();
		glUseProgram(0);
	}

	//Draw columns.
	const float fFrontZVal = (g_fParthenonLength / 2.0f) - 1.0f;
	const float fRightXVal = (g_fParthenonWidth / 2.0f) - 1.0f;

	for(int iColumnNum = 0; iColumnNum < int(g_fParthenonWidth / 2.0f); iColumnNum++)
	{
		{
			glutil::PushStack push(modelMatrix);
			modelMatrix.Translate(glm::vec3((2.0f * iColumnNum) - (g_fParthenonWidth / 2.0f) + 1.0f,
				g_fParthenonBaseHeight, fFrontZVal));

			DrawColumn(modelMatrix, g_fParthenonColumnHeight);
		}
		{
			glutil::PushStack push(modelMatrix);
			modelMatrix.Translate(glm::vec3((2.0f * iColumnNum) - (g_fParthenonWidth / 2.0f) + 1.0f,
				g_fParthenonBaseHeight, -fFrontZVal));

			DrawColumn(modelMatrix, g_fParthenonColumnHeight);
		}
	}

	//Don't draw the first or last columns, since they've been drawn already.
	for(int iColumnNum = 1; iColumnNum < int((g_fParthenonLength - 2.0f) / 2.0f); iColumnNum++)
	{
		{
			glutil::PushStack push(modelMatrix);
			modelMatrix.Translate(glm::vec3(fRightXVal,
				g_fParthenonBaseHeight, (2.0f * iColumnNum) - (g_fParthenonLength / 2.0f) + 1.0f));

			DrawColumn(modelMatrix, g_fParthenonColumnHeight);
		}
		{
			glutil::PushStack push(modelMatrix);
			modelMatrix.Translate(glm::vec3(-fRightXVal,
				g_fParthenonBaseHeight, (2.0f * iColumnNum) - (g_fParthenonLength / 2.0f) + 1.0f));

			DrawColumn(modelMatrix, g_fParthenonColumnHeight);
		}
	}

	//Draw interior.
	{
		glutil::PushStack push(modelMatrix);

		modelMatrix.Translate(glm::vec3(0.0f, 1.0f, 0.0f));
		modelMatrix.Scale(glm::vec3(g_fParthenonWidth - 6.0f, g_fParthenonColumnHeight,
			g_fParthenonLength - 6.0f));
		modelMatrix.Translate(glm::vec3(0.0f, 0.5f, 0.0f));

		glUseProgram(ObjectColor.theProgram);
		glUniformMatrix4fv(ObjectColor.modelToWorldMatrixUnif, 1, GL_FALSE, glm::value_ptr(modelMatrix.Top()));
		g_pCubeColorMesh->Render();
		glUseProgram(0);
	}

	//Draw headpiece.
	{
		glutil::PushStack push(modelMatrix);

		modelMatrix.Translate(glm::vec3(
			0.0f,
			g_fParthenonColumnHeight + g_fParthenonBaseHeight + (g_fParthenonTopHeight / 2.0f),
			g_fParthenonLength / 2.0f));
		modelMatrix.RotateX(-135.0f);
		modelMatrix.RotateY(45.0f);

		glUseProgram(ObjectColor.theProgram);
		glUniformMatrix4fv(ObjectColor.modelToWorldMatrixUnif, 1, GL_FALSE, glm::value_ptr(modelMatrix.Top()));
		g_pCubeColorMesh->Render();
		glUseProgram(0);
	}
}
コード例 #16
0
	void FloatAttributeUpdater::push(const float *value)
	{
		push(value,1);
	}
コード例 #17
0
//Called to update the display.
//You should call glutSwapBuffers after all of your rendering to display what you rendered.
//If you need continuous updates of the screen, call glutPostRedisplay() at the end of the function.
void display()
{
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClearDepth(1.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	if(g_pConeMesh && g_pCylinderMesh && g_pCubeTintMesh && g_pCubeColorMesh && g_pPlaneMesh)
	{
		const glm::vec3 &camPos = ResolveCamPosition();

		glutil::MatrixStack camMatrix;
		camMatrix.SetMatrix(CalcLookAtMatrix(camPos, g_camTarget, glm::vec3(0.0f, 1.0f, 0.0f)));

		glUseProgram(UniformColor.theProgram);
		glUniformMatrix4fv(UniformColor.worldToCameraMatrixUnif, 1, GL_FALSE, glm::value_ptr(camMatrix.Top()));
		glUseProgram(ObjectColor.theProgram);
		glUniformMatrix4fv(ObjectColor.worldToCameraMatrixUnif, 1, GL_FALSE, glm::value_ptr(camMatrix.Top()));
		glUseProgram(UniformColorTint.theProgram);
		glUniformMatrix4fv(UniformColorTint.worldToCameraMatrixUnif, 1, GL_FALSE, glm::value_ptr(camMatrix.Top()));
		glUseProgram(0);

		glutil::MatrixStack modelMatrix;

		//Render the ground plane.
		{
			glutil::PushStack push(modelMatrix);

			modelMatrix.Scale(glm::vec3(100.0f, 1.0f, 100.0f));

			glUseProgram(UniformColor.theProgram);
			glUniformMatrix4fv(UniformColor.modelToWorldMatrixUnif, 1, GL_FALSE, glm::value_ptr(modelMatrix.Top()));
			glUniform4f(UniformColor.baseColorUnif, 0.302f, 0.416f, 0.0589f, 1.0f);
			g_pPlaneMesh->Render();
			glUseProgram(0);
		}

		//Draw the trees
		DrawForest(modelMatrix);

		//Draw the building.
		{
			glutil::PushStack push(modelMatrix);
			modelMatrix.Translate(glm::vec3(20.0f, 0.0f, -10.0f));

			DrawParthenon(modelMatrix);
		}

		if(g_bDrawLookatPoint)
		{
			glDisable(GL_DEPTH_TEST);
			glm::mat4 idenity(1.0f);

			glutil::PushStack push(modelMatrix);

			glm::vec3 cameraAimVec = g_camTarget - camPos;
			modelMatrix.Translate(0.0f, 0.0, -glm::length(cameraAimVec));
			modelMatrix.Scale(1.0f, 1.0f, 1.0f);
		
			glUseProgram(ObjectColor.theProgram);
			glUniformMatrix4fv(ObjectColor.modelToWorldMatrixUnif, 1, GL_FALSE, glm::value_ptr(modelMatrix.Top()));
			glUniformMatrix4fv(ObjectColor.worldToCameraMatrixUnif, 1, GL_FALSE, glm::value_ptr(idenity));
			g_pCubeColorMesh->Render();
			glUseProgram(0);
			glEnable(GL_DEPTH_TEST);
		}
	}

	glutSwapBuffers();
}
コード例 #18
0
ファイル: 4-4.c プロジェクト: sirajmuneer123/k-and-r
/* reverse Polish calculator */
main()
{
	int type;
	double op2,temp;
	char s[MAXOP];
	while ((type = getop(s)) != EOF) {
		switch (type) {
			case NUMBER:
				push(atof(s));
				break;
			case '+':
				push(pop() + pop());
				break;
			case '*':
				push(pop() * pop());
				break;
			case '-':
				op2 = pop();
				push(pop() - op2);
				break;
			case '/':
				op2 = pop();
				if (op2 != 0.0)
					push(pop() / op2);
				else
					printf("error: zero divisor\n");
				break;
			case '%':
				op2=pop();
				if(op2!=0.0)
					push(fmod(pop(), op2));
				else
					printf("error :zero diviser\n");
				break;
			case '?':
				op2=pop();
				printf("the top value of the stack is: %g\n ",op2);
				push(op2);
				break;
			case 'd':
				op2=pop();
				push(op2);
				push(op2);
				break;
			case 's':
				op2=pop();
				temp=pop();
				push(op2);
				push(temp);
				break;
			case 'c':
				clear();
				break;
			case '\n':
				printf("\t%.8g\n", pop());
				break;
			default:
				printf("error: unknown command %s\n", s);
				break;
		}
	}
	return 0;
}
コード例 #19
0
ファイル: counter.hpp プロジェクト: flixster/mesos
 void reset()
 {
   push(__sync_and_and_fetch(&data->v, 0));
 }
コード例 #20
0
ファイル: compiler.cpp プロジェクト: honzasp/brainfuck
	bool Compiler::compile(std::istream& input)
	{
		mInput = &input;
		mInstructions.clear();

		std::stack<int> loopStack;
		char command;

		command = getCommand();
		while(command) {
			int move = 0;
			while(command and isMove(command)) {
				if(command == '>') {
					move++;
				} else {
					move--;
				}
				command = getCommand();
			}
			if(move != 0) {
				push(op_move);
				push(move);
			}

			int change = 0;
			while(command and isChange(command)) {
				if(command == '+') {
					change++;
				} else {
					change--;
				}
				command = getCommand();
			}
			if(change != 0) {
				push(op_change);
				push(change);
			}

			while(command and isIO(command)) {
				if(command == '.') {
					push(op_output);
				} else {
					push(op_input);
				}
				command = getCommand();
			}

			while(command and isLoop(command)) {
				if(command == '[') {
					loopStack.push(mInstructions.size());

					push(op_loop_begin);
					push(-1);
				} else {
					if(loopStack.empty()) {
						mError = "unopened ]";
						return false;
					} else {
						push(op_loop_end);
						mInstructions[loopStack.top() + 1].param = mInstructions.size();
						loopStack.pop();
					}
				}
				command = getCommand();
			}
		}

		if(not loopStack.empty()) {
			mError = "unclosed [";
			return false;
		}

		push(op_stop);

		return true;
	}
コード例 #21
0
ファイル: read-command.c プロジェクト: robertabbott/CS_111
command_t
makeCommandStreamUtil(int (*get_next_byte) (void *),
		      void *get_next_byte_argument,
		      STATE *state)
{
  char **tokenPTR = checked_malloc(sizeof(char**));
  char *token = NULL;
  int len = 0;
  TOKENTYPE type;
  command_t command = NULL;
  char *input = NULL, *output = NULL;

  type = readNextToken(tokenPTR, &len, get_next_byte, get_next_byte_argument);
  if (type == NOT_DEFINED) {
    free(tokenPTR);
    return NULL;
  } else if (type == O_PAR) {
    token = "(";
  } else {
    token = *tokenPTR;
  }

  command = AllocateCommand();
  if (!command) {
    return NULL;
  }


  if (!strncmp(token, "then", 4)) {
    if (!(pop() == IF)) {
      printErr();
    }
    push(THEN);
    *state = THEN;
    goto ret_null;
  } else if (!strncmp(token, "done", 4)) {
    if (!(pop() == DO)) {
      printErr();
    }
    *state = DONE;
    CScount--;
    goto ret_null;
  } else if (!strncmp(token, "do", 4)) {
    STATE tmp = pop();
    if (!((tmp == WHILE) || (tmp == UNTIL))) {
      printErr();
    }
    push(DO);
    *state = DO;
    goto ret_null;
  } else if (!strncmp(token, "else", 4)) {
    if (!(pop() == THEN)) {
      printErr();
    }
    push(ELSE);
    *state = ELSE;
    goto ret_null;
  } else if (!strncmp(token, "fi", 4)) {
    STATE tmp = pop();
    if (!((tmp == THEN) || (tmp == ELSE))) {
      printErr();
    }
    CScount--;
    *state = FI;
    goto ret_null;
  } else if (!strncmp(token, ")", 1)) {
    CScount--;
    *state = CLOSE_PAR;
    goto ret_null;
  } else if (!strncmp(token, "if", 2)) {
    push(IF);
    CScount++;
    command = makeCommand(command, NULL, IF_COMMAND, input, output);
    free(tokenPTR);
    command->u.command[0] = makeCommandStreamUtil(get_next_byte,
						  get_next_byte_argument,
						  state);
    while (*state != THEN) {
      if (!makeCommandStreamUtil(get_next_byte,
				 get_next_byte_argument,
				 state)) {
	type = NOT_DEFINED;
	break;
      }
    }

    if (type == NOT_DEFINED && *state != THEN) {
      return NULL;
    }

    command->u.command[1] = makeCommandStreamUtil(get_next_byte,
						  get_next_byte_argument,
						  state);
    if (*state != ELSE && *state != FI) {
      // HANDLE error;
      ;
    } else if (*state == ELSE || (*state == FI && CScount)) {
	command->u.command[2] = makeCommandStreamUtil(get_next_byte,
						      get_next_byte_argument,
						      state);
    } else {
      command->u.command[2] = NULL;
    }
  } else if (!strncmp(token, "while", 5)) {
    push(WHILE);
    (CScount)++;
    command = makeCommand(command, NULL, WHILE_COMMAND, input, output);
    free(tokenPTR);
    command->u.command[0] = makeCommandStreamUtil(get_next_byte,
						  get_next_byte_argument,
						  state);
    if (*state != DO) {
      // Handle Error
      ;
    }
    command->u.command[1] = makeCommandStreamUtil(get_next_byte,
						  get_next_byte_argument,
						  state);
    if (*state != DONE) {
      // HANDLE error;
      ;
    } else if (*state == DONE) {
      if (checkRedirection(get_next_byte, get_next_byte_argument)) {
	fillRedirectionOperands(&command->input, &command->output,
				get_next_byte, get_next_byte_argument);
      }

      command->u.command[2] = makeCommandStreamUtil(get_next_byte,
      						    get_next_byte_argument,
      						    state);
      /* if (command->u.command[2]) { */
      /* 	command_t newCommand = makeCommand(NULL, NULL, SEQUENCE_COMMAND, */
      /* 					   NULL, NULL); */
      /* 	newCommand->u.command[0] = command->u.command[1]; */
      /* 	newCommand->u.command[1] = command->u.command[2]; */
      /* 	command->u.command[1] = newCommand; */
      /* 	command->u.command[2] = NULL; */
      /* } */

    } else {
      command->u.command[2] = NULL;
    }    
  } else if (!strncmp(token, "until", 5)) {
    push(UNTIL);
    (CScount)++;
    command = makeCommand(command, NULL, UNTIL_COMMAND, input, output);
    free(tokenPTR);
    command->u.command[0] = makeCommandStreamUtil(get_next_byte,
						  get_next_byte_argument,
						  state);
    if (*state != DO) {
      // Handle Error
      ;
    }
    command->u.command[1] = makeCommandStreamUtil(get_next_byte,
						  get_next_byte_argument,
						  state);
    if (*state != DONE) {
      // HANDLE error;
      ;
    } else if (*state == DONE) {
      if (checkRedirection(get_next_byte, get_next_byte_argument)) {
	fillRedirectionOperands(&command->input, &command->output,
				get_next_byte, get_next_byte_argument);
      }
      command->u.command[2] = makeCommandStreamUtil(get_next_byte,
      						    get_next_byte_argument,
      						    state);
      /* if (command->u.command[2]) { */
      /* 	command_t newCommand = makeCommand(NULL, NULL, SEQUENCE_COMMAND, */
      /* 					   NULL, NULL); */
      /* 	newCommand->u.command[0] = command->u.command[1]; */
      /* 	newCommand->u.command[1] = command->u.command[2]; */
      /* 	command->u.command[1] = newCommand; */
      /* 	command->u.command[2] = NULL; */
      /* } */
    } else {
      command->u.command[2] = NULL;
    }    

  } else if (!strncmp(token, "(", 1)) {
    CScount++;
    command = makeCommand(command, NULL, SUBSHELL_COMMAND, input, output);
    free(tokenPTR);
    command->u.command[0] =  makeCommandStreamUtil(get_next_byte,
              get_next_byte_argument,
              state);
    if (*state != CLOSE_PAR) {
      // Handle Error
    } else if (*state == CLOSE_PAR && CScount) {
      command->u.command[0] = makeCommandStreamUtil(get_next_byte,
                get_next_byte_argument,
                state);
    } 
  } else {
    // SIMPLE_COMMAND
    while (1) {
      STATE prevState = *state;
      if (isKeyWordUpdate(token, state) && (prevState == COMMAND)) {
         	removeWhiteSpace(token);
        	command = makeSimpleCommand(command, tokenPTR, input, output);
        	break;
      }
      if (type == REDIRECTION1 || type == REDIRECTION2) {
	type = fillRedirectionOperands(&input,
				       &output,
				       get_next_byte,
				       get_next_byte_argument);

	//	command = makeSimpleCommand(command, tokenPTR, input, output);
	//        break;
	//	type = readNextToken(tokenPTR, &len, get_next_byte, get_next_byte_argument);
      } else if (type == SPACE) {
	appendChar(token, ' ');
	type = readNextToken(tokenPTR, &len, get_next_byte, get_next_byte_argument);
      } else if (type == NEWLINE && !CScount) {
      	command = makeSimpleCommand(command, tokenPTR, input, output);
      	break;
      } else if (type == PIPE || type == SEMICOLON || type == NEWLINE) {
	removeWhiteSpace(token);
	if (((type == PIPE) || (type == SEMICOLON)) && !strlen(token)) {
	  printErr();
	}
	command = makeCommand(command, tokenPTR, 
			      type == PIPE ? PIPE_COMMAND : SEQUENCE_COMMAND,
			      input, output);
	command->u.command[1] = makeCommandStreamUtil(get_next_byte,
						      get_next_byte_argument,
						      state);
	if (!command->u.command[1]) {
	  command = convertToSimple(command);
	}
	break;
      }
      *state = COMMAND;
    }
  }

  return command;
ret_null:
  free(command);
  free(tokenPTR);
  return NULL;
}
コード例 #22
0
void GPUDrawScanlineCodeGenerator::Generate()
{
	push(esi);
	push(edi);

	Init();

	align(16);

L("loop");

	// GSVector4i test = m_test[7 + (steps & (steps >> 31))];

	mov(edx, ecx);
	sar(edx, 31);
	and(edx, ecx);
	shl(edx, 4);

	movdqa(xmm7, ptr[edx + (size_t)&m_test[7]]);

	// movdqu(xmm1, ptr[edi]);

	movq(xmm1, qword[edi]);
	movhps(xmm1, qword[edi + 8]);

	// ecx = steps
	// esi = tex (tme)
	// edi = fb
	// xmm1 = fd
	// xmm2 = s
	// xmm3 = t
	// xmm4 = r
	// xmm5 = g
	// xmm6 = b
	// xmm7 = test

	TestMask();

	SampleTexture();

	// xmm1 = fd
	// xmm3 = a
	// xmm4 = r
	// xmm5 = g
	// xmm6 = b
	// xmm7 = test
	// xmm0, xmm2 = free

	ColorTFX();

	AlphaBlend();

	Dither();

	WriteFrame();

L("step");

	// if(steps <= 0) break;

	test(ecx, ecx);
	jle("exit", T_NEAR);

	Step();

	jmp("loop", T_NEAR);

L("exit");

	pop(edi);
	pop(esi);

	ret(8);
}
コード例 #23
0
ファイル: Dijkstra.hpp プロジェクト: galippi/xcsoar
 /**
  * Constructor
  *
  * @param n Node to start
  * @param is_min Whether this algorithm will search for min or max distance
  */
 Dijkstra(const Node &node, const bool is_min = true) :
   m_min(is_min) { 
   push(node, node, 0);
   reserve();
 }
コード例 #24
0
int main(int argc, char *argv[]) {
    pptr = code;
    len = strlen(code);
    push(NULL);
    return 0;
}
コード例 #25
0
void main()
{
  int i,choice,no,r,last=0;
  int Stack[20],b=0;
  clrscr();

   do
   {
    printf("\n1> FOR PUSH INTO STACK");
    printf("\n2> FOR POP FROM STACK");
    printf("\n3> FOR EXIT FROM MENU");
    printf("\nENTER YOUR CHOICE:");
    scanf("%d",&choice);

    switch(choice)
    {
      case 1:printf("\nEnter Number:");
	     scanf("%d",&no);
	     if(no>9)
	     { printf("\n-->YOU HAVE ENTER NUMBER BETWEEN (0- 9):");}

	     else if(no>=last+2 || no<=last)
	     {
	       if(no==0)
	       {
				push(no);
	       }
	       else
	       {
				printf("\nLAST PUSHED NUMBER:%d",last);
				printf("\nPLESE PUSH NUMBER IN PROPER SEQUENCE\n");
	       }
	     }
	     else
	     {
		    last=no;
		    push(no);
	     }
	     break;

       case 2: r=pop();
				if(r!=-1)
				{
					Stack[b++]=r;
					printf("\nPOP element from stack:%d",r);
				}
				printf("\nElement in Stack:");
				for(i=0;i<b;i++)
				{
						printf("%d ",Stack[i]);
				}
				printf("\n");
				break;

      case 3: exit(0);
				break;

     default:printf("\n Please Enter Proper Choice");
    }
   }while(choice!=3);
   getch();
}
コード例 #26
0
ファイル: lua_ref_impl.hpp プロジェクト: HyEvil/kaguya
			//push to Lua stack
			int push()const
			{
				return push(state_);
			}
コード例 #27
0
ファイル: Dijkstra.hpp プロジェクト: Plantain/XCSoar
/** 
 * Add an edge (node-node-distance) to the search 
 * 
 * @param n Destination node to add
 * @param pn Predecessor of destination node
 * @param e Edge distance
 */
  void link(const Node &n, const Node &pn, const unsigned &e=1) { 
#ifdef INSTRUMENT_TASK
    count_dijkstra_links++;
#endif
    push(n, pn, cur->second + minmax_dist(e)); 
  }
コード例 #28
0
ファイル: lua_ref_impl.hpp プロジェクト: HyEvil/kaguya
			int pushStackIndex(lua_State* state)const
			{
				push(state);
				return lua_gettop(state);
			}
コード例 #29
0
ファイル: Dijkstra.hpp プロジェクト: Plantain/XCSoar
/** 
 * Resets as if constructed afresh
 * 
 * @param n Node to start
 */
  void reset(const Node &n) {
    clear();
    push(n,n,0);
  };
コード例 #30
0
ファイル: CFG.hpp プロジェクト: DezerteR/Po-Male-Ka
	Cfg& operator [] (u32 i){
		if(i >= container.size())
			push("");
		return container[i];
	}