git-svn-id: svn://db.shs.com.ru/libs@1 a8b55f48-bf90-11e4-a774-851b48703e85
104 lines
3.1 KiB
C++
104 lines
3.1 KiB
C++
/*
|
|
QGLView
|
|
Copyright (C) 2012 Ivan Pelipenko peri4ko@gmail.com
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "glprimitives.h"
|
|
|
|
|
|
void GLPrimitivePoint::draw(bool simplest) {
|
|
glPointSize(sz);
|
|
glColor3f(material_.color_diffuse.redF(), material_.color_diffuse.greenF(), material_.color_diffuse.blueF());
|
|
glBegin(GL_POINTS);
|
|
glVertex3d(0., 0., 0.);
|
|
glEnd();
|
|
}
|
|
|
|
|
|
|
|
GLPrimitiveCube::GLPrimitiveCube(double width, double length, double height, QVector3D pos): GLObjectBase() {
|
|
geom_prim = Quads;
|
|
w = width;
|
|
l = length;
|
|
h = height;
|
|
moveTo(pos);
|
|
init();
|
|
}
|
|
|
|
|
|
void GLPrimitiveCube::init() {
|
|
double hw = w / 2., hl = l / 2., hh = h / 2.;
|
|
//list = glGenLists(1);
|
|
//glNewList(list, GL_COMPILE);
|
|
//glColor4d(material_.color_diffuse.redF(), material_.color_diffuse.greenF(), material_.color_diffuse.blueF(), material_.color_diffuse.alphaF());
|
|
vbo.init();
|
|
QVector<GLfloat> & d_vertices(vbo.vertices()), & d_normals(vbo.normals()), & d_uvs(vbo.texcoords());
|
|
d_vertices.clear();
|
|
d_normals.clear();
|
|
d_uvs.clear();
|
|
|
|
for (int i = 0; i < 4; ++i)
|
|
d_normals << 0. << -1. << 0.;
|
|
d_vertices << -hw << -hl << -hh;
|
|
d_vertices << hw << -hl << -hh;
|
|
d_vertices << hw << -hl << hh;
|
|
d_vertices << -hw << -hl << hh;
|
|
d_uvs << 0. << 0. << 1. << 0. << 1. << 1. << 0. << 1.;
|
|
|
|
for (int i = 0; i < 4; ++i)
|
|
d_normals << 0. << 1. << 0.;
|
|
d_vertices << -hw << hl << -hh;
|
|
d_vertices << -hw << hl << hh;
|
|
d_vertices << hw << hl << hh;
|
|
d_vertices << hw << hl << -hh;
|
|
d_uvs << 0. << 0. << 1. << 0. << 1. << 1. << 0. << 1.;
|
|
|
|
for (int i = 0; i < 4; ++i)
|
|
d_normals << -1. << 0. << 0.;
|
|
d_vertices << -hw << -hl << -hh;
|
|
d_vertices << -hw << -hl << hh;
|
|
d_vertices << -hw << hl << hh;
|
|
d_vertices << -hw << hl << -hh;
|
|
d_uvs << 0. << 0. << 1. << 0. << 1. << 1. << 0. << 1.;
|
|
|
|
for (int i = 0; i < 4; ++i)
|
|
d_normals << 1. << 0. << 0.;
|
|
d_vertices << hw << -hl << -hh;
|
|
d_vertices << hw << hl << -hh;
|
|
d_vertices << hw << hl << hh;
|
|
d_vertices << hw << -hl << hh;
|
|
d_uvs << 0. << 0. << 1. << 0. << 1. << 1. << 0. << 1.;
|
|
|
|
for (int i = 0; i < 4; ++i)
|
|
d_normals << 0. << 0. << -1.;
|
|
d_vertices << -hw << -hl << -hh;
|
|
d_vertices << -hw << hl << -hh;
|
|
d_vertices << hw << hl << -hh;
|
|
d_vertices << hw << -hl << -hh;
|
|
d_uvs << 0. << 0. << 1. << 0. << 1. << 1. << 0. << 1.;
|
|
|
|
for (int i = 0; i < 4; ++i)
|
|
d_normals << 0. << 0. << 1.;
|
|
d_vertices << -hw << -hl << hh;
|
|
d_vertices << hw << -hl << hh;
|
|
d_vertices << hw << hl << hh;
|
|
d_vertices << -hw << hl << hh;
|
|
d_uvs << 0. << 0. << 1. << 0. << 1. << 1. << 0. << 1.;
|
|
|
|
is_init = true;
|
|
vbo.rebuffer();
|
|
}
|