void RandomModel::surfacesAndEdges(double margin[2], double bH[2], double bL[2], double bInterval[2]) { double totalLength = -bInterval[1]; // 道路右侧情况,x>0 while (totalLength <= this->length) { double x0 = (width / 2) + this->randomNum(margin); double y0 = totalLength + this->randomNum(bInterval); double z0 = this->randomNum(bH); Point p0(x0, y0, z0); // 面 double length = this->randomNum(bL); Surface s = this->surfaceProduce(p0, length, this->materials); s.init(); this->surfaces.push_back(s); // 刃形,p2p0,p1p3 Point p1 = s.getP1(); Point p2 = s.getP2(); Point p3 = s.getP3(); Point pb0(p0.x + BUILDING_WIDTH, p0.y, p0.z); Point pb1(p3.x + BUILDING_WIDTH, p3.y, p3.z); Edge e0(p2, p0, pb0, p3); Edge e1(p1, p3, pb1, p0); this->edges.push_back(e0); this->edges.push_back(e1); totalLength = y0 + length ; } // 道路左侧情况,x<0 totalLength = -bInterval[1]; while (totalLength <= this->length) { double x0 = -((width / 2) + this->randomNum(margin)); double y0 = totalLength + this->randomNum(bInterval); double z0 = this->randomNum(bH); Point p0(x0, y0, z0); // 面 double length = this->randomNum(bL); Surface s = this->surfaceProduce(p0, length, this->materials); s.init(); this->surfaces.push_back(s); // 刃形,p2p0,p1p3 Point p1 = s.getP1(); Point p2 = s.getP2(); Point p3 = s.getP3(); Point pb0(p0.x - BUILDING_WIDTH, p0.y, p0.z); Point pb1(p3.x - BUILDING_WIDTH, p3.y, p3.z); Edge e0(p2, p0, pb0, p3); Edge e1(p1, p3, pb1, p0); this->edges.push_back(e0); this->edges.push_back(e1); totalLength = y0 + length; } }
void create_data(Eigen::MatrixXd &pa, Eigen::MatrixXd &pb) { int n_data = 7; Eigen::MatrixXd pa0(3, n_data); Eigen::MatrixXd pb0(3, n_data); pb0 << -0.7045189014502934,0.31652495664145264,-0.8913587885243552,0.4196143278053829,0.33125081405575785,-1.148712511573519,-0.7211957446166447,-0.4204243223315903,-0.8922857301575797,0.41556308950696674,-0.36760757371251074,-1.1630155401570457,-0.12535642300333297,0.26708755761917147,1.5095344824450356,0.9968448409012386,0.27593113974268946,1.2189108175890786,-0.28095118914331707,-0.40276257201497045,1.3669272703783852; Eigen::Quaterniond q = Eigen::Quaterniond(2.86073, 0.0378363, 3.59752, 0.4211619).normalized(); std::cout << "groundtruth-quaternion. w: " << q.w() << " x " << q.x() << " y: " << q.y() << " z " << q.z() << std::endl; pa = q.toRotationMatrix()*pb0; pb = pb0; }
void Scarry::drawtra(wardraw_t *wd){ st::drawtra(wd); Scarry *p = this; Scarry *pt = this; Mat4d mat; Vec3d pa, pb, pa0(.01, 0, 0), pb0(-.01, 0, 0); double scale; /* if(scarry_cull(pt, wd)) return;*/ if(wd->vw->gc->cullFrustum(pos, getHitRadius())) return; scale = fabs(wd->vw->gc->scale(this->pos)); transform(mat); const double blastscale = .04; drawCapitalBlast(wd, Vec3d(0, 0, .55), blastscale); drawCapitalBlast(wd, Vec3d(.08, .08, .55), blastscale); drawCapitalBlast(wd, Vec3d(-.08, .08, .55), blastscale); drawCapitalBlast(wd, Vec3d(-.08, -.08, .55), blastscale); drawCapitalBlast(wd, Vec3d(.08, -.08, .55), blastscale); pa = pt->rot.trans(pa0); pa += pt->pos; pb = pt->rot.trans(pb0); pb += pt->pos; glColor4ub(255,255,9,255); glBegin(GL_LINES); glVertex3dv(pa); glVertex3dv(pb); glEnd(); { int i; static const avec3_t lights[] = { {0, 520 * SCARRY_SCALE, 220 * SCARRY_SCALE}, {0, -520 * SCARRY_SCALE, 220 * SCARRY_SCALE}, {140 * SCARRY_SCALE, 370 * SCARRY_SCALE, 220 * SCARRY_SCALE}, {-140 * SCARRY_SCALE, 370 * SCARRY_SCALE, 220 * SCARRY_SCALE}, {140 * SCARRY_SCALE, -370 * SCARRY_SCALE, 220 * SCARRY_SCALE}, {-140 * SCARRY_SCALE, -370 * SCARRY_SCALE, 220 * SCARRY_SCALE}, {100 * SCARRY_SCALE, -360 * SCARRY_SCALE, -600 * SCARRY_SCALE}, {100 * SCARRY_SCALE, 360 * SCARRY_SCALE, -600 * SCARRY_SCALE}, { 280 * SCARRY_SCALE, 20 * SCARRY_SCALE, 520 * SCARRY_SCALE}, { 280 * SCARRY_SCALE, -20 * SCARRY_SCALE, 520 * SCARRY_SCALE}, {-280 * SCARRY_SCALE, 20 * SCARRY_SCALE, 520 * SCARRY_SCALE}, {-280 * SCARRY_SCALE, -20 * SCARRY_SCALE, 520 * SCARRY_SCALE}, {-280 * SCARRY_SCALE, 20 * SCARRY_SCALE, -300 * SCARRY_SCALE}, {-280 * SCARRY_SCALE, -20 * SCARRY_SCALE, -300 * SCARRY_SCALE}, { 280 * SCARRY_SCALE, 20 * SCARRY_SCALE, -480 * SCARRY_SCALE}, { 280 * SCARRY_SCALE, -20 * SCARRY_SCALE, -480 * SCARRY_SCALE}, }; avec3_t pos; double rad = .01; double t; GLubyte col[4] = {255, 31, 31, 255}; random_sequence rs; init_rseq(&rs, (unsigned long)this); /* color calculation of static navlights */ t = fmod(wd->vw->viewtime + drseq(&rs) * 2., 2.); if(t < 1.){ rad *= (t + 1.) / 2.; col[3] *= t; } else{ rad *= (2. - t + 1.) / 2.; col[3] *= 2. - t; } for(i = 0 ; i < numof(lights); i++){ mat4vp3(pos, mat, lights[i]); gldSpriteGlow(pos, rad, col, wd->vw->irot); } /* runway lights */ if(1 < scale * .01){ col[0] = 0; col[1] = 191; col[2] = 255; for(i = 0 ; i <= 10; i++){ avec3_t pos0; pos0[0] = -160 * SCARRY_SCALE; pos0[1] = 20 * SCARRY_SCALE + .0025; pos0[2] = (i * -460 + (10 - i) * -960) * SCARRY_SCALE / 10; rad = .005 * (1. - fmod(i / 10. + t / 2., 1.)); col[3] = 255/*rad * 255 / .01*/; mat4vp3(pos, mat, pos0); gldSpriteGlow(pos, rad, col, wd->vw->irot); pos0[0] = -40 * SCARRY_SCALE; mat4vp3(pos, mat, pos0); gldSpriteGlow(pos, rad, col, wd->vw->irot); pos0[1] = -20 * SCARRY_SCALE - .0025; mat4vp3(pos, mat, pos0); gldSpriteGlow(pos, rad, col, wd->vw->irot); pos0[0] = -160 * SCARRY_SCALE; mat4vp3(pos, mat, pos0); gldSpriteGlow(pos, rad, col, wd->vw->irot); } } /* for(i = 0; i < numof(p->turrets); i++) mturret_drawtra(&p->turrets[i], pt, wd);*/ } static int init = 0; static suftex_t *pst; static suf_t *sufbase = NULL; if(init == 0) do{ init = 1; sufbase = CallLoadSUF("models/spacecarrier.bin"); } while(0); if(sufbase){ static const double normal[3] = {0., 1., 0.}; double scale = SCARRY_SCALE; static const GLdouble rotaxis[16] = { -1,0,0,0, 0,1,0,0, 0,0,-1,0, 0,0,0,1, }; Mat4d mat; glPushAttrib(GL_TEXTURE_BIT | GL_LIGHTING_BIT | GL_CURRENT_BIT | GL_ENABLE_BIT); glEnable(GL_CULL_FACE); glPushMatrix(); transform(mat); glMultMatrixd(mat); extern GLuint screentex; glBindTexture(GL_TEXTURE_2D, screentex); glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE); glColor4f(1.,1.,1.,1.); glDisable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); Mat4d modelview, proj; glGetDoublev(GL_MODELVIEW_MATRIX, modelview); glGetDoublev(GL_PROJECTION_MATRIX, proj); Mat4d trans = proj * modelview; texture((glPushMatrix(), glScaled(1./2., 1./2., 1.), glTranslated(1, 1, 0), glMultMatrixd(trans) )); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGendv(GL_S, GL_EYE_PLANE, Vec4d(.9,0,0,0)); glEnable(GL_TEXTURE_GEN_S); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGendv(GL_T, GL_EYE_PLANE, Vec4d(0,.9,0,0)); glEnable(GL_TEXTURE_GEN_T); glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGendv(GL_R, GL_EYE_PLANE, Vec4d(0,0,.9,0)); glEnable(GL_TEXTURE_GEN_R); glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGeniv(GL_Q, GL_EYE_PLANE, Vec4<int>(0,0,0,1)); glEnable(GL_TEXTURE_GEN_Q); glPushMatrix(); glScaled(-scale, scale, -scale); DrawSUF(sufbase, 0, NULL); glPopMatrix(); texture((glPopMatrix())); glPopMatrix(); glPopAttrib(); } }
void Shipyard::drawtra(wardraw_t *wd){ st::drawtra(wd); Shipyard *p = this; Shipyard *pt = this; Mat4d mat; Vec3d pa, pb, pa0(10., 0, 0), pb0(-10., 0, 0); double scale; /* if(scarry_cull(pt, wd)) return;*/ if(wd->vw->gc->cullFrustum(pos, getHitRadius())) return; scale = fabs(wd->vw->gc->scale(this->pos)); transform(mat); pa = pt->rot.trans(pa0); pa += pt->pos; pb = pt->rot.trans(pb0); pb += pt->pos; glColor4ub(255,255,9,255); glBegin(GL_LINES); glVertex3dv(pa); glVertex3dv(pb); glEnd(); { random_sequence rs; init_rseq(&rs, (unsigned long)this); double t0 = drseq(&rs); drawNavlights(wd, navlights, &mat); if(undockingFrigate){ double t = fmod(wd->vw->viewtime + t0, 2.); /* runway lights */ if(1 < scale * .01){ Vec3d pos; GLubyte col[4]; col[0] = 0; col[1] = 191; col[2] = 255; for(int i = 0 ; i <= 10; i++){ avec3_t pos0; pos0[0] = 180 * modelScale; pos0[1] = 60 * modelScale; pos0[2] = (i * -460 + (10 - i) * -960) * modelScale / 10; double rad = 5. * (1. - fmod(i / 10. + t / 2., 1.)); col[3] = 255/*rad * 255 / .01*/; mat4vp3(pos, mat, pos0); gldSpriteGlow(pos, rad, col, wd->vw->irot); pos0[0] = 20 * modelScale; mat4vp3(pos, mat, pos0); gldSpriteGlow(pos, rad, col, wd->vw->irot); pos0[1] = -60 * modelScale; mat4vp3(pos, mat, pos0); gldSpriteGlow(pos, rad, col, wd->vw->irot); pos0[0] = 180 * modelScale; mat4vp3(pos, mat, pos0); gldSpriteGlow(pos, rad, col, wd->vw->irot); } } } /* for(i = 0; i < numof(p->turrets); i++) mturret_drawtra(&p->turrets[i], pt, wd);*/ } }