Ejemplo n.º 1
0
void setRay() {
    vert = vec3(0, 1, 0);
    hori = vert ^ dir;

    dir  =  dir.normalize();
    vert = vert.normalize();
    hori = hori.normalize();

    hori = hori * ( dir.length() * Tan(Fangle/2) / (Rw/2) );
    vert = vert * ( dir.length() * Tan(Fangle/2) / (Rh/2) );
    dir  =  dir - Rw/2 * hori + Rh/2 * vert;
    ///cout << dir[0] << ", " << dir[1] << ", " << dir[2] << endl;
}
Ejemplo n.º 2
0
void EarthquakeApp::setup()
{
	gl::Texture earthDiffuse	= gl::Texture( loadImage( loadResource( RES_EARTHDIFFUSE ) ) );
	gl::Texture earthNormal		= gl::Texture( loadImage( loadResource( RES_EARTHNORMAL ) ) );
	gl::Texture earthMask		= gl::Texture( loadImage( loadResource( RES_EARTHMASK ) ) );
	earthDiffuse.setWrap( GL_REPEAT, GL_REPEAT );
	earthNormal.setWrap( GL_REPEAT, GL_REPEAT );
	earthMask.setWrap( GL_REPEAT, GL_REPEAT );

	mStars						= gl::Texture( loadImage( loadResource( RES_STARS_PNG ) ) );

	
	mEarthShader = gl::GlslProg( loadResource( RES_PASSTHRU_VERT ), loadResource( RES_EARTH_FRAG ) );
	mQuakeShader = gl::GlslProg( loadResource( RES_QUAKE_VERT ), loadResource( RES_QUAKE_FRAG ) );

	
	mCounter		= 0.0f;
	mCurrentFrame	= 0;
	mSaveFrames		= false;
	mShowEarth		= true;
	mShowText		= true;
	mShowQuakes		= true;
	mLightDir		= vec3( 0.025f, 0.25f, 1.0f );
	mLightDir.normalize();
	mPov			= POV( this, ci::vec3( 0.0f, 0.0f, 1000.0f ), ci::vec3( 0.0f, 0.0f, 0.0f ) );
	mEarth			= Earth( earthDiffuse, earthNormal, earthMask );
	
	parseEarthquakes( "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.geojson" );
	
	mEarth.setQuakeLocTip();
}
Ejemplo n.º 3
0
bool triangle3<T>::is_front_facing(const vec3<T>& lookDirection) const
{
	const vec3<T> n = get_normal();
	n.normalize();
	const T d = dot(n, lookDirection);
	return F32_LOWER_EQUAL_0(d);
}
Ejemplo n.º 4
0
vec3 randomCirclePoint(vec3 normal) {
	//generate random sphere points and then change the z components so that the
	//points are perpendicular to the normal
	normal.normalize();
	vec3 point = randomSpherePoint();
	point[2] = -(point[0]*normal[0] + point[1]*normal[1]) / normal[2];
	return point;
}
Ejemplo n.º 5
0
Triangle::Triangle(vec3 v1,vec3 v2, vec3 v3, vec3 n1, vec3 n2, vec3 n3, Material material, Transformation& transformation) {
    this->transform = transformation.transform;
    this->transformI = transformation.transformI;
    this->transformTI = transformation.transformTI;

    this->v1 = v1;
    this->v2 = v2;
    this->v3 = v3;

    this->material = material;

    this->isSphere=false;

    this->n1 = n1.normalize();
    this->n2 = n2.normalize();
    this->n3 = n3.normalize();
}
Ejemplo n.º 6
0
void	draw_stuff(const controls& c, float density)
{
	float	mx = c.m_mouse_x - 500.0f;
	float	my = 500.0f - c.m_mouse_y;
	vec3	mouse_pos(mx, my, 0);

	if (c.m_mouse_right)
	{
		// Re-compute light direction.
		s_light_direction = mouse_pos - s_light_arrow_spot;
		s_light_direction.normalize();

		// Direction perpendicular to the light.
		s_light_right = vec3(s_light_direction.y, -s_light_direction.x, 0);

		// Draw a white line to the mouse, so the user can see
		// what they're orbiting around.
		glColor3f(1, 1, 1);
		draw_segment(s_light_arrow_spot, mouse_pos);
	}

	if (c.m_mouse_left_click)
	{
		// Add or delete an occluder.

		// If we're on an occluder, then delete it.
		bool	deleted = false;
		for (int i = 0; i < s_occluders.size(); i++)
		{
			if (s_occluders[i].hit(mouse_pos))
			{
				// Remove this guy.
				s_occluders[i] = s_occluders.back();
				s_occluders.resize(s_occluders.size() - 1);
				deleted = true;
				break;
			}
		}

		if (!deleted)
		{
			// If we didn't delete, then the user want to
			// add an occluder.
			s_occluders.push_back(occluder(mouse_pos, 20));
		}
	}

	draw_light_arrow();
	draw_light_rays(density);
	draw_occluders();

	// Draw a line at the "near clip plane".
	glColor3f(0, 0, 1);
	draw_segment(vec3(-1000, s_viewer_y, 0), vec3(1000, s_viewer_y, 0));

	draw_frustum();
}
Ejemplo n.º 7
0
 color sample(PosNormal point)
 {
     vec3 n = point.n;
     n.normalize();
     direction.normalize();
     float k = n.x*direction.x + n.y*direction.y + n.z*direction.z;
     k = k < 0.0f ? 0.0f : k;
     return{ col.r*k, col.g*k, col.b*k, 1.0f };
 }
Ejemplo n.º 8
0
void Model::Rotate( float angle, vec3 vector) {
	vector.normalize();
	float d=sqrt(vector.y*vector.y+vector.z*vector.z);
	Matrix m1, m2, m3, m4;
	m1.init(), m2.init(), m3.init(), m4.init();

	if(d>=1e-10) {
		m4.mat[5]=vector.z/d;
		m4.mat[6]=vector.y/d;
		m4.mat[9]=-vector.y/d;
		m4.mat[10]=vector.z/d;
		m3.mat[0]=d;
		m3.mat[2]=vector.x;
		m3.mat[8]=-vector.x;
		m3.mat[10]=d;
		m1.mat[5]=m4.mat[5];
		m1.mat[6]=-m4.mat[6];
		m1.mat[9]=-m4.mat[9];
		m1.mat[10]=m4.mat[10];
		m2.mat[0]=m3.mat[0];
		m2.mat[2]=-m3.mat[2];
		m2.mat[8]=-m3.mat[8];
		m2.mat[10]=m3.mat[10];
		m3.MultiMatrix(m4);
		m1.MultiMatrix(m2);
		m2.init();
		m2.mat[0]=cos(angle);
		m2.mat[4]=-sin(angle);
		m2.mat[1]=sin(angle);
		m2.mat[5]=cos(angle);
		m1.MultiMatrix(m2);
		m1.MultiMatrix(m3);
		md_mat.MultiMatrix(m1);
	}

	else {
		m3.mat[0]=d;
		m3.mat[2]=vector.x;
		m3.mat[8]=-vector.x;
		m3.mat[10]=d;

		m1.mat[0]=m3.mat[0];
		m1.mat[2]=-m3.mat[2];
		m1.mat[8]=-m3.mat[8];
		m1.mat[10]=m3.mat[10];

		m2.mat[0]=cos(angle);
		m2.mat[4]=-sin(angle);
		m2.mat[1]=sin(angle);
		m2.mat[5]=cos(angle);

		m1.MultiMatrix(m2);
		m1.MultiMatrix(m3);
		md_mat.MultiMatrix(m1);
	}
}
Ejemplo n.º 9
0
//--------------------------------------------------------------------------------
// get target look at
//--------------------------------------------------------------------------------
bool zz_camera_follow::get_target_dir (vec3& dir)
{
	if (!target_) {
		dir.set(0, 1, 0);
		return false;
	}
	dir = target_->get_look_at();
	dir.normalize();
	return true;
}
Ejemplo n.º 10
0
// Multiplying a quaternion q with a vector v applies the q-rotation to v
vec3 tgQuaternion::operator* (vec3 v){
	v.normalize();
 
	tgQuaternion vecQuat, resQuat;
	vecQuat.x = v.x;
	vecQuat.y = v.y;
	vecQuat.z = v.z;
	vecQuat.w = 0.0f;
 
	resQuat = vecQuat * getConjugate();
	resQuat = *this * resQuat;
 
	return (vec3(resQuat.x, resQuat.y, resQuat.z));
}
Ejemplo n.º 11
0
void
tgPose::RotateAxis (vec3 r)
{
  // 	tgQuaternion q2;
  // 	q2.fromEuler(rot.x,rot.y,rot.z);
  // 	q = q2 * q;
  // 	q.normalise();
  tgQuaternion q2;
  float a = r.length ();
  r.normalize ();
  q2.fromAxis (r, a);
  q = q2 * q;
  q.normalise ();
}
Ejemplo n.º 12
0
// Use Rodriques formula
mat3 getRotationMatrix(vec3 axis, double angle)
{
	mat3 R = mat3(vec3(1,0,0),vec3(0,1,0),vec3(0,0,1));
	axis = axis.normalize();
	for (int i = 0; i < 3; ++i)
	{
		vec3 currCol = R.col(i);
		//currCol = (currCol * cos(angle)) + (mAxis.cross(currCol) * sin(angle)) + (Mat(mAxis_t * currCol).at<double>(0,0) * (1 - cos(angle)) * mAxis);
		currCol = (currCol * cos(angle)) + ((axis ^ currCol) * sin(angle)) + ((axis * currCol) * (1 - cos(angle)) * axis);
		R[0][i] = currCol[0];
		R[1][i] = currCol[1];
		R[2][i] = currCol[2];
	}
	return R;
}
Ejemplo n.º 13
0
void mat4::createRotation(vec3 axis, float rad)
{
	axis.normalize();

	float cosine = cos(rad);
	float sine = sin(rad);

	elements[0] = cosine + pow(axis.x, 2)*(1-cosine);
	elements[1] = axis.x*axis.y*(1 - cosine) - axis.z*sine;
	elements[2] = axis.x*axis.z*(1 - cosine) + axis.y*sine;
	elements[4] = axis.y*axis.x*(1 - cosine) + axis.z*sine;
	elements[5] = cosine + pow(axis.y, 2)*(1 - cosine);
	elements[6] = axis.z*axis.y*(1 - cosine) - axis.x*sine;
	elements[8] = axis.x*axis.z*(1 - cosine) - axis.y*sine;
	elements[9] = axis.z*axis.y*(1 - cosine) + axis.x*sine;
	elements[10] = cosine + pow(axis.z, 2)*(1 - cosine);
	elements[15] = 1.0f;
}
Ejemplo n.º 14
0
bool World::intersect(Ray & r, double & bestT, vec3 &outn, MaterialInfo &outm) {
	double thisT;
	Ray w2mRay;
	bestT = numeric_limits<double>::infinity();
	for (vector<Sphere>::iterator it = _spheres.begin();it != _spheres.end();it++) {
		w2mRay = Ray(r);
		w2mRay.transform(it->w2m());
		thisT = it->intersect(w2mRay);
		if (thisT<bestT && thisT>=0){
			vec4 p = w2mRay.getPos(thisT);
			outn = vec3(it->w2m().transpose() * it->calculateNormal(p),VW);
			outn.normalize();
			outm = it->getMaterial();
			bestT = thisT;
		}
	}
				
	return bestT < numeric_limits<double>::infinity();
}
Ejemplo n.º 15
0
mat33 getMatrix(vec3 vec, double alpha)
{
    mat33 res;

    mat33 I;
    for(int i=0;i<3;++i){
        for(int j=0;j<3;++j){
            I(i,j)=(i==j)?1.0:.0;
        }
    }

    vec.normalize();
    mat33 E=crossProductMat(vec);
    //print(E);
    //print(I);
    //std::cout<<vec.transpose()<<"\n";
    res=cos(alpha)*I+(1-cos(alpha))*vec*vec.transpose()-sin(alpha)*E;
    return res;
}
Ejemplo n.º 16
0
/////////////////////////////////////////////////////////////////////
// get the closest point to pt in the primative
bool
sphere::
closestPtIn ( vec3& dest, ValueType xval, ValueType yval, ValueType zval ) const
{
	if ( isEmpty () )
		return false;

	if ( contains ( xval, yval, zval ) )
		dest.set ( xval, yval, zval );
	else
	{
		dest.set ( xval, yval, zval );
		dest -= center;
		dest.normalize ();
		dest *= radius;
		dest += center;
	}
	
	return true;
}
Ejemplo n.º 17
0
		mat4 rotation3Drad(vec3& Axis, const double angleRad) {
			double   c = cos(angleRad),
				s = sin(angleRad),
				t = 1.0 - c;

			Axis.normalize();
			return mat4(vec4(t * Axis[VX] * Axis[VX] + c,
					t * Axis[VX] * Axis[VY] - s * Axis[VZ],
					t * Axis[VX] * Axis[VZ] + s * Axis[VY],
					0.0),
				vec4(t * Axis[VX] * Axis[VY] + s * Axis[VZ],
					t * Axis[VY] * Axis[VY] + c,
					t * Axis[VY] * Axis[VZ] - s * Axis[VX],
					0.0),
				vec4(t * Axis[VX] * Axis[VZ] - s * Axis[VY],
					t * Axis[VY] * Axis[VZ] + s * Axis[VX],
					t * Axis[VZ] * Axis[VZ] + c,
					0.0),
				vec4(0.0, 0.0, 0.0, 1.0));
		}
void getRayFromMouse(vec2 mouse, vec3 &start, vec3 &dir) {
	int viewport[4];
	double modelview[16], projection[16];

	glGetIntegerv(GL_VIEWPORT, viewport);			// Retrieves The Viewport Values (X, Y, Width, Height)
	glGetDoublev(GL_MODELVIEW_MATRIX, modelview);		// Retrieve The Modelview Matrix
	glGetDoublev(GL_PROJECTION_MATRIX, projection);		// Retrieve The Projection Matrix

	int mx = (int)mouse[0];
	int my = (int)mouse[1];
	my = viewport[3] - my; // convert to opengl's coordinates (y axis from bottom left)
	
	double sx,sy,sz;
	gluUnProject((float)mx, (float)my, 0, modelview, projection, viewport, &sx, &sy, &sz);
	double ex,ey,ez;
	gluUnProject((float)mx, (float)my, .3, modelview, projection, viewport, &ex, &ey, &ez);
	start = vec3(sx,sy,sz);
	vec3 end(ex, ey, ez);
	dir = end-start;
	dir.normalize();
}
Ejemplo n.º 19
0
void EnvironmentRender::reflection(vec3 pos, vec3 nor, f32 dis, gchandle tex)
{
  kgmCamera cam;

  vec3 cpos = gr->m_camera->mPos;
  vec3 cdir = gr->m_camera->mDir;
  f32  fov  = gr->m_camera->mFov;
  f32  asp  = gr->m_camera->mAspect;
  f32  zfar  = gr->m_camera->mFar;
  f32  zner  = gr->m_camera->mNear;

  cpos.z *= -1;
  cdir.z *= -1;

  cam.set(fov, asp, zner, zfar, cpos, cdir, vec3(0, 0, 1));

  kgmGraphics::Options o;

  o.width = 512;
  o.height = 512;

  o.clipping = true;
  o.light    = false;

  nor.normalize();

  plane plane(nor, pos);
  o.plane[0] = plane.x;
  o.plane[1] = plane.y;
  o.plane[2] = plane.z;
  o.plane[3] = plane.w;

  o.discard = m_discard;

  gc->gcTexTarget(m_target, tex, gctype_tex2d);
  gc->gcSetTarget(m_target);
  gr->render(cam, o);
  gc->gcSetTarget(null);
}
Ejemplo n.º 20
0
mat4 mat4::RotationMatrix(vec3 axis,double angle)
{
	const float MATH_PI = 3.141592653f;
	float rad = angle*MATH_PI/180.0f;
	mat4 R;	
	axis.normalize();
	double x=axis.X;

	double y = axis.Y;
	double z = axis.Z;
	double c = cos(rad);
	double s = sin(rad);
	R.m_Mat[0][0] = x*x*(1-c)+c;
	R.m_Mat[0][1] = x*y*(1-c)-z*s;
	R.m_Mat[0][2] = x*z*(1-c)+y*s;
	R.m_Mat[1][0] = y*x*(1-c)+z*s;
	R.m_Mat[1][1] = y*y*(1-c)+c;
	R.m_Mat[1][2] = y*z*(1-c)-x*s;
	R.m_Mat[2][0] = z*x*(1-c)-y*s;
	R.m_Mat[2][1] = z*y*(1-c)+x*s;
	R.m_Mat[2][2] = z*z*(1-c)+c;

	return R;
}
Ejemplo n.º 21
0
 ray3(const T* coords): p0(coords), u(coords + 3) {
     u.normalize();
 }
Ejemplo n.º 22
0
 plane3(T v0x, T v0y, T v0z, T norm_x, T norm_y, T norm_z): v0(v0x, v0y, v0z), n(norm_x, norm_y, norm_z) {
     n.normalize();
 }
Ejemplo n.º 23
0
 ray3(T p0x, T p0y, T p0z, T ux, T uy, T uz): u(ux, uy, uz), p0(p0x, p0y, p0z) {
     u.normalize();
 }
Ejemplo n.º 24
0
 ray3(vec3<T> &p0, vec3<T> &u): u(u), p0(p0) {
     u.normalize();
 }
Ejemplo n.º 25
0
 plane3(const T* coords): v0(coords), n(coords + 3) {
     n.normalize();
 }
Ejemplo n.º 26
0
void missil::setDirection(vec3 d)
{
	this->direction = d.normalize();
}
Ejemplo n.º 27
0
 plane3(vec3<T> &v0, vec3<T> &norm): n(norm), v0(v0) {
     n.normalize();
 }