- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有以下代码:
#define GLUT_DISABLE_ATEXIT_HACK
#include <GL/glut.h>
#include <GL/gl.h>
#include <math.h>
#include <stdio.h>
GLfloat ctrlptsBezier[4][4][3] =
{
{
{-2.0, -2.0, 1.0},
{-0.5, -2.0, 0.0},
{0.5, -2.0, 0.0},
{2.0, -2.0, 1.0}},
{
{-2, -0.5, -1.0},
{-0.5, -0.5, 0.0},
{0.5, -0.5, 0.0},
{2.0, -0.5, 0.0}},
{
{-2, 0.5, 0.0},
{-0.5, 0.5, -2.0},
{0.5, 0.5, 0.0},
{2.0, 0.5, 0.0}},
{
{-2.0, 2.0, 1.0},
{-0.5, 2.0, 0.0},
{0.5, 2.0, 0.0},
{2.0, 2.0, 1.0}}
};
int uSteps = 30;
int vSteps = 30;
bool shade = false;
GLfloat black [] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat blue[] = { 0.0, 0.0, 1.0, 1.0 };
GLfloat green[] = { 0.0, 1.0, 0.0, 1.0 };
GLfloat peach[] = { 1.0, 0.5, 0.5, 1.0 };
GLfloat purple[] = { 0.5, 0.0, 0.5, 1.0 };
GLfloat red[] = { 1.0, 0.0, 0.0, 1.0 };
GLfloat white[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat yellow[] = { 1.0, 1.0, 0.0, 1.0 };
//Initial eye/viewpoint coords.
double xPos = -20.0, zPos = -20.0;
double eyeHeight = 4.5;
double eyeIncline = -0.5;
double theta = 0.0; //Rotation angle in rads
//Movement params (camera)
double posIncr = 0.25;
double thetaIncr = 0.1;
#define BUFSIZE 512 //Pick buffer size
void setObjLight( bool s )
{
int shadeNumber = GL_FLAT;
if ( shade == true )
shadeNumber = GL_SMOOTH;
glShadeModel(shadeNumber);
}
void setLights(void)
{
setObjLight(shade);
}
void drawRoom(void)
{
GLfloat floor_color[] = { 0.5, 0.5, 0.5, 1.0 }; //Grey floor
GLfloat blue_wall[] = { 0.0, 0.0, 1.0, 1.0 };
GLfloat green_wall[] = { 0.0, 1.0, 0.0, 1.0 };
GLfloat purple_wall[] = { 0.5, 0.0, 0.5, 1.0 };
//FLOOR
glMaterialfv(GL_FRONT, GL_DIFFUSE, floor_color);
glBegin(GL_POLYGON);
glNormal3f(0.0, 1.0, 0.0);
glVertex3f(-25.0, 0.0, -25.0);
glVertex3f( 25.0, 0.0, -25.0);
glVertex3f( 25.0, 0.0, 25.0);
glVertex3f(-25.0, 0.0, 25.0);
glEnd();
//WALLS
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, blue_wall);
glPushMatrix();
glTranslatef(0.0, 0.0, 25.0);
glBegin(GL_POLYGON);
glNormal3f(0.0, 1.0, 0.0);
glVertex3f(-25.0,-25.0,0.0);
glVertex3f(25,-25.0,0);
glVertex3f(25, 25, 0);
glVertex3f(-25, 25, 0);
glEnd();
glPopMatrix();
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, green_wall);
glPushMatrix();
glTranslatef(0.0, 0.0, -25.0);
glBegin(GL_POLYGON);
glNormal3f(0.0, 1.0, 0.0);
glVertex3f(-25.0,-25.0,0.0);
glVertex3f(25,-25.0,0);
glVertex3f(25, 25, 0);
glVertex3f(-25, 25, 0);
glEnd();
glPopMatrix();
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, purple_wall);
glPushMatrix();
glTranslatef(25.0, 0.0, 0.0);
glRotatef(90.0, 0.0, 1.0, 0.0);
glBegin(GL_POLYGON);
glNormal3f(0.0, 1.0, 0.0);
glVertex3f(-25.0,-25.0,0.0);
glVertex3f(25,-25.0,0);
glVertex3f(25, 25, 0);
glVertex3f(-25, 25, 0);
glEnd();
glPopMatrix();
}
void drawShapes()
{
//SPHERE
glPushMatrix();
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, blue);
glNormal3f(0.0, 1.0, 0.0);
glTranslatef(0.0, 2.0, 0.0);
glLoadName(1);
glutSolidSphere (2.0, 20, 16);
glPopMatrix();
glFlush();
//CONE
glPushMatrix();
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, purple);
glNormal3f(0.0, 1.0, 0.0);
glTranslatef(5.0, 0.0, 0.0);
glRotatef(-90.0, 1.0, 0.0, 0.0);
glLoadName(2);
glutSolidCone (2.0, 3, 20, 16);
glPopMatrix();
glFlush();
glLoadName(0);
}
void drawBezier()
{
glEnable(GL_MAP2_VERTEX_3);
glPushMatrix();
glTranslatef(10, 2, 15);
glMaterialfv(GL_FRONT, GL_DIFFUSE, white);
glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &ctrlptsBezier[0][0][0]);
glMapGrid2f(uSteps, 0.0, 1.0, vSteps, 0.0, 1.0);
glEvalMesh2(GL_FILL, 0, uSteps, 0, vSteps);
glPopMatrix();
glPushMatrix();
glTranslatef(13, 2, 18);
glRotatef(-90, 0.0, 1.0, 0.0);
glMaterialfv(GL_FRONT, GL_DIFFUSE, red);
glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &ctrlptsBezier[0][0][0]);
glMapGrid2f(uSteps, 0.0, 1.0, vSteps, 0.0, 1.0);
glEvalMesh2(GL_FILL, 0, uSteps, 0, vSteps);
glPopMatrix();
glPushMatrix();
glTranslatef(7, 2, 18);
glRotatef(90, 0.0, 1.0, 0.0);
glMaterialfv(GL_FRONT, GL_DIFFUSE, yellow);
glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &ctrlptsBezier[0][0][0]);
glMapGrid2f(uSteps, 0.0, 1.0, vSteps, 0.0, 1.0);
glEvalMesh2(GL_FILL, 0, uSteps, 0, vSteps);
glPopMatrix();
glPushMatrix();
glTranslatef(10, 2, 21);
glRotatef(180, 0.0, 1.0, 0.0);
glMaterialfv(GL_FRONT, GL_DIFFUSE, peach);
glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &ctrlptsBezier[0][0][0]);
glMapGrid2f(uSteps, 0.0, 1.0, vSteps, 0.0, 1.0);
glEvalMesh2(GL_FILL, 0, uSteps, 0, vSteps);
glPopMatrix();
glPushMatrix();
glTranslatef(10, 5, 18);
glRotatef(90.0, 1.0, 0.0, 0.0);
glMaterialfv(GL_FRONT, GL_DIFFUSE, black);
glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &ctrlptsBezier[0][0][0]);
glMapGrid2f(uSteps, 0.0, 1.0, vSteps, 0.0, 1.0);
glEvalMesh2(GL_FILL, 0, uSteps, 0, vSteps);
glPopMatrix();
//Sphere for filler
glPushMatrix();
glTranslatef(10, 2, 18);
glRotatef(90.0, 1.0, 0.0, 0.0);
glMaterialfv(GL_FRONT, GL_DIFFUSE, white);
glutSolidSphere(3.0, 20, 16);
glPopMatrix();
glFlush();
}
void drawScene(void)
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
double atx = xPos + cos(theta);
double atz = zPos + sin(theta);
double atHeight = eyeHeight + eyeIncline;
gluLookAt(xPos, eyeHeight, zPos, atx, atHeight, atz, 0.0, 1.0, 0.0);
glPushMatrix();
setLights();
drawRoom();
drawShapes();
glLoadName(3);
drawBezier();
glPopMatrix();
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
drawScene();
glutSwapBuffers();
}
void setProjection(void)
{
gluPerspective(60.0, 1.0, 0.1, 100.0);
}
void init(void)
{
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHT0);
glDepthFunc(GL_LEQUAL);
glEnable(GL_LIGHTING);
glEnable(GL_FLAT); //Flat shading initially
glShadeModel(GL_FLAT);
//LIGHTING
GLfloat specular[]= {1.0, 1.0, 1.0, 1.0};
GLfloat diffuse[]= {1.0, 1.0, 1.0, 1.0};
GLfloat ambient[]= {1.0, 1.0, 1.0, 1.0};
GLfloat shininess= {100.0};
GLfloat light_ambient[]= {0.0, 0.0, 0.0, 1.0};
GLfloat light_diffuse[]= {1.0, 1.0, 1.0, 1.0};
GLfloat light_specular[]= {1.0, 1.0, 1.0, 1.0};
GLfloat light_position[]= {10.0, 10.0, 10.0, 0.0};
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
glMaterialf(GL_FRONT, GL_SHININESS, shininess);
// /LIGHTING
glEnable(GL_NORMALIZE);
glClearColor (0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
}
void specialKey(int k, int x, int y) //Camera movement commands with arrow keys
{
switch (k) {
case GLUT_KEY_UP:
xPos += posIncr * cos(theta);
zPos += posIncr * sin(theta);
break;
case GLUT_KEY_DOWN:
xPos -= posIncr * cos(theta);
zPos -= posIncr * sin(theta);
break;
case GLUT_KEY_LEFT:
theta -= thetaIncr;
break;
case GLUT_KEY_RIGHT:
theta += thetaIncr;
break;
case GLUT_KEY_PAGE_UP:
eyeIncline += 0.5;
break;
case GLUT_KEY_PAGE_DOWN:
eyeIncline -= 0.5;
break;
case GLUT_KEY_HOME:
eyeHeight += 0.5;
break;
case GLUT_KEY_END:
eyeHeight -= 0.5;
break;
default:
return;
}
glutPostRedisplay();
}
void key(unsigned char k, int x, int y)
{
if ( k == 27 ) //ESC to close
exit(0);
glutPostRedisplay();
}
void processHits(GLint hits, GLuint buffer[])
{
unsigned int j;
GLuint names, *ptr;
float z1, z2;
printf ("hits = %d\n", hits);
ptr = (GLuint *) buffer;
shade = !shade;
setLights();
glutPostRedisplay();
for (int i = 0; i < hits; i++)
{ /* for each hit */
names = *ptr;
printf (" number of names for hit = %d\n", names); ptr++;
z1 = (float) *ptr/0x7fffffff; ptr++;
z2 = (float) *ptr/0x7fffffff; ptr++;
printf(" z1 is %g;",z1);
printf(" z2 is %g\n", z2);
printf (" the name is ");
for (j = 0; j < names; j++) { /* for each name */
printf ("%d ", *ptr); ptr++;
}
printf ("\n");
}
}
void pick( int button, int state, int x, int y )
{
GLuint selectBuf[BUFSIZE];
GLint hits;
GLint viewport[4];
if (button != GLUT_LEFT_BUTTON || state != GLUT_DOWN) {
return;
}
glSelectBuffer(BUFSIZE, selectBuf);
glRenderMode(GL_SELECT);
glPushMatrix();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glGetIntegerv(GL_VIEWPORT, viewport);
gluPickMatrix ((GLdouble) x, (GLdouble) (viewport[3] - y), 5.0, 5.0, viewport); //5x5 pixel area around the mouse for selecting
gluPerspective(75, 1.0, 0.1, 100); //NEED
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glInitNames();
glPushName(0);
drawScene();
glPopMatrix();
glFlush();
hits = glRenderMode(GL_RENDER); //# of hits assigned
processHits(hits, selectBuf);
}
void reshape(int w, int h){
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(75, w/h,1,150);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutCreateWindow("Room");
init();
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutSpecialFunc(specialKey);
glutReshapeFunc(reshape);
glutMouseFunc(pick);
glutMainLoop();
return 0;
}
请原谅我的长度。我正在尝试挑选工作,以便我可以一次选择一个对象来处理。根据我的打印输出,它的功能与我预期的一样,除了一个障碍:当你选择一个物体时,你最终会非常放大,基本上在所选形状内。我已经梳理了我的代码,并做了一些更改/调试工作,但我找不到问题所在。谁能指出正确的方向,说明为什么采摘会出现这种奇怪的行为?
最佳答案
您的函数 pick
使用 gluperspective
更改投影矩阵(以放大拾取区域),但无法恢复之前的矩阵状态:可以轻松修复在矩阵 GL_PROJECTION
模式下,用一组 glPushMatrix
和 glPopMatrix
包装函数的绘图部分。
void pick( int button, int state, int x, int y )
{
GLuint selectBuf[BUFSIZE];
GLint hits;
GLint viewport[4];
if (button != GLUT_LEFT_BUTTON || state != GLUT_DOWN) {
return;
}
glSelectBuffer(BUFSIZE, selectBuf);
glRenderMode(GL_SELECT);
glPushMatrix();
glMatrixMode(GL_PROJECTION);
glPushMatrix(); // save projection settings
glLoadIdentity();
glGetIntegerv(GL_VIEWPORT, viewport);
gluPickMatrix ((GLdouble) x, (GLdouble) (viewport[3] - y), 5.0, 5.0, viewport); //5x5 pixel area around the mouse for selecting
gluPerspective(75, 1.0, 0.1, 100); //NEED
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glInitNames();
glPushName(0);
drawScene();
// restore previous projection settings
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glFlush();
关于c - 为什么我总是在选择时放大? (OpenGL),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27177819/
是否有某种方法可以使用 JPA 或 Hibernate Crtiteria API 来表示这种 SQL?或者我应该将其作为 native 执行吗? SELECT A.X FROM (SELECT X,
在查询中, select id,name,feature,marks from (....) 我想删除其 id 在另一个 select 语句中存在的那些。 从 (...) 中选择 id 我是 sql
我想响应用户在 select 元素中选择一个项目。然而这个 jQuery: $('#platypusDropDown').select(function () { alert('You sel
这个问题在这里已经有了答案: SQL select only rows with max value on a column [duplicate] (27 个回答) 关闭8年前。 我正在学习 SQL
This question already has answers here: “Notice: Undefined variable”, “Notice: Undefined index”, and
我在 php 脚本中调用 SQL。有时“DE”中没有值,如果是这种情况我想从“EN”中获取值 应该是这样的,但不是这样的 IF (EXISTS (SELECT epf_application_deta
这可能是一个奇怪的问题,但不知道如何研究它。执行以下查询时: SELECT Foo.col1, Foo.col2, Foo.col3 FROM Foo INNER JOIN Bar ON
如何在使用 Camera.DestinationType.FILE_URI. 时在 phonegap camera API 中同时选择或拾取多个图像我能够一次只选择一张图像。我可以使用 this 在
这是一个纯粹的学术问题。这两个陈述实际上是否相同? IF EXISTS (SELECT TOP 1 1 FROM Table1) SELECT 1 ELSE SELECT 0 相对 IF EXIS
我使用 JSoup 来解析 HTML 响应。我有多个 Div 标签。我必须根据 ID 选择 Div 标签。 我的伪代码是这样的 Document divTag = Jsoup.connect(link
我正在处理一个具有多个选择框的表单。当用户从 selectbox1 中选择一个选项时,我需要 selectbox2 active 的另一个值。同样,当他选择 selectbox2 的另一个值时,我需要
Acme Inc. Christa Woods Charlotte Freeman Jeffrey Walton Ella Hubbard Se
我有一个login.html其中form定义如下: First Initial Plus Last Name : 我的do_authorize如下: "; pri
$.get( 'http://www.ufilme.ro/api/load/maron_online/470', function(data
我有一个下拉列表“磅”、“克”、“千克”和“盎司”。我想要这样一种情况,当我选择 gram 来执行一个函数时,当我在输入字段中输入一个值时,当我选择 pounds 时,我想要另一个函数来执行时我在输入
我有一个 GLSL 着色器,它从输入纹理的 channel 之一(例如 R)读取,然后写入输出纹理中的同一 channel 。该 channel 必须由用户选择。 我现在能想到的就是使用一个 int
我想根据下拉列表中的选定值生成输入文本框。 Options 2 3 4 5 就在这个选择框之后,一些输入字段应该按照选定的数字出现。 最佳答案 我建议您使用响应式(Reac
我是 SQL 新手,我想问一下如何根据首选项和分组选择条目。 +----------+----------+------+ | ENTRY_ID | ROUTE_ID | TYPE | +------
我有以下表结构: CREATE TABLE [dbo].[UTS_USERCLIENT_MAPPING_USER_LIST] ( [MAPPING_ID] [int] IDENTITY(1,1
我在移除不必要的床单时遇到了问题。我查看了不同的论坛并将不同的解决方案混合在一起。 此宏删除工作表(第一张工作表除外)。 Sub wrong() Dim sht As Object Applicati
我是一名优秀的程序员,十分优秀!