//will add points along exsisting edges and make new faces from them void geo_sphere::subdivide_geosphere(int res){ int e = n_tri(res); if(gs_sphere_start[res]+e>(int)gstris.size())return; for(int i = 0; i<e; i++){ int p1 = gstris[gs_sphere_start[res] + i].point[0]; int p2 = gstris[gs_sphere_start[res] + i].point[1]; int p3= gstris[gs_sphere_start[res] + i].point[2]; vector3d v1 = gspoints[p1]; vector3d v2 = gspoints[p2]; vector3d v3 = gspoints[p3]; //adding two vectors makes a scalar multiple of of there average //normaliseing them will project them onto the unit sphere int p12 = add_if_not_present(MakeUnitVector(v1+v2)); int p23 = add_if_not_present(MakeUnitVector(v2+v3)); int p31 = add_if_not_present(MakeUnitVector(v3+v1)); gstris.push_back(stri(p1,p12,p31)); gstris.push_back(stri(p2,p23,p12)); gstris.push_back(stri(p3,p31,p23)); gstris.push_back(stri(p12,p23,p31)); } }
inline void PointTo(const Vector3 & from, const Vector3 & pointTo) { X = pointTo.X - from.X; Y = pointTo.Y - from.Y; Z = pointTo.Z - from.Z; MakeUnitVector(); }
// Construct a change of basis from e1,e2,e3 to the given vector matrix::matrix(vector3d basis) { basis = MakeUnitVector(basis); for (int j = 0; j < MATRIX_SIZE; j++) { a2d[0][j] = basis[j]; } vector3d temp (1,0,0); temp = temp - dot(temp,basis) / dot(basis,basis) * basis; if (temp == vector3d(0,0,0)) { temp = vector3d(0,1,0); // shouldn't be necessary... temp = temp - dot(temp,basis) / dot(basis,basis) * basis; } temp = MakeUnitVector(temp); for (int j = 0; j < MATRIX_SIZE; j++) { a2d[1][j] = temp[j]; } temp = MakeUnitVector(CrossProduct(basis,temp)); for (int j = 0; j < MATRIX_SIZE; j++) { a2d[2][j] = temp[j]; } }
void wxGL_PMFCanvas::ray_cast(int mx, int my, vector3d&start, vector3d&dir){ wxSize size = GetClientSize(); float x = float(mx); float y = float(size.y-my); double M[16], P[16]; int v[4]; glGetDoublev(GL_MODELVIEW_MATRIX, M); glGetDoublev(GL_PROJECTION_MATRIX, P); glGetIntegerv(GL_VIEWPORT, v); double ret[3]; gluUnProject(x, y, 0.0f, M, P, v, &ret[0], &ret[1], &ret[2]); start.x = ret[0]; start.y = ret[1]; start.z = ret[2]; gluUnProject(x, y, 1.0f, M, P, v, &ret[0], &ret[1], &ret[2]); dir.x = ret[0]; dir.y = ret[1]; dir.z = ret[2]; dir = MakeUnitVector(dir-start); }