コード例 #1
0
ファイル: VoxRaytracer.cpp プロジェクト: AndreaRigoni/uLib
VoxRaytracer::RayData VoxRaytracer::TraceBetweenPoints(const Vector4f &in,
                                                       const Vector4f &out)
const
{
    RayData ray;
    Vector4f pt1 = m_Image->GetLocalPoint(in);
    Vector4f pt2 = m_Image->GetLocalPoint(out);
    Vector4f s = pt2 - pt1;



    Vector3f scale; // FIXXX
    scale << (m_Image->GetWorldMatrix() * Vector4f(1,0,0,0)).norm(),
            (m_Image->GetWorldMatrix() * Vector4f(0,1,0,0)).norm(),
            (m_Image->GetWorldMatrix() * Vector4f(0,0,1,0)).norm();

    float l = s.head(3).norm();
    Vector3f L(l/s(0), l/s(1), l/s(2));

    Vector3f offset;
    for(int i=0;i<3;++i)
        offset(i) = (s(i)>=0) - (pt1(i)-floor(pt1(i))) ;

    offset = offset.cwiseProduct(L).cwiseAbs();
    L = L.cwiseAbs();

    int id; float d;
    Vector3i vid = m_Image->Find(in);
    while(l>0)
    {
        d = offset.minCoeff(&id);

        if(m_Image->IsInsideGrid(vid))
            ray.AddElement(m_Image->Map(vid), d * scale(id) );

        // nan check //
        //        if(unlikely(!isFinite(d * scale(id)))) {
        //            std:: cout << "NAN in raytracer\n";
        //            exit(1);
        //        }

        vid(id) += (int)fast_sign(s(id));

        l -= d;
        offset.array() -= d;
        offset(id) = fmin(L(id),l);
    }
    return ray;
}
コード例 #2
0
/**
* @brief	Updates the position and rotation every time step dt. 
*
* @param	dt	  The steptime, the time since the last drawn frame. 
*
* @return	void 
*/
void Camera::update(float dt)
{
	glm::vec4 dir = glm::vec4(0,0,1,0);
 	glm::mat4x4 mDir = glm::rotate(glm::mat4(),-_rotation[0],glm::vec3(0.0f,1.0f,0.0f));
 	glm::mat4x4 mSide = glm::rotate(glm::mat4(),90.0f,glm::vec3(0.0f,1.0f,0.0f));
 	dir = mDir * dir;
 	glm::vec4 side = mSide * dir;

	glm::vec3 force;
	if(_movingForward && !_movingBackward)
	{
		force -= glm::vec3(dir[0],dir[1],dir[2]);
	}
	if(!_movingForward && _movingBackward)
	{
		force += glm::vec3(dir[0],dir[1],dir[2]);
	}
	if(_movingLeft && !_movingRight)
	{
		force -= glm::vec3(side[0],side[1],side[2]);
	}
	if(!_movingLeft && _movingRight)
	{
		force += glm::vec3(side[0],side[1],side[2]);
	}
	if(!_movingUp && _movingDown)
	{
		force += glm::vec3(0,1,0);
	}
	if(_movingUp && !_movingDown)
	{
		force -= glm::vec3(0,1,0);
	}

	_velocity += force*(dt*_acceleration); 
	_position += _velocity*dt;

	float m = glm::length(_velocity);
	if(m!=0){
		glm::vec3 velDir = glm::normalize(_velocity);
		_velocity -= velDir*dt*_deacceleration;
	}

	if(m<0.001)
		_velocity = glm::vec3(0,0,0);
	if(m>_speed)
		_velocity *= _speed/m;



	float sign;
	_rotVelocityV += _rotForceV*(dt*_rotationAcceleration); 
	sign = fast_sign(_rotVelocityV);

	_rotVelocityV -= sign*dt*_rotationDeacceleration;
	if(fabs(_rotVelocityV)>_rotationSpeed)
		_rotVelocityV = sign*_rotationSpeed;
	if(fabs(_rotVelocityV)<0.1){
		_rotVelocityV = 0;
	}
	_rotation.y += _rotVelocityV*dt;
	_rotForceV = 0;


	_rotVelocityH += _rotForceH*(dt*_rotationAcceleration); 
	sign = fast_sign(_rotVelocityH);

	_rotVelocityH -= sign*dt*_rotationDeacceleration;
	if(fabs(_rotVelocityH)>_rotationSpeed)
		_rotVelocityH = sign*_rotationSpeed;
	if(fabs(_rotVelocityH)<0.1){
		_rotVelocityH = 0;
	}
	_rotation.x += _rotVelocityH*dt;
	_rotForceH = 0;

	glm::vec3 headPos = sgct::Engine::getUserPtr()->getPos();

	if(_rotation[1]<-89)
	{
		_rotation[1] = -89;
	}
	if(_rotation[1]>89)
	{
		_rotation[1] = 89;
	}

	//glm::vec4 worldRect = ImmersiveKidz::getInstance()->getWorldRect();
	if(_position.x+headPos.x < _limitsX.x) _position.x = _limitsX.x-headPos.x;
	if(_position.x+headPos.x > _limitsX.y) _position.x = _limitsX.y-headPos.x;
	if(_position.y+headPos.y < _limitsY.x) _position.y = _limitsY.x-headPos.y;
	if(_position.y+headPos.y > _limitsY.y) _position.y = _limitsY.y-headPos.y;
	if(_position.z+headPos.z < _limitsZ.x) _position.z = _limitsZ.x-headPos.z;
	if(_position.z+headPos.z > _limitsZ.y) _position.z = _limitsZ.y-headPos.z;

	_viewMatrix = glm::mat4();
	_viewMatrix = glm::translate(_viewMatrix,headPos);
 	_viewMatrix = glm::rotate(_viewMatrix,_rotation[1],glm::vec3(1.0f,0.0f,0.0f));
 	_viewMatrix = glm::rotate(_viewMatrix,_rotation[0],glm::vec3(0.0f,1.0f,0.0f));
	_viewMatrix = glm::translate(_viewMatrix,-_position);
	_viewMatrix = glm::translate(_viewMatrix,-headPos);
}