我正在尝试用点云显示OpenGL.
我已经遵循了一些教程,并设法显示一些几何模式但是当我尝试显示从csv文件中读取的点云时,它不起作用.阅读文件工作得很好.
包括
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <stdlib.h>
#include <stdio.h>
#include <boost/tokenizer.hpp>
#include <sstream>
#include <vector>
#include <SDL/SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <algorithm>
#include "Point.cpp"
#include "drawing.cpp"
using namespace std;
Run Code Online (Sandbox Code Playgroud)
声明
void draw(vector<Point> v);
int pointsNBR = 200;
char *theFileName;
Run Code Online (Sandbox Code Playgroud)
主要方法
int main (int argc, char** argv) {
if(argv[1]){
theFileName = argv[1];
}else{
cout << "Please enter the file name !!\n";
exit(0);
}
if(argv[2]){
pointsNBR = atoi(argv[2]);
}
PCEngine(theFileName, pointsNBR);
SDL_Init(SDL_INIT_VIDEO);
atexit(SDL_Quit);
SDL_WM_SetCaption("Point Cloud", NULL);
SDL_SetVideoMode(720,640, 32, SDL_OPENGL);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70,(double)640/480,1,1000);
bool continuer = true;
SDL_Event event;
vector<Point> v = getCloudPoint(theFileName);
draw(v);
for (;;) {
SDL_WaitEvent(&event);
switch(event.type){
case SDL_QUIT:
exit(0);
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
绘制方法
void draw(vector<Point> v){
glPushAttrib(GL_ALL_ATTRIB_BITS);
glPushMatrix();
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluLookAt(3,4,2,0,0,0,0,0,1);
glPointSize(2.0);
glBegin(GL_POINTS);
for (size_t n = 0; n < v.size(); n++){
glColor3ub(v[n].r, v[n].g, v[n].b);
glVertex3d(v[n].x, v[n].y, v[n].z);
}
glEnd();
glFlush();
SDL_GL_SwapBuffers();
glPopMatrix();
glPopAttrib();
}
Run Code Online (Sandbox Code Playgroud)
我的问题是我没有任何显示.
有谁可以帮助我吗?
您应该使用GL_MODELVIEW来将云定位在场景中。
在绘制方法中更改glMatrixMode(GL_PROJECTION);为glMatrixMode(GL_MODELVIEW);
| 归档时间: |
|
| 查看次数: |
14613 次 |
| 最近记录: |