Exemple #1
0
void IceMaths::NormalizePRSMatrix(Matrix4x4& dest, Point& scale, const Matrix4x4& src)
{
	Point row;
	dest = src;
	for( int i=0;i<3;i++)
	{
		src.GetRow(i,row);

		// computes scales

		scale[i] = row.Magnitude();

		row /= scale[i];

		dest.SetRow(i,row);
	}
}
/* Helper function to set up a scale matrix. */
static void
ProcessScaleHelper(Matrix4x4& aMatrix,
                   float aXScale, 
                   float aYScale, 
                   float aZScale)
{
  aMatrix.PreScale(aXScale, aYScale, aZScale);
}
Matrix4x4 RenderManager::BuildViewMatrix()
{
	Matrix4x4 view;
	if (viewMatrixMade == false) {
		Vector4 position = activeCamera->GetParent()->GetPosition();
		Vector4 upVector = activeCamera->GetParent()->GetLocalY();
		Vector4 lookAt = position + activeCamera->GetParent()->GetLocalZ();

		view.LookAt(position, lookAt, upVector);
		ConvertToOpenGLMatrix(view, viewMatrix);
		viewMat = view;
		viewMatrixMade = true;
	} else {
		view = viewMat;
	}
	return view;
}
Exemple #4
0
Matrix4x4 Perspective( float fov, float aspectRatio, float fNear, float fFar )
{
	Matrix4x4 result;
	
	float yScale = ( 1 / tan( fov / 2 ) );		// cot( fov / 2 )
	float xScale = yScale / aspectRatio;
	
	result.Identity();
	result.m[0][0] = xScale;
	result.m[1][1] = yScale;
	result.m[2][2] = fFar / ( fFar - fNear );
	result.m[2][3] = ( -fNear * fFar) / ( fFar - fNear );
	result.m[3][2] = 1;
	result.m[3][3] = 0;

	return result;
}
Exemple #5
0
 Matrix4x4 Matrix4x4::Orthographic(float left, float right, float bottom, float top, float near, float far)
 {
     //http://www.songho.ca/opengl/gl_projectionmatrix.html
     Matrix4x4 matrix = Matrix4x4::identity;
     
     //Scale components
     matrix.RowCol(0, 0) = 2 / (right - left);
     matrix.RowCol(1, 1) = 2 / (top - bottom);
     matrix.RowCol(2, 2) = -2 / (far - near);
     
     //Translate components
     matrix.RowCol(0, 3) = -(right + left) / (right - left);
     matrix.RowCol(1, 3) = -(top + bottom) / (top - bottom);
     matrix.RowCol(2, 3) = -(far + near) / (far - near);
     
     return matrix;
 }
Exemple #6
0
void MainWindow::setShaderConstants( SceneObject& obj,
                                     ShaderProgram& shader ) {
  uboMaterial.shadowMatrix = shadowMatrix();

  Matrix4x4 view = scene.camera().view();
  view.mul( obj.transform()  );

  Matrix4x4 mvp = scene.camera().projective();
  mvp.mul( view );

  uboMaterial.modelView  = view;
  uboMaterial.mvpMatrix  = mvp;
  uboMaterial.projMatrix = mvp;
  uboMaterial.diffuse    = obj.material().diffuse;
  uboMaterial.matColor   = obj.material().color;
  shader.setUniform(uboMaterial,umaterial,0);
  }
Exemple #7
0
Matrix4x4 matc::ortho(float left, float right, float bottom, float top, float nearVal, float farVal)
{
  float r_l = 1/(right-left);
  float t_b = 1/(top-bottom);
  float f_n = 1/(farVal-nearVal);

  Matrix4x4 res;
  res.set(0,0, 2*r_l);
  res.set(1,1, 2*t_b);
  res.set(2,2, (-2)*f_n);
  
  res.set(3,0, -(right+left)*r_l);
  res.set(3,1, -(top+bottom)*t_b);
  res.set(3,2, -(farVal+nearVal)*f_n);

  return res;
}
Exemple #8
0
Vec4 Matrix4x4::transform_normal_ray(Matrix4x4 t,Vec4 p)
{
    Matrix4x4 scale,rot;

    scale.setMatrix4x4(t.scale_m);
    rot.setMatrix4x4(t.rotate_m);
    scale.matrix[0] = 1.0/scale.matrix[0];
    scale.matrix[5] = 1.0/scale.matrix[5];
    scale.matrix[10] = 1.0/scale.matrix[10];

    Matrix4x4 result;
    result = result.multMatrix(rot,scale);
    Vec4 out = scale.transpose().vector(p);
    out = rot.transpose().vector(out);
//    out = inv_scale.transpose().vector(out);
    return out;
}
Exemple #9
0
Matrix4x4::Matrix4x4( const Matrix4x4& m )
{
    this->ID = m.ID + " copy";
    this->Data = new float[ m.Dimensions * m.Dimensions ];
    for ( int x = 0; x < this->Dimensions; x++ )
        for ( int y = 0; y < this->Dimensions; y++ )
            this->SetValue( x, y, m.GetValue( x, y ) );
}
Exemple #10
0
void Item::UpdateItemParticleEffects(float dt)
{
	if(m_erase)
	{
		return;
	}

	if(m_pVoxelItem != NULL)
	{
		for(int i = 0; i < m_pVoxelItem->GetNumParticleEffects(); i++)
		{
			unsigned int particleEffectId;
			vec3 ParticleEffectPos;
			string effectName;
			bool connectedToSegment;
			m_pVoxelItem->GetParticleEffectParams(i, &particleEffectId, &ParticleEffectPos, &effectName, &connectedToSegment);

			if(particleEffectId == -1)
			{
				m_pBlockParticleManager->ImportParticleEffect(effectName, ParticleEffectPos, &particleEffectId);
				m_pVoxelItem->SetParticleEffectId(i, particleEffectId);
			}

			if(connectedToSegment == false)
			{
				ParticleEffectPos *= m_renderScale;

				// Rotate due to characters forward vector
				float rotationAngle = acos(dot(vec3(0.0f, 0.0f, 1.0f), m_forward));
				if(m_forward.x < 0.0f)
				{
					rotationAngle = -rotationAngle;
				}
				Matrix4x4 rotationMatrix;
				rotationMatrix.SetRotation(0.0f, rotationAngle, 0.0f);
				ParticleEffectPos = rotationMatrix * ParticleEffectPos;

				// Translate to position
				ParticleEffectPos += m_position;
			}

			m_pBlockParticleManager->UpdateParticleEffectPosition(particleEffectId, ParticleEffectPos, ParticleEffectPos);
		}
	}
}
Exemple #11
0
 Matrix4x4 Matrix4x4::FromRotation(Quaternion rotation)
 {
     //rotation.Normalize();
     
     Matrix4x4 matrix = Matrix4x4::identity;
     
     float a = rotation.w;
     float b = rotation.x;
     float c = rotation.y;
     float d = rotation.z;
     
     float aSqr = a * a;
     float bSqr = b * b;
     float cSqr = c * c;
     float dSqr = d * d;
     
     matrix.RowCol(0, 0) = aSqr + bSqr - cSqr - dSqr;
     matrix.RowCol(0, 1) = (2 * b * c) - (2 * a * d);
     matrix.RowCol(0, 2) = (2 * b * d) + (2 * a * c);
     
     matrix.RowCol(1, 0) = (2 * b * c) + (2 * a * d);
     matrix.RowCol(1, 1) = aSqr - bSqr + cSqr - dSqr;
     matrix.RowCol(1, 2) = (2 * c * d) - (2 * a * b);
     
     matrix.RowCol(2, 0) = (2 * b * d) - (2 * a * c);
     matrix.RowCol(2, 1) = (2 * c * d) + (2 * a * b);
     matrix.RowCol(2, 2) = aSqr - bSqr - cSqr + dSqr;
     
     return matrix;
 }
Exemple #12
0
void Matrix4x4::EulerRotation(const Vertex &rot)
{
	float radiansX = rot._x * (float(PI)/float(180));
	float radiansY = rot._y * (float(PI)/float(180));
	float radiansZ = rot._z * (float(PI)/float(180));

	Matrix4x4 matRotateX;
	matRotateX.SetMatrix(1.0f, 0.0f,         0.0f,
						0.0f, cos(radiansX), sin(radiansX),
						0.0f, -sin(radiansX),cos(radiansX));

	Matrix4x4 matRotateY; 
	matRotateY.SetMatrix(cos(radiansY), 0.0f, -sin(radiansY),
						0.0f,         1.0f, 0.0f,
						sin(radiansY), 0,    cos(radiansY));
	
	Matrix4x4 matRotateZ; 
	matRotateZ.SetMatrix(cos(radiansZ),  sin(radiansZ), 0.0f,
						-sin(radiansZ), cos(radiansZ), 0.0f,
						0.0f,          0.0f,         1.0f);

	matRotateZ.Transformation(matRotateX);
	matRotateZ.Transformation(matRotateY);

	Transformation(matRotateZ);
}
Exemple #13
0
/**
*  @brief
*    Returns the 8 camera frustum vertices
*/
const Array<Vector3> &SNCamera::GetFrustumVertices(const Rectangle &cViewport)
{
	// Get the viewport width and height
	const uint32 nViewportWidth  = static_cast<uint32>(cViewport.GetWidth());
	const uint32 nViewportHeight = static_cast<uint32>(cViewport.GetHeight());

	// Calculate frustum vertices if required
	if ((m_nInternalCameraFlags & RecalculateFrustumVertices) ||
		m_nViewportWidth != nViewportWidth || m_nViewportHeight != nViewportHeight) {
		// Ensure that the other camera properties which depend on the viewport dimension are also updated correctly
		// -> This may lead to a "double" (in sense of "we could probably avoid one when doing more complex tests") calculation, but this in here is just an optimization and should never result in invalid settings
		m_nInternalCameraFlags |= RecalculateProjectionMatrix;
		m_nInternalCameraFlags |= RecalculateFrustum;

		// Backup the viewport dimension
		m_nViewportWidth  = nViewportWidth;
		m_nViewportHeight = nViewportHeight;

		// Set unit box
		m_cFrustumVertices.Resize(8);
		m_cFrustumVertices[0].SetXYZ(-1.0f, -1.0f, -1.0f);
		m_cFrustumVertices[1].SetXYZ(-1.0f,  1.0f, -1.0f);
		m_cFrustumVertices[2].SetXYZ( 1.0f,  1.0f, -1.0f);
		m_cFrustumVertices[3].SetXYZ( 1.0f, -1.0f, -1.0f);
		m_cFrustumVertices[4].SetXYZ(-1.0f, -1.0f,  1.0f);
		m_cFrustumVertices[5].SetXYZ(-1.0f,  1.0f,  1.0f);
		m_cFrustumVertices[6].SetXYZ( 1.0f,  1.0f,  1.0f);
		m_cFrustumVertices[7].SetXYZ( 1.0f, -1.0f,  1.0f);

		// Get world transform matrix with no scale
		Matrix4x4 mWorld;
		mWorld.FromQuatTrans(CalculateViewRotation(), GetTransform().GetPosition());
		mWorld *= GetProjectionMatrix(cViewport).GetInverted();

		// Project the vertices
		for (uint8 i=0; i<m_cFrustumVertices.GetNumOfElements(); i++)
			m_cFrustumVertices[i] *= mWorld;

		// Recalculation done
		m_nInternalCameraFlags &= ~RecalculateFrustumVertices;
	}

	// Return the frustum vertices
	return m_cFrustumVertices;
}
void NativeRender(GraphicsContext *graphicsContext) {
	g_GameManager.Update();

	float xres = dp_xres;
	float yres = dp_yres;

	// Apply the UIContext bounds as a 2D transformation matrix.
	Matrix4x4 ortho;
	if (GetGPUBackend() == GPUBackend::DIRECT3D9) {
		ortho.setOrthoD3D(0.0f, xres, yres, 0.0f, -1.0f, 1.0f);
		Matrix4x4 translation;
		translation.setTranslation(Vec3(-0.5f, -0.5f, 0.0f));
		ortho = translation * ortho;
	} else {
		ortho.setOrtho(0.0f, xres, yres, 0.0f, -1.0f, 1.0f);
	}

	ui_draw2d.SetDrawMatrix(ortho);
	ui_draw2d_front.SetDrawMatrix(ortho);

	screenManager->render();
	if (screenManager->getUIContext()->Text()) {
		screenManager->getUIContext()->Text()->OncePerFrame();
	}

	DrawDownloadsOverlay(*screenManager->getUIContext());

	if (g_TakeScreenshot) {
		TakeScreenshot();
	}

	if (resized) {
		resized = false;

		graphicsContext->Resize();
		// TODO: Move this to new GraphicsContext objects for each backend.
#ifndef _WIN32
		if (GetGPUBackend() == GPUBackend::OPENGL) {
			PSP_CoreParameter().pixelWidth = pixel_xres;
			PSP_CoreParameter().pixelHeight = pixel_yres;
			NativeMessageReceived("gpu resized", "");
		}
#endif
	}
}
Exemple #15
0
Matrix4x4 matc::translate(const Matrix4x4 &m, const Vector3 &v)
{
  matc::Matrix4x4 res(m);
  const float* p = m.asArray();
  res.set(MAT_DIM-1, 0, p[MAT_DIM * (MAT_DIM-1) + 0] + v.x);
  res.set(MAT_DIM-1, 1, p[MAT_DIM * (MAT_DIM-1) + 1] + v.y);
  res.set(MAT_DIM-1, 2, p[MAT_DIM * (MAT_DIM-1) + 2] + v.z);
  return res;
}
Exemple #16
0
		void Ray::Detransform( const Matrix4x4 &p_Matrix )
		{
			Matrix4x4 Tmp;
			Tmp.Copy( p_Matrix );

			// Take the negated translation from the matrix
			m_Origin[ 0 ] -= p_Matrix( 0, 3 );
			m_Origin[ 1 ] -= p_Matrix( 1, 3 );
			m_Origin[ 2 ] -= p_Matrix( 2, 3 );

			// Get rid of the translation in the matrix
			Tmp( 0, 3 ) = Tmp( 1, 3 ) = Tmp( 2, 3 ) = 0.0f;

			// Invert the matrix
			Tmp.AffineInverse( );

/*UNCOMMENT!			m_Direction = m_Origin * Tmp;*/
		}
void CPhysicsActor::GetTransform(Matrix4x4& trans)
{
	NxMat34 tmp = m_Actor->getGlobalPose();
	float* tmp2 = new float[16];
	tmp.getColumnMajor44( tmp2 );
	trans.SetFrom4x4( tmp2 );

	delete tmp2;
}
Exemple #18
0
void Item::RenderCollisionRegions()
{
	for(unsigned int i = 0; i < m_vpBoundingRegionList.size(); i++)
	{
		BoundingRegion* pRegion = m_vpBoundingRegionList[i];

		m_pRenderer->PushMatrix();
			m_pRenderer->TranslateWorldMatrix(GetCenter().x, GetCenter().y, GetCenter().z);

			Matrix4x4 justParentRotation;
			justParentRotation.SetRotation(DegToRad(m_rotation.x), DegToRad(m_rotation.y), DegToRad(m_rotation.z));
			m_pRenderer->MultiplyWorldMatrix(justParentRotation);

			m_pRenderer->ScaleWorldMatrix(m_renderScale, m_renderScale, m_renderScale);
			pRegion->Render(m_pRenderer);
		m_pRenderer->PopMatrix();
	}
}
    /*
    * Rotate around a specific point and orientation vector.
    *
    * The point is specified by [px], [py], and [pz].
    *
    * The orientation vector is specified by [ax], [ay], and [az].
    *
    * The parameter [local] determines whether local or world space is used.
    * If world space is used, it takes into account the  aggregated transform
    * of the scene object's ancestors.
    */
    void SceneObjectTransform::RotateAround(Real px, Real py, Real pz, Real ax, Real ay, Real az, Real angle, Bool local) {
        if (!local) {
            Matrix4x4 worldTransMat;
            worldTransMat.PreTranslate(-px, -py, -pz);
            worldTransMat.PreRotate(ax, ay, az, angle);
            worldTransMat.PreTranslate(px, py, pz);
            Transform worldTrans;
            worldTrans.SetTo(worldTransMat);

            Transform localTrans;
            GetLocalTransformationFromWorldTransformation(worldTrans, localTrans);

            this->TransformBy(localTrans);
        }
        else {
            Transform::RotateAround(px, py, pz, ax, ay, az, angle, true);
        }
    }
Exemple #20
0
 Matrix4x4 Matrix4x4::Perspective(float left, float right, float bottom, float top, float near, float far)
 {
     //http://www.songho.ca/opengl/gl_projectionmatrix.html
     Matrix4x4 matrix = Matrix4x4::zero;
     
     matrix.RowCol(0, 0) = 2 * near / (right - left);
     matrix.RowCol(0, 2) = (right + left) / (right - left);
     
     matrix.RowCol(1, 1) = 2 * near / (top - bottom);
     matrix.RowCol(1, 2) = (top + bottom) / (top - bottom);
     
     matrix.RowCol(2, 2) = -(far + near) / (far - near);
     matrix.RowCol(2, 3) = -2 * far * near / (far - near);
     
     matrix.RowCol(3, 2) = -1;
     
     return matrix;
 }
void ModelViewerRender::RenderParticleEmitter()
{
	for(uint32 i=0;i<m_pModelMF1->m_Header.m_iNumParticles;++i)
	{
		Matrix4x4 matrix;
		uint32 nBoneCount=m_pModelMF1->m_iNumBones;
		uint32 boneID=m_pModelMF1->m_pParticleEmitter[i].m_iAttachBoneID;
	//	if(boneID>=nBoneCount) continue;
		if(m_pDynamicModel!=NULL)
		{
			float* pBuffer=m_pDynamicModel->getBonesMatrix();
			Matrix4x4 boneMatrix;
			boneMatrix.Identity();
			boneMatrix._11=pBuffer[12*boneID];
			boneMatrix._21=pBuffer[12*boneID+1];
			boneMatrix._31=pBuffer[12*boneID+2];
			boneMatrix._41=pBuffer[12*boneID+3];
			boneMatrix._12=pBuffer[12*boneID+4];
			boneMatrix._22=pBuffer[12*boneID+5];
			boneMatrix._32=pBuffer[12*boneID+6];
			boneMatrix._42=pBuffer[12*boneID+7];
			boneMatrix._13=pBuffer[12*boneID+8];
			boneMatrix._23=pBuffer[12*boneID+9];
			boneMatrix._33=pBuffer[12*boneID+10];
			boneMatrix._43=pBuffer[12*boneID+11];
			matrix=m_pModelMF1->m_pParticleEmitter[i].m_AbsoluteMatrix*boneMatrix*m_pDynamicModel->getModelMatrix();
		}
		if(m_pStaticModel!=NULL)
		{
			matrix=m_pModelMF1->m_pParticleEmitter[i].m_AbsoluteMatrix*m_pStaticModel->getModelMatrix();
		}
		if(m_pStaticModel!=NULL||m_pDynamicModel!=NULL)
		{
			AABBox aabox=m_pModelMF1->m_MeshAABBox;
			float length=(aabox.vcMax-aabox.vcMin).GetLength();
			length*=0.02f;

			if((int)(i+1)==ModelViewerConfig::GetInstance()->m_nCurrSelParticle)
				m_pRenderDevice->GetVertexCacheManager()->RenderCone(matrix,length,-length,4,Colour(255,0,0));
			else
				m_pRenderDevice->GetVertexCacheManager()->RenderCone(matrix,length,-length,4,Colour(255,255,255));
		}
	}
}
void
BasicContainerLayer::ComputeEffectiveTransforms(const Matrix4x4& aTransformToSurface)
{
  // We push groups for container layers if we need to, which always
  // are aligned in device space, so it doesn't really matter how we snap
  // containers.
  Matrix residual;
  Matrix4x4 idealTransform = GetLocalTransform() * aTransformToSurface;
  idealTransform.ProjectTo2D();

  if (!idealTransform.CanDraw2D()) {
    mEffectiveTransform = idealTransform;
    ComputeEffectiveTransformsForChildren(Matrix4x4());
    ComputeEffectiveTransformForMaskLayer(Matrix4x4());
    mUseIntermediateSurface = true;
    return;
  }

  mEffectiveTransform = SnapTransformTranslation(idealTransform, &residual);
  // We always pass the ideal matrix down to our children, so there is no
  // need to apply any compensation using the residual from SnapTransformTranslation.
  ComputeEffectiveTransformsForChildren(idealTransform);

  ComputeEffectiveTransformForMaskLayer(aTransformToSurface);

  Layer* child = GetFirstChild();
  bool hasSingleBlendingChild = false;
  if (!HasMultipleChildren() && child) {
    hasSingleBlendingChild = child->GetMixBlendMode() != CompositionOp::OP_OVER;
  }

  /* If we have a single childand it is not blending,, it can just inherit our opacity,
   * otherwise we need a PushGroup and we need to mark ourselves as using
   * an intermediate surface so our children don't inherit our opacity
   * via GetEffectiveOpacity.
   * Having a mask layer always forces our own push group
   * Having a blend mode also always forces our own push group
   */
  mUseIntermediateSurface =
    GetMaskLayer() ||
    GetForceIsolatedGroup() ||
    (GetMixBlendMode() != CompositionOp::OP_OVER && HasMultipleChildren()) ||
    (GetEffectiveOpacity() != 1.0 && (HasMultipleChildren() || hasSingleBlendingChild));
}
Exemple #23
0
gfx::IntRect
ComputeBackdropCopyRect(const gfx::Rect& aRect,
                        const gfx::IntRect& aClipRect,
                        const gfx::Matrix4x4& aTransform,
                        const gfx::IntRect& aRenderTargetRect,
                        gfx::Matrix4x4* aOutTransform,
                        gfx::Rect* aOutLayerQuad)
{
  // Compute the clip.
  IntPoint rtOffset = aRenderTargetRect.TopLeft();
  IntSize rtSize = aRenderTargetRect.Size();

  gfx::IntRect renderBounds(0, 0, rtSize.width, rtSize.height);
  renderBounds.IntersectRect(renderBounds, aClipRect);
  renderBounds.MoveBy(rtOffset);

  // Apply the layer transform.
  RectDouble dest = aTransform.TransformAndClipBounds(
    RectDouble(aRect.x, aRect.y, aRect.width, aRect.height),
    RectDouble(renderBounds.x, renderBounds.y, renderBounds.width, renderBounds.height));
  dest -= rtOffset;

  // Ensure we don't round out to -1, which trips up Direct3D.
  dest.IntersectRect(dest, RectDouble(0, 0, rtSize.width, rtSize.height));

  if (aOutLayerQuad) {
    *aOutLayerQuad = Rect(dest.x, dest.y, dest.width, dest.height);
  }

  // Round out to integer.
  IntRect result;
  dest.RoundOut();
  dest.ToIntRect(&result);

  // Create a transform from adjusted clip space to render target space,
  // translate it for the backdrop rect, then transform it into the backdrop's
  // uv-space.
  Matrix4x4 transform;
  transform.PostScale(rtSize.width, rtSize.height, 1.0);
  transform.PostTranslate(-result.x, -result.y, 0.0);
  transform.PostScale(1 / float(result.width), 1 / float(result.height), 1.0);
  *aOutTransform = transform;
  return result;
}
Exemple #24
0
BoundingBox appProjectActor (Actor3D *actor, Camera *camera,
                             Float viewX, Float viewY, Float viewW, Float viewH)
{
  //Get the transformation matrix
  Matrix4x4 world = actor->getGlobalMatrix();
  Matrix4x4 modelview = camera->getGlobalMatrix().affineNormalize().affineInverse();
  Matrix4x4 projection = camera->getProjection( viewW, viewH );
  Matrix4x4 m = projection * modelview * world;

  //Get corners of the bounding box
  BoundingBox bboxActor = actor->getBoundingBox();
  Vector3 bboxCorners[8];
  bboxActor.getCorners( bboxCorners );

  //Project each corner into viewport
  BoundingBox bboxOut;
  for (Uint c=0; c<8; ++c)
  {
    //Projection and perspective division
    Vector4 p = m.transformPoint( bboxCorners[ c ].xyz(1.0f) );
    p /= p.w;

    //Apply view
    Vector3 v;
    v.x = (Float)viewX + (0.5f * p.x + 0.5f) * (Float)viewW;
    v.y = (Float)viewY + (0.5f * p.y + 0.5f) * (Float)viewH;
    v.z = 1.0f - (0.5f * p.z + 0.5f);

    //Find projected bounds
    if (c==0) bboxOut.min = bboxOut.max = v;
    else {

      if (v.x < bboxOut.min.x) bboxOut.min.x = v.x;
      if (v.y < bboxOut.min.y) bboxOut.min.y = v.y;
      if (v.z < bboxOut.min.z) bboxOut.min.z = v.z;

      if (v.x > bboxOut.max.x) bboxOut.max.x = v.x;
      if (v.y > bboxOut.max.y) bboxOut.max.y = v.y;
      if (v.z > bboxOut.max.z) bboxOut.max.z = v.z;
    }
  }

  return bboxOut;
}
Exemple #25
0
void SimpleGLWindow::Redraw(bool andSwap) {
	DrawChecker();

	if (tw_ == 0 && th_ == 0) {
		if (andSwap) {
			Swap();
		}
		return;
	}

	if (flags_ & ALPHA_BLEND) {
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glBlendEquation(GL_FUNC_ADD);
	} else {
		glDisable(GL_BLEND);
	}
	glViewport(0, 0, w_, h_);
	glScissor(0, 0, w_, h_);

	glBindTexture(GL_TEXTURE_2D, tex_);
	glsl_bind(drawProgram_);

	float fw, fh;
	float x, y;
	GetContentSize(x, y, fw, fh);

	const float pos[12] = {x,y,0, x+fw,y,0, x+fw,y+fh,0, x,y+fh,0};
	static const float texCoords[8] = {0,0, 1,0, 1,1, 0,1};
	static const float texCoordsFlipped[8] = {0,1, 1,1, 1,0, 0,0};
	static const GLubyte indices[4] = {0,1,3,2};

	Matrix4x4 ortho;
	ortho.setOrtho(0, (float)w_, (float)h_, 0, -1, 1);
	glUniformMatrix4fv(drawProgram_->u_viewproj, 1, GL_FALSE, ortho.getReadPtr());
	glVertexAttribPointer(drawProgram_->a_position, 3, GL_FLOAT, GL_FALSE, 12, pos);
	glVertexAttribPointer(drawProgram_->a_texcoord0, 2, GL_FLOAT, GL_FALSE, 8, tflipped_ ? texCoordsFlipped : texCoords);
	glActiveTexture(GL_TEXTURE0);
	glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, indices);

	if (andSwap) {
		Swap();
	}
}
Exemple #26
0
void
AppendToString(std::stringstream& aStream, const Matrix4x4& m,
               const char* pfx, const char* sfx)
{
  if (m.Is2D()) {
    Matrix matrix = m.As2D();
    AppendToString(aStream, matrix, pfx, sfx);
    return;
  }

  aStream << pfx;
  aStream << nsPrintfCString(
    "[ %g %g %g %g; %g %g %g %g; %g %g %g %g; %g %g %g %g; ]",
    m._11, m._12, m._13, m._14,
    m._21, m._22, m._23, m._24,
    m._31, m._32, m._33, m._34,
    m._41, m._42, m._43, m._44).get();
  aStream << sfx;
}
Exemple #27
0
Matrix4x4 Frame::GetTransformationMatrix(const Date& t, const Frame& ref) const
{
	Matrix4x4 transform = Matrix4x4::Zero;

	Vector3 x = AxisX(t, ref);
	Vector3 y = AxisY(t, ref);
	Vector3 z = AxisZ(t, ref);

	for(int row = 0; row < 3; row++)
	{
		transform.Set(row, 0, x[row]);
		transform.Set(row, 1, y[row]);
		transform.Set(row, 2, z[row]);
	}

	transform.Set(3, 3, 1.0);

	return transform;
}
Exemple #28
0
void ArbitraryRotate(Vec3 U, Vec3 V, Vec3 W, double degreeX, double degreeY, Vec3& point, Vec3 aim) {
  double cx=cos(PI*degreeX/180);
  double sx=sin(PI*degreeX/180);
  double cy=cos(PI*degreeY/180);
  double sy=sin(PI*degreeY/180); 

  Matrix4x4 trans(1, 0, 0, -aim[0],
		  0, 1, 0, -aim[1],
		  0, 0, 1, -aim[2],
		  0, 0, 0, 1);

  Matrix4x4 mat(U[0], U[1], U[2], 0,
		V[0], V[1], V[2], 0,
		W[0], W[1], W[2], 0,
		0, 0, 0, 1);

  Matrix4x4 rot;
  Vec4 pos(point[0], point[1], point[2], 1);

  pos = trans*pos;

  pos = mat*pos;

  rot.set(1,   0,  0, 0,
	  0,  cx, sx, 0,
	  0, -sx, cx, 0,
	  0,   0,  0, 1);

  pos = rot*pos;

  rot.set( cy, 0, sy, 0,
	   0, 1,  0, 0,
	   -sy, 0, cy, 0,
	   0, 0,  0, 1);

  pos = rot*pos;

  pos = mat.inv()*pos;

  pos = trans.inv()*pos;

  point.set(pos[0], pos[1], pos[2]);
}
void CalculateDirectionalLight(Vertex_VCN *pVertices, int num_vertices, Vector4 &light_direction, Vector4 &light_color)
{
	for ( int i=0; i<num_vertices; i++ )
	{
		Vector4 normal = g_world_matrix.RotateVector(pVertices[i].m_Normal);
		Vector4 intensity = VectorDot(normal, light_direction);
		intensity.Abs();
		pVertices[i].m_Color = intensity * light_color;
	}
}
Exemple #30
0
void NativeRender()
{
	EnableFZ();
	glstate.depthWrite.set(GL_TRUE);
	glstate.colorMask.set(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

	// Clearing the screen at the start of the frame is an optimization for tiled mobile GPUs, as it then doesn't need to keep it around between frames.
	glClearColor(0,0,0,1);
	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

	glstate.Restore();
	glViewport(0, 0, pixel_xres, pixel_yres);
	Matrix4x4 ortho;
	ortho.setOrtho(0.0f, dp_xres, dp_yres, 0.0f, -1.0f, 1.0f);
	glsl_bind(UIShader_Get());
	glUniformMatrix4fv(UIShader_Get()->u_worldviewproj, 1, GL_FALSE, ortho.getReadPtr());

	screenManager->render();
}