本文整理汇总了C++中Cube::Draw方法的典型用法代码示例。如果您正苦于以下问题:C++ Cube::Draw方法的具体用法?C++ Cube::Draw怎么用?C++ Cube::Draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cube
的用法示例。
在下文中一共展示了Cube::Draw方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DrawRubik
void Rubik::DrawRubik(GLfloat rot, Cube::Layer primary,int iterr,vector<Cube::Layer> alllayers,vector<int> allrotlayers){
int injuraxei = -1;
if(primary == Cube::L_L1 || primary == Cube::L_L2 || primary == Cube::L_L3){
injuraxei = 1;
}
else
if(primary == Cube::L_D1 || primary == Cube::L_D2 || primary == Cube::L_D3){
injuraxei = 2;
}
else
if(primary == Cube::L_F1 || primary == Cube::L_F2 || primary == Cube::L_F3){
injuraxei = 3;
}
vector<Cube*> primare ;
int k = 0;
for(list<Cube*>::iterator it = cuburi.begin(); it!= cuburi.end(); it++){
Cube * c = (*it);
glPushMatrix();
if(c->layer1 == primary || c->layer2 == primary || c->layer3 == primary){
primare.push_back(c);
}else
glTranslatef(c->trax + size*0.1,c->tray + size*0.1,c->traz+ size*0.1);
c->Draw(size,0);
glPopMatrix();
}
if(injuraxei == 1)
glRotatef(rot,1.0f,0.0f,0.0f);
else
if(injuraxei == 2)
glRotatef(rot,0.0f,1.0f,0.0f);
else
if(injuraxei == 3)
glRotatef(rot,0.0f,0.0f,1.0f);
for(vector<Cube*>::iterator it = primare.begin(); it!= primare.end(); it++){
Cube * c = (*it);
glPushMatrix();
glTranslatef(c->trax,c->tray,c->traz);
c->Draw(size,1);
glPopMatrix();
}
}
示例2: DisplayCube
void DisplayCube()
{
Window * window = Window::FindCurrentWindow(windows);
if (window->handle == BAD_GL_VALUE)
return;
glViewport(0, 0, window->size.x, window->size.y);
vec4 crimson(0.6f, 0.0f, 0.0f, 1.0f);
vec3 ambient = vec3(0.0f, 0.0f, 0.0f);
vec3 specular = vec3(0.6f, 0.0f, 0.0f);
vec3 diffuse = vec3(0.0f, 0.0f, 0.8f);
glClearColor(crimson.r, crimson.g, crimson.b, crimson.a);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
mat4 model_matrix = rotate(mat4(), radians(window->LocalTime() * 30.0f), vec3(0.1f, 1.0f, 0.1f));
model_matrix = rotate(model_matrix, radians(5.0f), vec3(1.0f, 1.0f, 1.0f));
model_matrix = scale(model_matrix, vec3(0.7f, 0.7f, 0.7f));
mat4 view_matrix = lookAt(vec3(0.0f, 0.0f, 5.0f), vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 1.0f, 0.0f));
mat4 projection_matrix = perspective(radians(window->fovy), window->aspect, window->near_distance, window->far_distance);
phong_shader.Use(model_matrix, view_matrix, projection_matrix);
phong_shader.SetMaterial(diffuse, specular, 64.0f, ambient);
phong_shader.SetLightPosition(vec3(0.0f, 0.0f, 1000.0f));
phong_shader.SelectSubroutine(PhongShader::SHADER_TOY_1);
phong_shader.SetGlobalTime(Window::CurrentTime());
phong_shader.EnableTexture(textures[3] , 0);
cube.Draw(false);
phong_shader.UnUse();
if (window->draw_normals)
{
constant_shader.Use(model_matrix , view_matrix , projection_matrix);
constant_shader.SetMaterial(diffuse , specular , 64.0f , vec3(1.0f , 1.0f , 1.0f));
cube.Draw(true);
constant_shader.UnUse();
}
glutSwapBuffers();
cube.UpdateValues(TestUpdateCube, window->LocalTime(), nullptr);
}
示例3: WinMain
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR, int )
{
HANDLE ghInstance;
WNDCLASS wcex;
HWND hwnd;
TCHAR WindowTitle[] = _T("Cube");
TCHAR WindowClassName[] = _T("AppClass");
if (!hPrevInstance)
{
wcex.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.lpszClassName = WindowClassName;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = 0;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
if (!RegisterClass(&wcex))
return 0;
}
ghInstance = hInstance;
if (NULL==(hwnd = CreateWindow(WindowClassName, WindowTitle,
WS_CAPTION | WS_SYSMENU,
CW_USEDEFAULT, 0, WIDTH, HEIGHT,
NULL, NULL, hInstance, NULL)))
{
return 0;
}
if (SUCCEEDED(cube.device.InitialDirect3D(hwnd)))
{
if (SUCCEEDED(cube.InitialObject()))
{
if (SUCCEEDED(cube.device.shader.InitialShader()))
{
ShowWindow(hwnd, SW_SHOWDEFAULT);
UpdateWindow(hwnd);
MSG msg;
ZeroMemory(&msg, sizeof(msg));
while (WM_QUIT!=msg.message)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
cube.Draw();
}
}
}
}
}
return 0;
}
示例4: Draw
void World::Draw(void)
{
//std::cout << "Drawing Terrain at " << posx << " / " << posy << " / " << posz << " / ";
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity (); // Reset The Modelview Matrix
// --- Go to Cam Pos ---
glRotatef (angle.x, 1.0f, 0.0f, 0.0f); // Rotate On The X-Axis By angle
glRotatef (angle.y, 0.0f, 1.0f, 0.0f); // Rotate On The Y-Axis By angle
glRotatef (angle.z, 0.0f, 0.0f, 1.0f); // Rotate On The Z-Axis By angle
glTranslatef (-this->pos.x, -this->pos.y, -this->pos.z); // Translate to Cam Pos
static const float max = 100.0f;
static const float min = 100.0f;
static Cube mycube;
static float speed = 0.10f;
static float pos[4] = {(float)terrain[0]->GetWidth()*2, max, (float)terrain[0]->GetHeight()*2, 1.0f};
static float amb[4] = {0.01f, 0.01f, 0.01f, 1.0f};
static float dif[4] = {0.5f, 0.5f, 0.5f, 1.0f};
static float spec[4]= {1.0f, 1.0f, 1.0f, 1.0f};
GL_SetLight(pos, amb, dif, spec);
mycube.Create(pos[0],pos[1],pos[2],1.0f);
pos[1]+=speed;
if(pos[1] >= max){
speed = -speed;
pos[1]=max;
}
else if(pos[1] <= min){
speed = -speed;
pos[1]=min;
}
mycube.Draw();
DrawChildren();
if(drawright)
{
glPushMatrix();
glTranslatef(terrain[0]->GetWidth(), 0.0f, 0.0f);
DrawChildren();
glPopMatrix();
}
if(drawleft)
{
glPushMatrix();
glTranslatef(-(terrain[0]->GetWidth()), 0.0f, 0.0f);
DrawChildren();
glPopMatrix();
}
if(drawtop)
{
glPushMatrix();
glTranslatef(0.0f, 0.0f, -terrain[0]->GetHeight());
DrawChildren();
if(drawright)
{
glTranslatef(terrain[0]->GetWidth(), 0.0f, 0.0f);
DrawChildren();
glTranslatef(-terrain[0]->GetWidth(), 0.0f, 0.0f);
}
if(drawleft)
{
glTranslatef(-(terrain[0]->GetWidth()), 0.0f, 0.0f);
DrawChildren();
}
glPopMatrix();
}
if(drawbuttom)
{
glPushMatrix();
glTranslatef(0.0f, 0.0f, terrain[0]->GetHeight());
DrawChildren();
if(drawright)
{
glTranslatef(terrain[0]->GetWidth(), 0.0f, 0.0f);
DrawChildren();
glTranslatef(-terrain[0]->GetWidth(), 0.0f, 0.0f);
}
if(drawleft)
{
glTranslatef(-(terrain[0]->GetWidth()), 0.0f, 0.0f);
DrawChildren();
}
glPopMatrix();
}/**/
glFlush (); // Flush The GL Rendering Pipeline
}
示例5: DrawScene
void DrawScene(Window * window)
{
phong_shader.GLReturnedError("DrawScene() - entering");
#ifdef MOVE
mat4 m = rotate(mat4() , radians(window->LocalTime() * 30.0f) , vec3(0.0f , 1.0f , 0.2f));
m = translate(m, vec3(0.0f, 11.5f * cos(window->LocalTime() * 0.5f) + 2.0f, 11.5f * sin(window->LocalTime() * 0.5f) + 2.0f));
#else
mat4 m;
#endif // MOVE
mat4 view_matrix = lookAt(vec3(m * vec4(eye, 1.0f)), cop, up);
mat4 model_matrix;
mat4 projection_matrix = perspective(radians(window->fovy), window->aspect, window->near_distance, window->far_distance);
vec3 z_axis = vec3(0.0f, 0.0f, 1.0f);
vec3 y_axis = vec3(0.0f, 1.0f, 0.0f);
vec3 ambient = vec3(0.1f, 0.1f, 0.1f);
vec3 specular = vec3(1.0f, 1.0f, 1.0f);
float c_offset = radians(45.0f);
glViewport(0, 0, window->size.x, window->size.y);
const int count_of_shapes = 4;
for (unsigned int i = 0; i < instances.size(); i++)
{
model_matrix = translate(mat4(), instances[i].position);
model_matrix = rotate(model_matrix, radians(window->LocalTime() * instances[i].rate) + instances[i].offset, y_axis);
if (i % count_of_shapes == 3)
model_matrix = scale(model_matrix, vec3(0.25f, 0.25f, 0.25f));
phong_shader.Use(model_matrix, view_matrix, projection_matrix);
phong_shader.SetMaterial(instances[i].diffuse, specular, 32.0f, ambient);
phong_shader.SetLightPosition(vec3(0.0f, 0.0f, 1000.0f));
switch (i % count_of_shapes)
{
case 0:
disc1.Draw(false);
break;
case 1:
disc3.Draw(false);
break;
case 2:
plane2.Draw(false);
break;
case 3:
cube.Draw(false);
break;
}
phong_shader.UnUse();
#ifdef SHOW_NORMALS
if (i == 0)
{
constant_shader.Use(model_matrix, view_matrix, projection_matrix);
constant_shader.SetMaterial(vec3(0.0f, 0.0f, 0.8f), specular, 128.0f, vec3(1.0f, 0.0f, 0.0f));
disc1.Draw(true);
constant_shader.UnUse();
}
#endif
}
model_matrix = mat4();
mat4 mz = model_matrix;
model_matrix = scale(model_matrix, vec3(0.5f, 0.5f, 16.0f));
phong_shader.Use(model_matrix, view_matrix, projection_matrix);
phong_shader.SetMaterial(vec3(0.0f, 0.0f, 0.8f), specular, 128.0f, ambient);
phong_shader.SetLightPosition(vec3(0.0f, 1000.0f, 0.0f));
cylinder1.Draw(false);
phong_shader.UnUse();
#ifdef SHOW_NORMALS
constant_shader.Use(model_matrix, view_matrix, projection_matrix);
constant_shader.SetMaterial(vec3(0.0f, 0.0f, 0.8f), specular, 128.0f, vec3(1.0f, 1.0f, 1.0f));
cylinder.Draw(true);
constant_shader.UnUse();
#endif
model_matrix = rotate(mz, radians(90.0f), y_axis);
model_matrix = scale(model_matrix, vec3(0.5f, 0.5f, 16.0f));
phong_shader.Use(model_matrix, view_matrix, projection_matrix);
phong_shader.SetMaterial(vec3(1.0f, 0.0f, 0.0f), specular, 128.0f, ambient);
phong_shader.SetLightPosition(vec3(0.0f, 1000.0f, 0.0f));
cylinder1.Draw(false);
phong_shader.UnUse();
model_matrix = rotate(mz, radians(-90.0f), vec3(1.0f, 0.0f, 0.0f));
model_matrix = scale(model_matrix, vec3(0.5f, 0.5f, 16.0f));
phong_shader.Use(model_matrix, view_matrix, projection_matrix);
phong_shader.SetMaterial(vec3(0.0f, 1.0f, 0.0f), specular, 128.0f, ambient);
phong_shader.SetLightPosition(vec3(0.0f, 1000.0f, 0.0f));
cylinder1.Draw(false);
phong_shader.UnUse();
cylinder1.UpdateValues(TestUpdate, window->LocalTime(), nullptr);
}