예제 #1
0
파일: vr.cpp 프로젝트: nikki93/thesis-2015
std::array<mat4, 2> VR::eye_transforms(ovrPosef pose[2], bool mid) const
{
    ovrVector3f eye_offset[2] =
    {
        m_eye_rdesc[0].HmdToEyeViewOffset,
        m_eye_rdesc[1].HmdToEyeViewOffset,
    };

    // 'mid eye'? use midpoint
    if (mid)
    {
        eye_offset[0].x = eye_offset[1].x =
            0.5f * (eye_offset[0].x + eye_offset[1].x);
        eye_offset[0].y = eye_offset[1].y =
            0.5f * (eye_offset[0].y + eye_offset[1].y);
        eye_offset[0].z = eye_offset[1].z =
            0.5f * (eye_offset[0].z + eye_offset[1].z);
    }

    ovrHmd_GetEyePoses(m_hmd, 0, eye_offset, pose, nullptr);
    return
    {
        {
            translate(mat4(), convert(pose[0].Position))
            * mat4_cast(convert(pose[0].Orientation)),
            translate(mat4(), convert(pose[1].Position))
            * mat4_cast(convert(pose[1].Orientation))
        }
    };
}
예제 #2
0
void AxonometricLookAt::rebuild() const
{
    if(!m_rebuild)
        return;

    const mat4 vrot = mat4_cast(angleAxis(m_verticalAngle, vec3( 0.f, 1.f, 0.f)));
    const mat4 hrot = mat4_cast(angleAxis(m_horizontalAngle, vec3( 1.f, 0.f, 0.f)));

    const mat4 zoom = scale(m_zoom, m_zoom, -1.f);
    const mat4 t    = translate(m_position);

    m_axonometric = zoom * t * hrot * vrot * m_rotation;

    m_rebuild = false;
}
예제 #3
0
mat4 Transform::renderMatrix(bool scaled)
{
	if (dirty && scaled)
	{
		matrix = glm::translate(_position) * mat4_cast(_rotation) * glm::scale(_scale);
		dirty = false;
	}

	if (unscaledDirty && !scaled)
	{
		unscaledMatrix = glm::translate(_position) * mat4_cast(_rotation);
		unscaledDirty = false;
	}

	if (scaled)
		return matrix;
	return unscaledMatrix;
}
예제 #4
0
	glm::mat4 DisplayObject::getRotationMatrix ()
	{
		if (_rotationIsDirty)
		{
			_rotationMatrixCache = mat4_cast(_rotation);
			_rotationIsDirty = false;
		}
		
		return _rotationMatrixCache;
	}
예제 #5
0
  void Transform::
  recalculate_world()
  {
    _world = mat4(1);

    _world = translate(_world, _t);
    _world = mat4_cast(_r) * _world;
    _world = scale(_world, _s);

    _dirty = false;
  }
예제 #6
0
void LifeCounter::Draw(mat4 view, mat4 projection) {
	projection = ortho(0.0f, 20.0f * (scene->width / (float)scene->height), 0.0f, 20.0f, -20.0f, 20.0f);
	for(int i=0; i<lives; i++) {
		Content::shader(basic).Begin();
			mat4 model = translation(position + vec3(i * icon.size.x, 0, 0))  * mat4_cast(orientation) * scale(size);
			model = model;
			glUniformMatrix4fv(Content::shader(basic)("inv_view"), 1, GL_FALSE, &(model[0][0]));
			icon.Draw(model, projection);
		Content::shader(basic).End();
	}
}
예제 #7
0
파일: Plane3.cpp 프로젝트: gersseba/glow
const mat4 rotate(
    const vec3 & a
,   const vec3 & b)
{
    const vec3 anorm(normalize(a));
    const vec3 bnorm(normalize(b));

    const vec3 axis = cross(anorm, bnorm);
    const float angle = acos(dot(anorm, bnorm));

    return mat4_cast(angleAxis(degrees(angle), axis));
}
예제 #8
0
void QuaternionTest::Draw(ModelviewStack* ms)
{
    useTexture(0);
    setColour(1.0, 1.0, 1.0);

    ms->Push();
    {
        ms->Mult(mat4_cast(_orientation));
        ms->Translate(_transform.position);

        vec4 pos4 = mat4_cast(_orientation) * vec4(1.0, 1.0, 1.0, 1.0);

        drawCube(*ms);
    }
    ms->Pop();

    setColour(0.0, 0.0, 0.0);
    ms->Push();
    {
        ms->Scale(vec3(0.25f, 0.25f, 0.25f));
        drawSphere(*ms);
    }
    ms->Pop();
}
예제 #9
0
  /**
   * Animate the cube rotations.
   * @param elapsed The elapsed time since the last draw call.
   */
  mat4 Cubie::animateCubeRotation(double elapsed)
  {
    float cosTheta;

    // Spherical linear interpolation (SLERP) between the current and desired
    // orientations.  The orientation needs to be normalized or precision
    // will be lost over time, causing constantly animated cubes.
    this->cubeRot.orientation = normalize(slerp(this->cubeRot.orientation,
      this->cubeRot.desired, this->cubeRot.speed * (float)elapsed));

    // The cosine between the orientation and desired.
    cosTheta = dot(this->cubeRot.orientation, this->cubeRot.desired);

    //if (cosTheta > .999 && cosTheta < 1.001 || cosTheta)
    if (fabs(1 - fabs(cosTheta)) < .00001)
      this->cubeRot.orientation = this->cubeRot.desired;

    return mat4_cast(this->cubeRot.orientation);
  }
예제 #10
0
Transform AnimatedTransform::interpolate(float time) const {
    if (!_actuallyAnimated || time <= 0.f) {
        return _transforms[0];
    }
    if (time >= 1.f) {
        return _transforms[1];
    }
    
    // Interpolate translation
    vec3 t = mix(_translations[0], _translations[1], time);
    
    // Interpolate rotation
    quat r = mix(_rotations[0], _rotations[1], time);
    
    // Interpolate scale
    mat4x4 s = mix(_scales[0], _scales[1], time);
    
    // Recompose interpolated matrix
    mat4x4 m;
    m = glm::translate(m, t) * mat4_cast(r) * s;
    return m;
}
예제 #11
0
void Ship::draw () {
    if (token != engine.token) init ();

    if (!exploded) {
        glUseProgram (program);

        modelMatrix = translate (mat4(1), position) * mat4_cast(orientation);

        mvMatrix = engine.viewMatrix * modelMatrix;
        mvpMatrix = engine.projectionMatrix * mvMatrix;

        glUniformMatrix4fv (u_MvpMatrixHandle, 1, GL_FALSE, value_ptr (mvpMatrix));
        glUniformMatrix4fv (u_MvMatrixHandle, 1, GL_FALSE, value_ptr (mvMatrix));

        mat4 lightMatrix = engine.viewMatrix * translate (mat4(1), position);
        glUniform3fv (u_LightPosHandle, 1, value_ptr (lightMatrix * engine.state.lightPos));
        glUniform3fv (u_EyePosHandle, 1, value_ptr (engine.state.eyePos));

        glBindBuffer (GL_ARRAY_BUFFER, vbo);

        glVertexAttribPointer (a_PositionHandle, 3, GL_FLOAT, GL_FALSE, stride, 0);
        glEnableVertexAttribArray (a_PositionHandle);

        glVertexAttribPointer (a_NormalHandle, 3, GL_FLOAT, GL_FALSE, stride, (void*)12);
        glEnableVertexAttribArray (a_NormalHandle);

        glVertexAttribPointer (a_ColorHandle, 3, GL_FLOAT, GL_FALSE, stride, (void*)24);
        glEnableVertexAttribArray (a_ColorHandle);

        glDrawArrays (GL_TRIANGLES, 0, nvertices / 3);

        glBindBuffer (GL_ARRAY_BUFFER, 0);
    }

    throttleParticles->draw ();
    fireParticles->draw ();
    guideParticles->draw ();
}
예제 #12
0
파일: testApp.cpp 프로젝트: Atayyab/pbd
//--------------------------------------------------------------
void testApp::draw(){
	glMatrixMode(GL_PROJECTION);
	glLoadMatrixf(value_ptr(persp));
	glMatrixMode(GL_MODELVIEW);
	mat4 qrot = cam * mat4_cast(rot);
	glLoadMatrixf(value_ptr(qrot));
	glEnable(GL_DEPTH_TEST);
	if(debug){
		cloth.draw();	
	}
	else {
		cloth_gl.draw();
	}
	particles.draw();
	if(record) {
		char buf[512];
		sprintf(buf, "pbd-%04d.png", frame_num);
		ofSaveScreen(buf);
		++frame_num;
	}

	ofxTweakbars::draw();
}
예제 #13
0
void Camera::Update() {
    auto yawq = glm::angleAxis(camera_pitch, vec3(1,0,0));
    auto pitchq = glm::angleAxis(camera_heading, vec3(0,1,0));

    projection = glm::perspective(field_of_view, aspect, near_clip, far_clip);

    rotation_quaternion = pitchq * yawq * rotation_quaternion;
    rotation_quaternion = normalize(rotation_quaternion);

    position += position_delta;
    look_at = position + direction;


    camera_heading *= .5;
    camera_pitch *= .5;
    position_delta = position_delta * .8f;
    
    view = translate(mat4_cast(rotation_quaternion), -position);//glm::lookAt(position, look_at, up);
    up = vec3(view[1][0],view[1][1],view[1][2]);
    direction = vec3(view[0][0],view[0][1],view[0][2]);
    model = glm::mat4(1.0f);
    MVP = projection * view * model;
    //glLoadMatrixf(glm::value_ptr(MVP));
}
예제 #14
0
	detail::tmat4x4<valType> toMat4(
		detail::tquat<valType> const & x){return mat4_cast(x);}
예제 #15
0
	GLM_FUNC_DECL tmat4x4<T, P> toMat4(
		tquat<T, P> const & x){return mat4_cast(x);}
예제 #16
0
	detail::tmat4x4<T, P> toMat4(
		detail::tquat<T, P> const & x){return mat4_cast(x);}
예제 #17
0
void CCube::Update(double dt)
{
	vec3 zero(0,0,0);

	//update velocity and angular velocity
	v = 0.99*v+ dt* down_vec + m_impulse;
	
	// lerp impulse to zero
	m_impulse = Lerp(m_impulse, zero, 0.1f);

	w = 0.99*w;

	//update translation of center of mass c, and rotation (represented by a quaternion q)
	c = c + vec3(v.x*dt, v.y*dt, v.z*dt);
	q = q + 0.5*dt*w*q;
	float s = 1.f/sqrt(q[0]*q[0]+q[1]*q[1]+q[2]*q[2]+q[3]*q[3]);
	q = s*q;
	m_rotation =mat4_cast(q);
	m_translation = glm::translate(mat4(1.f),c);

	//Handling collision
	vec3 n;
	for (int i = 0; i < 8; i++) {
		vec4 contact = m_rotation*vertex_positions[i];
		vec4 p = m_translation * contact;
		bool bCol = false;
		vec3 constraint_f=vec3(0.);

		//Detect collision with which wall
		if (p.x < -10.f) {
			bCol = true;
			n = vec3(1.f, 0.f, 0.f);
			constraint_f.x += -10-p.x;
		} else if (p.x > 10.f) {
			bCol = true;
			n = vec3(-1.f, 0.f, 0.f);
			constraint_f.x += 10-p.x;
		} else if (p.y < -10.f) {
			bCol = true;
			n = vec3(0.f, 1.f, 0.f);
			constraint_f.y += -10-p.y;
		} else if (p.y > 10.f) {
			bCol = true;
			n = vec3(0.f, -1.f, 0.f);
			constraint_f.y += 10-p.y;
		} else if (p.z < -10.f) {
			bCol = true;
			n = vec3(0.f, 0.f, 1.f);
			constraint_f.z += -10-p.z;
		} else if (p.z > 10.f) {
			bCol = true;
			n = vec3(0.f, 0.f, -1.f);
			constraint_f.z += 10-p.z;
		}

		if (bCol) {
			//Handle the collision: compute the impulse j, and update v and w

			vec3 u_rel = v + glm::cross(w, vec3(contact));
			vec3 rxn = glm::cross(vec3(contact), n);
			//For a cube, the impulse j=(1+e)* dot(u_rel,n) / (1+ 6 |r cross n|^2)
			//double j = -1.9f * glm::dot(u_rel,n);
			double j = -1.9f * glm::dot(u_rel,n) / (1.+6.*glm::dot(rxn,rxn));
			if (j > 0) {
				v = v + j*n;
				w = w + 6.*j*glm::cross(vec3(contact), n);
			}

			//Constraint force to prevent drifting down the floor
			constraint_f = dt * 100. * constraint_f;
			v = v + constraint_f;
			w = w + 6.*glm::cross(vec3(contact), constraint_f);
		}
	}
}
예제 #18
0
	GLM_FUNC_DECL mat<4, 4, T, P> toMat4(
		tquat<T, P> const& x){return mat4_cast(x);}