本文整理汇总了C++中scenehdl::active_object_valid方法的典型用法代码示例。如果您正苦于以下问题:C++ scenehdl::active_object_valid方法的具体用法?C++ scenehdl::active_object_valid怎么用?C++ scenehdl::active_object_valid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scenehdl
的用法示例。
在下文中一共展示了scenehdl::active_object_valid方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pmotionfunc
//.........这里部分代码省略.........
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();
}
}
}
}
}
if (scene.active_object != old_active_object)
{
bool is_light = false;
bool is_camera = false;
// TODO Assignment 3: uncomment this
//for (int i = 0; i < scene.lights.size() && !is_light; i++)
// if (scene.lights[i] != NULL && scene.active_object_valid() && scene.lights[i]->model == scene.objects[scene.active_object])
// is_light = true;
for (int i = 0; i < scene.cameras.size() && !is_camera; i++)
if (scene.cameras[i] != NULL && scene.active_object_valid() && scene.cameras[i]->model == scene.objects[scene.active_object])
is_camera = true;
glutDetachMenu(GLUT_RIGHT_BUTTON);
if (scene.active_object == -1)
glutSetMenu(canvas_menu_id);
else if (is_light)
glutSetMenu(light_menu_id);
else if (is_camera)
glutSetMenu(camera_menu_id);
else
glutSetMenu(object_menu_id);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutPostRedisplay();
}
}
}
示例2: 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();
//.........这里部分代码省略.........
示例3: 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);
//.........这里部分代码省略.........
示例4: 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();
}
//.........这里部分代码省略.........
示例5: 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;
//.........这里部分代码省略.........
示例6: pmotionfunc
//.........这里部分代码省略.........
{
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];
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();
}
}
}
}
}
if (scene.active_object != old_active_object)
{
bool is_light = false;
bool is_camera = false;
for (int i = 0; i < scene.lights.size() && !is_light; i++)
if (scene.lights[i] != NULL && scene.active_object_valid() && scene.lights[i]->model == scene.objects[scene.active_object])
is_light = true;
for (int i = 0; i < scene.cameras.size() && !is_camera; i++)
if (scene.cameras[i] != NULL && scene.active_object_valid() && scene.cameras[i]->model == scene.objects[scene.active_object])
is_camera = true;
glutDetachMenu(GLUT_RIGHT_BUTTON);
if (scene.active_object == -1)
glutSetMenu(canvas_menu_id);
else if (is_light)
glutSetMenu(light_menu_id);
else if (is_camera)
glutSetMenu(camera_menu_id);
else
glutSetMenu(object_menu_id);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutPostRedisplay();
}
}
}