chunkstream version fixedleaselication
git-svn-id: svn://db.shs.com.ru/libs@3 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -29,6 +29,16 @@ void GLPrimitivePoint::draw(bool simplest) {
|
||||
|
||||
|
||||
|
||||
void GLPrimitiveLine::draw(bool simplest) {
|
||||
glColor3f(material_.color_diffuse.redF(), material_.color_diffuse.greenF(), material_.color_diffuse.blueF());
|
||||
glBegin(GL_LINES);
|
||||
glVertex3d(p0.x(), p0.y(), p0.z());
|
||||
glVertex3d(p1.x(), p1.y(), p1.z());
|
||||
glEnd();
|
||||
}
|
||||
|
||||
|
||||
|
||||
GLPrimitiveCube::GLPrimitiveCube(double width, double length, double height, QVector3D pos): GLObjectBase() {
|
||||
geom_prim = Quads;
|
||||
w = width;
|
||||
@@ -101,3 +111,75 @@ void GLPrimitiveCube::init() {
|
||||
is_init = true;
|
||||
vbo.rebuffer();
|
||||
}
|
||||
|
||||
|
||||
GLPrimitiveEllipsoid::GLPrimitiveEllipsoid(double width, double length, double height, int seg_wl, int seg_h, QVector3D pos) {
|
||||
geom_prim = GLObjectBase::Triangles;
|
||||
w = width;
|
||||
l = length;
|
||||
h = height;
|
||||
swl = seg_wl;
|
||||
sh = seg_h;
|
||||
moveTo(pos);
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
void GLPrimitiveEllipsoid::putTriangle(const QVector3D & v0, const QVector3D & v1, const QVector3D & v2) {
|
||||
vbo.vertices() << v0.x() << v0.y() << v0.z() << v1.x() << v1.y() << v1.z() << v2.x() << v2.y() << v2.z();
|
||||
QVector3D n = QVector3D::normal(v1 - v0, v2 - v0);
|
||||
for (int i = 0; i < 3; ++i)
|
||||
vbo.normals() << n.x() << n.y() << n.z();
|
||||
return;
|
||||
QVector3D s(w, l, h);
|
||||
n = (v0 * s).normalized(); vbo.normals() << n.x() << n.y() << n.z();
|
||||
n = (v1 * s).normalized(); vbo.normals() << n.x() << n.y() << n.z();
|
||||
n = (v2 * s).normalized(); vbo.normals() << n.x() << n.y() << n.z();
|
||||
}
|
||||
|
||||
|
||||
void GLPrimitiveEllipsoid::init() {
|
||||
QVector<QVector3D> points;
|
||||
vbo.clear();
|
||||
vbo.init();
|
||||
|
||||
int ret = 0, hseg = sh + 1, wlseg = swl + 1;
|
||||
double crw, crl, a, ch, twl;
|
||||
QVector3D cp(0., 0., -h / 2.);
|
||||
points << cp;
|
||||
for (int i = 1; i < hseg; i++) {
|
||||
ch = -cos((double)i / hseg * M_PI);
|
||||
cp.setZ(ch * h / 2.);
|
||||
twl = sqrt(1. - ch * ch) / 2.;
|
||||
crw = twl * w;
|
||||
crl = twl * l;
|
||||
for (int j = 0; j < wlseg * 2; j++) {
|
||||
a = (double)j / wlseg * M_PI;
|
||||
cp.setY(crw * sin(a));
|
||||
cp.setX(crl * cos(a));
|
||||
points << cp;
|
||||
ret = points.size() - 1;
|
||||
if (i == 1)
|
||||
if (j > 0) putTriangle(points[0], points[ret], points[ret - 1]);
|
||||
if (j > 0) {
|
||||
if (i > 1) {
|
||||
putTriangle(points[ret - wlseg * 2 - 1], points[ret], points[ret - 1]);
|
||||
putTriangle(points[ret - wlseg * 2], points[ret], points[ret - wlseg * 2 - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i == 1) putTriangle(points[0], points[ret - wlseg * 2 + 1], points[ret]);
|
||||
else {
|
||||
putTriangle(points[ret - wlseg * 2 + 1], points[ret], points[ret - wlseg * 2]);
|
||||
putTriangle(points[ret - wlseg * 2 + 1], points[ret - wlseg * 2], points[ret - wlseg * 4 + 1]);
|
||||
}
|
||||
}
|
||||
points << QVector3D(0., 0., h / 2.);
|
||||
ret = points.size() - 1;
|
||||
putTriangle(points[ret - 1], points[ret - wlseg * 2], points[ret]);
|
||||
for (int j = 1; j < wlseg * 2; j++)
|
||||
if (j > 0) putTriangle(points[ret - wlseg * 2 + j - 1], points[ret - wlseg * 2 + j], points[ret]);
|
||||
|
||||
is_init = true;
|
||||
vbo.rebuffer();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user