本文整理汇总了C++中push函数的典型用法代码示例。如果您正苦于以下问题:C++ push函数的具体用法?C++ push怎么用?C++ push使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了push函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: display
//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: modify
void
modify(const_reference r_old, const_reference r_new)
{
erase(r_old);
push(r_new);
}
示例3: Dijkstra
/**
* 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: link
/**
* 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: restart
/**
* Resets as if constructed afresh
*
* @param n Node to start
*/
void restart(const Node &node) {
clear();
push(node, node, 0);
}
示例6: Counter
// '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: push
Counter& operator += (int64_t v)
{
push(__sync_add_and_fetch(&data->v, v));
return *this;
}
示例8: main
/* 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: mg_write
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: dup
/* dup : duplicate top element and push it in the stack */
void dup(void)
{
push(peek());
}
示例11: split_quoted
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;
//.........这里部分代码省略.........
示例12: push
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);
}
}
示例13: main
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;
}
示例14: DrawParthenon
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()));
//.........这里部分代码省略.........
示例15: push
void FloatAttributeUpdater::push(const float *value)
{
push(value,1);
}