本文整理汇总了C++中scenehdl类的典型用法代码示例。如果您正苦于以下问题:C++ scenehdl类的具体用法?C++ scenehdl怎么用?C++ scenehdl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了scenehdl类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: canvas_menu
//.........这里部分代码省略.........
else if (num == 14)
manipulator = manipulate::front;
else if (num == 15)
manipulator = manipulate::back;
else if (num == 16)
scene.render_cameras = !scene.render_cameras;
else if (num == 17 && scene.active_camera_valid())
scene.cameras[scene.active_camera]->focus = NULL;
else if (num == 18)
{
scene.cameras.push_back(new orthohdl());
scene.objects.push_back(new pyramidhdl(1.0, 1.0, 8));
for (int k = 0; k < scene.objects.back()->rigid.size(); k++)
for (int i = 0; i < scene.objects.back()->rigid[k].geometry.size(); i++)
{
swap(scene.objects.back()->rigid[k].geometry[i][1], scene.objects.back()->rigid[k].geometry[i][2]);
scene.objects.back()->rigid[k].geometry[i][1] *= -1.0;
swap(scene.objects.back()->rigid[k].geometry[i][4], scene.objects.back()->rigid[k].geometry[i][5]);
scene.objects.back()->rigid[k].geometry[i][4] *= -1.0;
}
swap(scene.objects.back()->bound[2], scene.objects.back()->bound[4]);
swap(scene.objects.back()->bound[3], scene.objects.back()->bound[5]);
scene.cameras.back()->model = scene.objects.back();
if (!scene.active_camera_valid())
{
scene.active_camera = scene.cameras.size()-1;
scene.cameras[scene.active_camera]->project(&canvas);
}
}
else if (num == 19)
{
scene.cameras.push_back(new frustumhdl());
scene.objects.push_back(new pyramidhdl(1.0, 1.0, 8));
for (int k = 0; k < scene.objects.back()->rigid.size(); k++)
for (int i = 0; i < scene.objects.back()->rigid[k].geometry.size(); i++)
{
swap(scene.objects.back()->rigid[k].geometry[i][1], scene.objects.back()->rigid[k].geometry[i][2]);
scene.objects.back()->rigid[k].geometry[i][1] *= -1.0;
swap(scene.objects.back()->rigid[k].geometry[i][4], scene.objects.back()->rigid[k].geometry[i][5]);
scene.objects.back()->rigid[k].geometry[i][4] *= -1.0;
}
swap(scene.objects.back()->bound[2], scene.objects.back()->bound[4]);
swap(scene.objects.back()->bound[3], scene.objects.back()->bound[5]);
scene.cameras.back()->model = scene.objects.back();
if (!scene.active_camera_valid())
{
scene.active_camera = scene.cameras.size()-1;
scene.cameras[scene.active_camera]->project(&canvas);
}
}
else if (num == 20)
{
scene.cameras.push_back(new perspectivehdl());
scene.objects.push_back(new pyramidhdl(1.0, 1.0, 8));
for (int k = 0; k < scene.objects.back()->rigid.size(); k++)
for (int i = 0; i < scene.objects.back()->rigid[k].geometry.size(); i++)
{
swap(scene.objects.back()->rigid[k].geometry[i][1], scene.objects.back()->rigid[k].geometry[i][2]);
scene.objects.back()->rigid[k].geometry[i][1] *= -1.0;
swap(scene.objects.back()->rigid[k].geometry[i][4], scene.objects.back()->rigid[k].geometry[i][5]);
scene.objects.back()->rigid[k].geometry[i][4] *= -1.0;
}
swap(scene.objects.back()->bound[2], scene.objects.back()->bound[4]);
swap(scene.objects.back()->bound[3], scene.objects.back()->bound[5]);
scene.cameras.back()->model = scene.objects.back();
if (!scene.active_camera_valid())
{
scene.active_camera = scene.cameras.size()-1;
scene.cameras[scene.active_camera]->project(&canvas);
}
}
else if (num == 21)
canvas.polygon_mode = canvashdl::point;
else if (num == 22)
canvas.polygon_mode = canvashdl::line;
else if (num == 23)
canvas.polygon_mode = canvashdl::fill;
// TODO Assignment 3: uncomment this
//else if (num == 25)
// canvas.shade_model = canvashdl::flat;
//else if (num == 26)
// canvas.shade_model = canvashdl::smooth;
else if (num == 28)
canvas.culling = canvashdl::disable;
else if (num == 29)
canvas.culling = canvashdl::backface;
else if (num == 30)
canvas.culling = canvashdl::frontface;
else if (num == 31)
scene.render_normals = scenehdl::none;
else if (num == 32)
scene.render_normals = scenehdl::face;
else if (num == 33)
scene.render_normals = scenehdl::vertex;
glutPostRedisplay();
}
开发者ID:cornell-cs5620,项目名称:assignment1,代码行数:101,代码来源:main.cpp
示例2: canvas_menu
//.........这里部分代码省略.........
manipulator = manipulate::front;
else if (num == 15)
manipulator = manipulate::back;
else if (num == 16)
scene.render_cameras = !scene.render_cameras;
else if (num == 17 && scene.active_camera_valid())
scene.cameras[scene.active_camera]->focus = NULL;
else if (num == 18)
{
scene.cameras.push_back(new orthohdl());
scene.objects.push_back(new pyramidhdl(1.0, 1.0, 8));
for (int k = 0; k < scene.objects.back()->rigid.size(); k++)
for (int i = 0; i < scene.objects.back()->rigid[k].geometry.size(); i++)
{
swap(scene.objects.back()->rigid[k].geometry[i][1], scene.objects.back()->rigid[k].geometry[i][2]);
scene.objects.back()->rigid[k].geometry[i][1] *= -1.0;
swap(scene.objects.back()->rigid[k].geometry[i][4], scene.objects.back()->rigid[k].geometry[i][5]);
scene.objects.back()->rigid[k].geometry[i][4] *= -1.0;
}
swap(scene.objects.back()->bound[2], scene.objects.back()->bound[4]);
swap(scene.objects.back()->bound[3], scene.objects.back()->bound[5]);
scene.cameras.back()->model = scene.objects.back();
if (!scene.active_camera_valid())
{
scene.active_camera = scene.cameras.size()-1;
scene.cameras[scene.active_camera]->project();
}
}
else if (num == 19)
{
scene.cameras.push_back(new frustumhdl());
scene.objects.push_back(new pyramidhdl(1.0, 1.0, 8));
for (int k = 0; k < scene.objects.back()->rigid.size(); k++)
for (int i = 0; i < scene.objects.back()->rigid[k].geometry.size(); i++)
{
swap(scene.objects.back()->rigid[k].geometry[i][1], scene.objects.back()->rigid[k].geometry[i][2]);
scene.objects.back()->rigid[k].geometry[i][1] *= -1.0;
swap(scene.objects.back()->rigid[k].geometry[i][4], scene.objects.back()->rigid[k].geometry[i][5]);
scene.objects.back()->rigid[k].geometry[i][4] *= -1.0;
}
swap(scene.objects.back()->bound[2], scene.objects.back()->bound[4]);
swap(scene.objects.back()->bound[3], scene.objects.back()->bound[5]);
scene.cameras.back()->model = scene.objects.back();
if (!scene.active_camera_valid())
{
scene.active_camera = scene.cameras.size()-1;
scene.cameras[scene.active_camera]->project();
}
}
else if (num == 20)
{
scene.cameras.push_back(new perspectivehdl());
scene.objects.push_back(new pyramidhdl(1.0, 1.0, 8));
for (int k = 0; k < scene.objects.back()->rigid.size(); k++)
for (int i = 0; i < scene.objects.back()->rigid[k].geometry.size(); i++)
{
swap(scene.objects.back()->rigid[k].geometry[i][1], scene.objects.back()->rigid[k].geometry[i][2]);
scene.objects.back()->rigid[k].geometry[i][1] *= -1.0;
swap(scene.objects.back()->rigid[k].geometry[i][4], scene.objects.back()->rigid[k].geometry[i][5]);
scene.objects.back()->rigid[k].geometry[i][4] *= -1.0;
}
swap(scene.objects.back()->bound[2], scene.objects.back()->bound[4]);
swap(scene.objects.back()->bound[3], scene.objects.back()->bound[5]);
scene.cameras.back()->model = scene.objects.back();
if (!scene.active_camera_valid())
{
scene.active_camera = scene.cameras.size()-1;
scene.cameras[scene.active_camera]->project();
}
}
else if (num == 21)
glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
else if (num == 22)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
else if (num == 23)
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
else if (num == 28)
glDisable(GL_CULL_FACE);
else if (num == 29)
{
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
}
else if (num == 30)
{
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
}
else if (num == 31)
scene.render_normals = scenehdl::none;
else if (num == 32)
scene.render_normals = scenehdl::face;
else if (num == 33)
scene.render_normals = scenehdl::vertex;
glutPostRedisplay();
}
开发者ID:yuchien302,项目名称:skeleton,代码行数:101,代码来源:main.cpp
示例3: idlefunc
void idlefunc()
{
bool change = false;
if (scene.active_camera_valid() && scene.cameras[scene.active_camera]->focus == NULL)
{
if (keys['w'])
{
scene.cameras[scene.active_camera]->position += -0.25f*ror3(vec3f(0.0, 0.0, 1.0), scene.cameras[scene.active_camera]->orientation);
change = true;
}
if (keys['s'])
{
scene.cameras[scene.active_camera]->position += 0.25f*ror3(vec3f(0.0, 0.0, 1.0), scene.cameras[scene.active_camera]->orientation);
change = true;
}
if (keys['a'])
{
scene.cameras[scene.active_camera]->position += -0.25f*ror3(vec3f(1.0, 0.0, 0.0), scene.cameras[scene.active_camera]->orientation);
change = true;
}
if (keys['d'])
{
scene.cameras[scene.active_camera]->position += 0.25f*ror3(vec3f(1.0, 0.0, 0.0), scene.cameras[scene.active_camera]->orientation);
change = true;
}
if (keys['q'])
{
scene.cameras[scene.active_camera]->position += -0.25f*ror3(vec3f(0.0, 1.0, 0.0), scene.cameras[scene.active_camera]->orientation);
change = true;
}
if (keys['e'])
{
scene.cameras[scene.active_camera]->position += 0.25f*ror3(vec3f(0.0, 1.0, 0.0), scene.cameras[scene.active_camera]->orientation);
change = true;
}
}
else if (scene.active_camera_valid() && scene.cameras[scene.active_camera]->focus != NULL)
{
if (keys['w'])
{
scene.cameras[scene.active_camera]->radius -= 0.25;
change = true;
}
if (keys['s'])
{
scene.cameras[scene.active_camera]->radius += 0.25;
change = true;
}
}
if (change)
glutPostRedisplay();
}
开发者ID:cornell-cs5620,项目名称:assignment1,代码行数:53,代码来源:main.cpp
示例4: init
void init(string working_directory)
{
for (int i = 0; i < 256; i++)
keys[i] = false;
canvas.working_directory = working_directory;
scene.canvas = &canvas;
scene.cameras.push_back(new frustumhdl());
scene.objects.push_back(new pyramidhdl(1.0, 1.0, 8));
for (int k = 0; k < scene.objects.back()->rigid.size(); k++)
for (int i = 0; i < scene.objects.back()->rigid[k].geometry.size(); i++)
{
swap(scene.objects.back()->rigid[k].geometry[i][1], scene.objects.back()->rigid[k].geometry[i][2]);
scene.objects.back()->rigid[k].geometry[i][1] *= -1.0;
swap(scene.objects.back()->rigid[k].geometry[i][4], scene.objects.back()->rigid[k].geometry[i][5]);
scene.objects.back()->rigid[k].geometry[i][4] *= -1.0;
}
swap(scene.objects.back()->bound[2], scene.objects.back()->bound[4]);
swap(scene.objects.back()->bound[3], scene.objects.back()->bound[5]);
scene.cameras.back()->model = scene.objects.back();
if (!scene.active_camera_valid())
{
scene.active_camera = scene.cameras.size()-1;
scene.cameras[scene.active_camera]->project(&canvas);
}
scene.cameras[scene.active_camera]->position[2] = 10.0;
}
开发者ID:cornell-cs5620,项目名称:assignment1,代码行数:28,代码来源:main.cpp
示例5: init
void init()
{
for (int i = 0; i < 256; i++)
keys[i] = false;
scene.cameras.push_back(new frustumhdl());
scene.objects.push_back(new pyramidhdl(1.0, 1.0, 8));
for (int k = 0; k < scene.objects.back()->rigid.size(); k++)
for (int i = 0; i < scene.objects.back()->rigid[k].geometry.size(); i++)
{
swap(scene.objects.back()->rigid[k].geometry[i][1], scene.objects.back()->rigid[k].geometry[i][2]);
scene.objects.back()->rigid[k].geometry[i][1] *= -1.0;
swap(scene.objects.back()->rigid[k].geometry[i][4], scene.objects.back()->rigid[k].geometry[i][5]);
scene.objects.back()->rigid[k].geometry[i][4] *= -1.0;
}
swap(scene.objects.back()->bound[2], scene.objects.back()->bound[4]);
swap(scene.objects.back()->bound[3], scene.objects.back()->bound[5]);
scene.cameras.back()->model = scene.objects.back();
if (!scene.active_camera_valid())
{
scene.active_camera = scene.cameras.size()-1;
scene.cameras[scene.active_camera]->project();
}
scene.cameras[scene.active_camera]->position[2] = 10.0;
glEnable(GL_DEPTH_TEST);
}
开发者ID:yuchien302,项目名称:skeleton,代码行数:28,代码来源:main.cpp
示例6: displayfunc
void displayfunc()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
scene.draw();
glutSwapBuffers();
}
开发者ID:yuchien302,项目名称:skeleton,代码行数:8,代码来源:main.cpp
示例7: displayfunc
void displayfunc()
{
canvas.clear_color_buffer();
canvas.clear_depth_buffer();
scene.draw();
canvas.swap_buffers();
}
开发者ID:cornell-cs5620,项目名称:assignment1,代码行数:9,代码来源:main.cpp
示例8: pmotionfunc
void pmotionfunc(int x, int y)
{
if (bound)
{
glutSetMenu(canvas_menu_id);
int deltax = x - mousex;
int deltay = y - mousey;
mousex = x;
mousey = y;
bool warp = false;
if (mousex > 3*canvas.get_width()/4 || mousex < canvas.get_width()/4)
{
mousex = canvas.get_width()/2;
warp = true;
}
if (mousey > 3*canvas.get_height()/4 || mousey < canvas.get_height()/4)
{
mousey = canvas.get_height()/2;
warp = true;
}
if (warp)
glutWarpPointer(mousex, mousey);
if (scene.active_camera_valid())
{
scene.cameras[scene.active_camera]->orientation[1] -= (float)deltax/500.0;
scene.cameras[scene.active_camera]->orientation[0] -= (float)deltay/500.0;
}
glutPostRedisplay();
}
else if (scene.active_camera_valid())
{
vec3f direction;
vec3f position;
if (scene.active_camera_valid())
{
if (scene.cameras[scene.active_camera]->type == "ortho")
{
position = canvas.unproject(canvas.to_window(vec2i(x, y)));
direction = ror3(vec3f(0.0f, 0.0f, 1.0f), scene.cameras[scene.active_camera]->orientation);
}
else
{
position = scene.cameras[scene.active_camera]->position;
direction = norm(canvas.unproject(canvas.to_window(vec2i(x, y))));
}
}
int old_active_object = scene.active_object;
scene.active_object = -1;
for (int i = 0; i < scene.objects.size(); i++)
{
if (scene.objects[i] != NULL && scene.cameras[scene.active_camera]->model != scene.objects[i])
{
bool is_light = false;
bool is_camera = false;
// TODO Assignment 3: uncomment this
//for (int j = 0; j < scene.lights.size() && !is_light; j++)
// if (scene.lights[j] != NULL && scene.lights[j]->model == scene.objects[i])
// is_light = true;
for (int j = 0; j < scene.cameras.size() && !is_camera; j++)
if (scene.cameras[j] != NULL && scene.cameras[j]->model == scene.objects[i])
is_camera = true;
if ((!is_light && !is_camera) || (is_light && scene.render_lights) || (is_camera && scene.render_cameras))
{
vec3f invdir = 1.0f/direction;
vec3i sign((int)(invdir[0] < 0), (int)(invdir[1] < 0), (int)(invdir[2] < 0));
vec3f origin = position - scene.objects[i]->position;
float tmin, tmax, tymin, tymax, tzmin, tzmax;
tmin = (scene.objects[i]->bound[0 + sign[0]]*scene.objects[i]->scale - origin[0])*invdir[0];
tmax = (scene.objects[i]->bound[0 + 1-sign[0]]*scene.objects[i]->scale - origin[0])*invdir[0];
tymin = (scene.objects[i]->bound[2 + sign[1]]*scene.objects[i]->scale - origin[1])*invdir[1];
tymax = (scene.objects[i]->bound[2 + 1-sign[1]]*scene.objects[i]->scale - origin[1])*invdir[1];
if ((tmin <= tymax) && (tymin <= tmax))
{
if (tymin > tmin)
tmin = tymin;
if (tymax < tmax)
tmax = tymax;
tzmin = (scene.objects[i]->bound[4 + sign[2]]*scene.objects[i]->scale - origin[2])*invdir[2];
tzmax = (scene.objects[i]->bound[4 + 1-sign[2]]*scene.objects[i]->scale - origin[2])*invdir[2];
if ((tmin <= tzmax) && (tzmin <= tmax))
{
scene.active_object = i;
i = scene.objects.size();
}
}
}
//.........这里部分代码省略.........
开发者ID:cornell-cs5620,项目名称:assignment1,代码行数:101,代码来源:main.cpp
示例9: object_menu
void object_menu(int num)
{
if (num == 0)
{
if (scene.active_object >= 0 && scene.active_object < scene.objects.size())
{
if (scene.objects[scene.active_object] != NULL)
{
// TODO Assignment 3: uncomment this
/*for (int i = 0; i < scene.lights.size(); )
{
if (scene.lights[i] != NULL && scene.lights[i]->model == scene.objects[scene.active_object])
{
delete scene.lights[i];
scene.lights.erase(scene.lights.begin() + i);
}
else
i++;
}*/
for (int i = 0; i < scene.cameras.size(); )
{
if (scene.cameras[i] != NULL && scene.cameras[i]->model == scene.objects[scene.active_object])
{
delete scene.cameras[i];
if (scene.active_camera > i)
scene.active_camera--;
scene.cameras.erase(scene.cameras.begin() + i);
}
else
i++;
}
delete scene.objects[scene.active_object];
}
scene.objects.erase(scene.objects.begin() + scene.active_object);
glutPostRedisplay();
}
}
else if (num == 4)
{
scene.active_camera = -1;
for (int i = 0; i < scene.cameras.size(); i++)
if (scene.cameras[i] != NULL && scene.active_object_valid() && scene.cameras[i]->model == scene.objects[scene.active_object])
scene.active_camera = i;
if (scene.active_camera_valid())
scene.cameras[scene.active_camera]->project(&canvas);
glutPostRedisplay();
}
else if (num == 1)
manipulator = manipulate::translate;
else if (num == 2)
manipulator = manipulate::rotate;
else if (num == 3)
manipulator = manipulate::scale;
else if (num == 5 && scene.active_object_valid() && scene.active_camera_valid())
{
scene.cameras[scene.active_camera]->focus = scene.objects[scene.active_object];
scene.cameras[scene.active_camera]->radius = dist(scene.objects[scene.active_object]->position, scene.cameras[scene.active_camera]->position);
}
// TODO Assignment 4: uncomment this
/*else if (num == 6 && scene.active_object_valid())
{
for (map<string, materialhdl*>::iterator i = scene.objects[scene.active_object]->material.begin(); i != scene.objects[scene.active_object]->material.end(); i++)
{
if (i->second != NULL)
delete i->second;
i->second = new texturehdl();
}
glutPostRedisplay();
}*/
// TODO Assignment 3: uncomment this
/*else if (num == 7 && scene.active_object_valid())
{
for (map<string, materialhdl*>::iterator i = scene.objects[scene.active_object]->material.begin(); i != scene.objects[scene.active_object]->material.end(); i++)
{
if (i->second != NULL)
delete i->second;
i->second = new customhdl();
}
glutPostRedisplay();
}
else if (num == 8 && scene.active_object_valid())
{
for (map<string, materialhdl*>::iterator i = scene.objects[scene.active_object]->material.begin(); i != scene.objects[scene.active_object]->material.end(); i++)
{
if (i->second != NULL)
delete i->second;
i->second = new phonghdl();
}
glutPostRedisplay();
}
else if (num == 9 && scene.active_object_valid())
{
for (map<string, materialhdl*>::iterator i = scene.objects[scene.active_object]->material.begin(); i != scene.objects[scene.active_object]->material.end(); i++)
{
if (i->second != NULL)
delete i->second;
i->second = new gouraudhdl();
//.........这里部分代码省略.........
开发者ID:cornell-cs5620,项目名称:assignment1,代码行数:101,代码来源:main.cpp
示例10: motionfunc
void motionfunc(int x, int y)
{
if (!bound && !menu)
{
int deltax = x - mousex;
int deltay = mousey - y;
mousex = x;
mousey = y;
vec3f direction;
vec3f position;
if (scene.active_camera_valid())
{
if (scene.cameras[scene.active_camera]->type == "ortho")
{
position = canvas.unproject(canvas.to_window(vec2i(x, y)));
direction = ror3(vec3f(0.0f, 0.0f, 1.0f), scene.cameras[scene.active_camera]->orientation);
}
else
{
position = scene.cameras[scene.active_camera]->position;
direction = norm(canvas.unproject(canvas.to_window(vec2i(x, y))));
}
}
if (scene.active_object_valid() && scene.active_camera_valid())
{
if (manipulator == manipulate::translate)
{
float d = mag(scene.objects[scene.active_object]->position - position);
scene.objects[scene.active_object]->position = d*direction + position;
}
else if (manipulator == manipulate::rotate)
scene.objects[scene.active_object]->orientation += vec3f(-(float)deltay/100.0, (float)deltax/100.0, 0.0);
else if (manipulator == manipulate::scale)
scene.objects[scene.active_object]->scale += (float)deltay/100.0;
for (int i = 0; i < scene.cameras.size(); i++)
if (scene.cameras[i]->model == scene.objects[scene.active_object])
{
scene.cameras[i]->position = scene.objects[scene.active_object]->position;
scene.cameras[i]->orientation = scene.objects[scene.active_object]->orientation;
}
}
if (scene.active_camera_valid())
{
if (manipulator == manipulate::fovy && scene.cameras[scene.active_camera]->type == "perspective")
((perspectivehdl*)scene.cameras[scene.active_camera])->fovy += (float)deltay/100.0;
else if (manipulator == manipulate::aspect && scene.cameras[scene.active_camera]->type == "perspective")
((perspectivehdl*)scene.cameras[scene.active_camera])->aspect += (float)deltay/100.0;
else if (manipulator == manipulate::width && scene.cameras[scene.active_camera]->type == "ortho")
{
((orthohdl*)scene.cameras[scene.active_camera])->right += (float)deltay/200.0;
((orthohdl*)scene.cameras[scene.active_camera])->left -= (float)deltay/200.0;
}
else if (manipulator == manipulate::width && scene.cameras[scene.active_camera]->type == "frustum")
{
((frustumhdl*)scene.cameras[scene.active_camera])->right += (float)deltay/200.0;
((frustumhdl*)scene.cameras[scene.active_camera])->left -= (float)deltay/200.0;
}
else if (manipulator == manipulate::height && scene.cameras[scene.active_camera]->type == "ortho")
{
((orthohdl*)scene.cameras[scene.active_camera])->top += (float)deltay/200.0;
((orthohdl*)scene.cameras[scene.active_camera])->bottom -= (float)deltay/200.0;
}
else if (manipulator == manipulate::height && scene.cameras[scene.active_camera]->type == "frustum")
{
((frustumhdl*)scene.cameras[scene.active_camera])->top += (float)deltay/200.0;
((frustumhdl*)scene.cameras[scene.active_camera])->bottom -= (float)deltay/200.0;
}
else if (manipulator == manipulate::front && scene.cameras[scene.active_camera]->type == "ortho")
((orthohdl*)scene.cameras[scene.active_camera])->front += (float)deltay/100.0;
else if (manipulator == manipulate::front && scene.cameras[scene.active_camera]->type == "frustum")
((frustumhdl*)scene.cameras[scene.active_camera])->front += (float)deltay/100.0;
else if (manipulator == manipulate::front && scene.cameras[scene.active_camera]->type == "perspective")
((perspectivehdl*)scene.cameras[scene.active_camera])->front += (float)deltay/100.0;
else if (manipulator == manipulate::back && scene.cameras[scene.active_camera]->type == "ortho")
((orthohdl*)scene.cameras[scene.active_camera])->back += (float)deltay/100.0;
else if (manipulator == manipulate::back && scene.cameras[scene.active_camera]->type == "frustum")
((frustumhdl*)scene.cameras[scene.active_camera])->back += (float)deltay/100.0;
else if (manipulator == manipulate::back && scene.cameras[scene.active_camera]->type == "perspective")
((perspectivehdl*)scene.cameras[scene.active_camera])->back += (float)deltay/100.0;
if (manipulator == manipulate::fovy ||
manipulator == manipulate::aspect ||
manipulator == manipulate::width ||
manipulator == manipulate::height ||
manipulator == manipulate::front ||
manipulator == manipulate::back)
scene.cameras[scene.active_camera]->project(&canvas);
}
glutPostRedisplay();
}
else if (!bound)
{
menu = false;
pmotionfunc(x, y);
//.........这里部分代码省略.........
开发者ID:cornell-cs5620,项目名称:assignment1,代码行数:101,代码来源:main.cpp
示例11: object_menu
void object_menu(int num)
{
if (num == 0)
{
if (scene.active_object >= 0 && scene.active_object < scene.objects.size())
{
if (scene.objects[scene.active_object] != NULL)
{
for (int i = 0; i < scene.lights.size(); )
{
if (scene.lights[i] != NULL && scene.lights[i]->model == scene.objects[scene.active_object])
{
delete scene.lights[i];
scene.lights.erase(scene.lights.begin() + i);
}
else
i++;
}
for (int i = 0; i < scene.cameras.size(); )
{
if (scene.cameras[i] != NULL && scene.cameras[i]->model == scene.objects[scene.active_object])
{
delete scene.cameras[i];
if (scene.active_camera > i)
scene.active_camera--;
scene.cameras.erase(scene.cameras.begin() + i);
}
else
i++;
}
delete scene.objects[scene.active_object];
}
scene.objects.erase(scene.objects.begin() + scene.active_object);
glutPostRedisplay();
}
}
else if (num == 4)
{
scene.active_camera = -1;
for (int i = 0; i < scene.cameras.size(); i++)
if (scene.cameras[i] != NULL && scene.active_object_valid() && scene.cameras[i]->model == scene.objects[scene.active_object])
scene.active_camera = i;
if (scene.active_camera_valid())
scene.cameras[scene.active_camera]->project();
glutPostRedisplay();
}
else if (num == 1)
manipulator = manipulate::translate;
else if (num == 2)
manipulator = manipulate::rotate;
else if (num == 3)
manipulator = manipulate::scale;
else if (num == 5 && scene.active_object_valid() && scene.active_camera_valid())
{
scene.cameras[scene.active_camera]->focus = scene.objects[scene.active_object];
scene.cameras[scene.active_camera]->radius = dist(scene.objects[scene.active_object]->position, scene.cameras[scene.active_camera]->position);
}
else if (num == 6 && scene.active_object_valid())
{
for (map<string, materialhdl*>::iterator i = scene.objects[scene.active_object]->material.begin(); i != scene.objects[scene.active_object]->material.end(); i++)
{
if (i->second != NULL)
delete i->second;
i->second = new texturehdl();
}
glutPostRedisplay();
}
else if (num == 7 && scene.active_object_valid())
{
for (map<string, materialhdl*>::iterator i = scene.objects[scene.active_object]->material.begin(); i != scene.objects[scene.active_object]->material.end(); i++)
{
if (i->second != NULL)
delete i->second;
i->second = new customhdl();
}
glutPostRedisplay();
}
else if (num == 8 && scene.active_object_valid())
{
for (map<string, materialhdl*>::iterator i = scene.objects[scene.active_object]->material.begin(); i != scene.objects[scene.active_object]->material.end(); i++)
{
if (i->second != NULL)
delete i->second;
i->second = new phonghdl();
}
glutPostRedisplay();
}
else if (num == 9 && scene.active_object_valid())
{
for (map<string, materialhdl*>::iterator i = scene.objects[scene.active_object]->material.begin(); i != scene.objects[scene.active_object]->material.end(); i++)
{
if (i->second != NULL)
delete i->second;
i->second = new gouraudhdl();
}
glutPostRedisplay();
}
//.........这里部分代码省略.........
开发者ID:yuchien302,项目名称:skeleton,代码行数:101,代码来源:main.cpp
示例12: motionfunc
void motionfunc(int x, int y)
{
if (!bound && !menu)
{
int deltax = x - mousex;
int deltay = mousey - y;
mousex = x;
mousey = y;
vec3f direction;
vec3f position;
if (scene.active_camera_valid())
{
if (scene.cameras[scene.active_camera]->type == "ortho")
{
GLdouble model[16];
GLdouble proj[16];
GLint view[4];
glGetDoublev(GL_MODELVIEW_MATRIX, model);
glGetDoublev(GL_PROJECTION_MATRIX, proj);
glGetIntegerv(GL_VIEWPORT, view);
vec<double, 3> p;
gluUnProject(x, height-y, 0.0, model, proj, view, &p[0], &p[1], &p[2]);
position = p;
direction = ror3(vec3f(0.0f, 0.0f, 1.0f), scene.cameras[scene.active_camera]->orientation);
}
else
{
GLdouble model[16];
GLdouble proj[16];
GLint view[4];
glGetDoublev(GL_MODELVIEW_MATRIX, model);
glGetDoublev(GL_PROJECTION_MATRIX, proj);
glGetIntegerv(GL_VIEWPORT, view);
vec<double, 3> p;
gluUnProject(x, height-y, 0.0, model, proj, view, &p[0], &p[1], &p[2]);
position = scene.cameras[scene.active_camera]->position;
direction = norm(p - position);
}
}
if (scene.active_object_valid() && scene.active_camera_valid())
{
if (manipulator == manipulate::translate)
{
float d = mag(scene.objects[scene.active_object]->position - position);
scene.objects[scene.active_object]->position = d*direction + position;
}
else if (manipulator == manipulate::rotate)
scene.objects[scene.active_object]->orientation += vec3f(-(float)deltay/100.0, (float)deltax/100.0, 0.0);
else if (manipulator == manipulate::scale)
scene.objects[scene.active_object]->scale += (float)deltay/100.0;
else if (manipulator == manipulate::stepsize)
{
scene.objects[scene.active_object]->minstep += (float)deltay/100.0;
if (scene.objects[scene.active_object]->minstep < 0.0)
scene.objects[scene.active_object]->minstep = 0.0;
}
for (int i = 0; i < scene.cameras.size(); i++)
if (scene.cameras[i]->model == scene.objects[scene.active_object])
{
scene.cameras[i]->position = scene.objects[scene.active_object]->position;
scene.cameras[i]->orientation = scene.objects[scene.active_object]->orientation;
}
}
if (scene.active_camera_valid())
{
if (manipulator == manipulate::fovy && scene.cameras[scene.active_camera]->type == "perspective")
((perspectivehdl*)scene.cameras[scene.active_camera])->fovy += (float)deltay/100.0;
else if (manipulator == manipulate::aspect && scene.cameras[scene.active_camera]->type == "perspective")
((perspectivehdl*)scene.cameras[scene.active_camera])->aspect += (float)deltay/100.0;
else if (manipulator == manipulate::width && scene.cameras[scene.active_camera]->type == "ortho")
{
((orthohdl*)scene.cameras[scene.active_camera])->right += (float)deltay/200.0;
((orthohdl*)scene.cameras[scene.active_camera])->left -= (float)deltay/200.0;
}
else if (manipulator == manipulate::width && scene.cameras[scene.active_camera]->type == "frustum")
{
((frustumhdl*)scene.cameras[scene.active_camera])->right += (float)deltay/200.0;
((frustumhdl*)scene.cameras[scene.active_camera])->left -= (float)deltay/200.0;
}
else if (manipulator == manipulate::height && scene.cameras[scene.active_camera]->type == "ortho")
{
((orthohdl*)scene.cameras[scene.active_camera])->top += (float)deltay/200.0;
((orthohdl*)scene.cameras[scene.active_camera])->bottom -= (float)deltay/200.0;
}
else if (manipulator == manipulate::height && scene.cameras[scene.active_camera]->type == "frustum")
{
((frustumhdl*)scene.cameras[scene.active_camera])->top += (float)deltay/200.0;
((frustumhdl*)scene.cameras[scene.active_camera])->bottom -= (float)deltay/200.0;
}
else if (manipulator == manipulate::front && scene.cameras[scene.active_camera]->type == "ortho")
((orthohdl*)scene.cameras[scene.active_camera])->front += (float)deltay/100.0;
else if (manipulator == manipulate::front && scene.cameras[scene.active_camera]->type == "frustum")
((frustumhdl*)scene.cameras[scene.active_camera])->front += (float)deltay/100.0;
else if (manipulator == manipulate::front && scene.cameras[scene.active_camera]->type == "perspective")
((perspectivehdl*)scene.cameras[scene.active_camera])->front += (float)deltay/100.0;
//.........这里部分代码省略.........
开发者ID:yuchien302,项目名称:skeleton,代码行数:101,代码来源:main.cpp
示例13: pmotionfunc
void pmotionfunc(int x, int y)
{
if (bound)
{
glutSetMenu(canvas_menu_id);
int deltax = x - mousex;
int deltay = y - mousey;
mousex = x;
mousey = y;
bool set_warp = false;
if (mousex > 3*width/4 || mousex < width/4)
{
mousex = width/2;
set_warp = true;
}
if (mousey > 3*height/4 || mousey < height/4)
{
mousey = height/2;
set_warp = true;
}
if (!set_warp)
warp = false;
if (scene.active_camera_valid() && !warp)
{
scene.cameras[scene.active_camera]->orientation[1] -= (float)deltax/500.0;
scene.cameras[scene.active_camera]->orientation[0] -= (float)deltay/500.0;
}
if (set_warp)
{
glutWarpPointer(mousex, mousey);
warp = true;
}
glutPostRedisplay();
}
else if (scene.active_camera_valid())
{
vec3f direction;
vec3f position;
if (scene.cameras[scene.active_camera]->type == "ortho")
{
GLdouble model[16];
GLdouble proj[16];
GLint view[4];
glGetDoublev(GL_MODELVIEW_MATRIX, model);
glGetDoublev(GL_PROJECTION_MATRIX, proj);
glGetIntegerv(GL_VIEWPORT, view);
vec<double, 3> p;
gluUnProject(x, height-y, 0.0f, model, proj, view, &p[0], &p[1], &p[2]);
position = p;
direction = ror3(vec3f(0.0f, 0.0f, 1.0f), scene.cameras[scene.active_camera]->orientation);
}
else
{
GLdouble model[16];
GLdouble proj[16];
GLint view[4];
glGetDoublev(GL_MODELVIEW_MATRIX, model);
glGetDoublev(GL_PROJECTION_MATRIX, proj);
glGetIntegerv(GL_VIEWPORT, view);
vec<double, 3> p;
gluUnProject(x, height-y, 0.0f, model, proj, view, &p[0], &p[1], &p[2]);
position = scene.cameras[scene.active_camera]->position;
direction = norm(p - position);
}
int old_active_object = scene.active_object;
scene.active_object = -1;
for (int i = 0; i < scene.objects.size(); i++)
{
if (scene.objects[i] != NULL && scene.cameras[scene.active_camera]->model != scene.objects[i])
{
bool is_light = false;
bool is_camera = false;
for (int j = 0; j < scene.lights.size() && !is_light; j++)
if (scene.lights[j] != NULL && scene.lights[j]->model == scene.objects[i])
is_light = true;
for (int j = 0; j < scene.cameras.size() && !is_camera; j++)
if (scene.cameras[j] != NULL && scene.cameras[j]->model == scene.objects[i])
is_camera = true;
if ((!is_light && !is_camera) || (is_light && scene.render_lights) || (is_camera && scene.render_cameras))
{
vec3f invdir = 1.0f/direction;
vec3i sign((int)(invdir[0] < 0), (int)(invdir[1] < 0), (int)(invdir[2] < 0));
vec3f origin = position - scene.objects[i]->position;
float tmin, tmax, tymin, tymax, tzmin, tzmax;
tmin = (scene.objects[i]->bound[0 + sign[0]]*scene.objects[i]->scale - origin[0])*invdir[0];
tmax = (scene.objects[i]->bound[0 + 1-sign[0]]*scene.objects[i]->scale - origin[0])*invdir[0];
tymin = (scene.objects[i]->bound[2 + sign[1]]*scene.objects[i]->scale - origin[1])*invdir[1];
//.........这里部分代码省略.........
开发者ID:yuchien302,项目名称:skeleton,代码行数:101,代码来源:main.cpp
注:本文中的scenehdl类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论