本文整理汇总了C++中scenehdl::active_camera_valid方法的典型用法代码示例。如果您正苦于以下问题:C++ scenehdl::active_camera_valid方法的具体用法?C++ scenehdl::active_camera_valid怎么用?C++ scenehdl::active_camera_valid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scenehdl
的用法示例。
在下文中一共展示了scenehdl::active_camera_valid方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
}
示例2: 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;
}
示例3: 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);
}
示例4: 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();
}
}
}
//.........这里部分代码省略.........
示例5: 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();
//.........这里部分代码省略.........
示例6: canvas_menu
void canvas_menu(int num)
{
if (num == 0)
exit(0);
else if (num == 1)
scene.objects.push_back(new boxhdl(1.0, 1.0, 1.0));
else if (num == 2)
scene.objects.push_back(new cylinderhdl(1.0, 1.0, 20));
else if (num == 3)
scene.objects.push_back(new spherehdl(1.0, 10, 20));
else if (num == 4)
scene.objects.push_back(new pyramidhdl(1.0, 1.0, 20));
else if (num == 5)
{
const char* filters[1];
filters[0] = "*.obj";
const char *path = tinyfd_openFileDialog("Load a Model", "", 1, filters, 0);
if (path != NULL && strlen(path) > 0)
scene.objects.push_back(new modelhdl(path));
}
// TODO Assignment 3: uncomment this
/*else if (num == 6)
scene.render_lights = !scene.render_lights;
else if (num == 7)
{
scene.lights.push_back(new directionalhdl());
scene.objects.push_back(new cylinderhdl(0.25, 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.lights.back()->model = scene.objects.back();
}
else if (num == 8)
{
scene.lights.push_back(new pointhdl());
scene.objects.push_back(new spherehdl(0.25, 4, 8));
scene.lights.back()->model = scene.objects.back();
}
else if (num == 9)
{
scene.lights.push_back(new spothdl());
scene.objects.push_back(new pyramidhdl(0.25, 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.lights.back()->model = scene.objects.back();
}*/
else if (num == 10)
manipulator = manipulate::fovy;
else if (num == 11)
manipulator = manipulate::aspect;
else if (num == 12)
manipulator = manipulate::width;
else if (num == 13)
manipulator = manipulate::height;
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)
//.........这里部分代码省略.........
示例7: 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);
//.........这里部分代码省略.........
示例8: 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();
}
//.........这里部分代码省略.........
示例9: canvas_menu
void canvas_menu(int num)
{
if (num == 0)
exit(0);
else if (num == 1)
scene.objects.push_back(new boxhdl(1.0, 1.0, 1.0));
else if (num == 2)
scene.objects.push_back(new cylinderhdl(1.0, 1.0, 20));
else if (num == 3)
scene.objects.push_back(new spherehdl(1.0, 10, 20));
else if (num == 4)
scene.objects.push_back(new pyramidhdl(1.0, 1.0, 20));
else if (num == 5)
{
const char* filters[2];
filters[0] = "*.obj";
filters[1] = "*.wrl";
const char *path = tinyfd_openFileDialog("Load a Model", "", 2, filters, 0);
if (path != NULL && path[0] != '\0')
{
string pathstr = path;
scene.objects.push_back(new modelhdl(path));
}
}
else if (num == 6)
scene.render_lights = !scene.render_lights;
else if (num == 7)
{
scene.lights.push_back(new directionalhdl());
scene.objects.push_back(new cylinderhdl(0.25, 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.lights.back()->model = scene.objects.back();
}
else if (num == 8)
{
scene.lights.push_back(new pointhdl());
scene.objects.push_back(new spherehdl(0.25, 4, 8));
scene.lights.back()->model = scene.objects.back();
}
else if (num == 9)
{
scene.lights.push_back(new spothdl());
scene.objects.push_back(new pyramidhdl(0.25, 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.lights.back()->model = scene.objects.back();
}
else if (num == 10)
manipulator = manipulate::fovy;
else if (num == 11)
manipulator = manipulate::aspect;
else if (num == 12)
manipulator = manipulate::width;
else if (num == 13)
manipulator = manipulate::height;
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();
//.........这里部分代码省略.........
示例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")
{
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;
//.........这里部分代码省略.........
示例11: 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];
//.........这里部分代码省略.........