Example #1
0
void
Matrix::CreateRBT(const Vector &from, 
                  const Vector &at, 
                  const Vector &world_up)
{
    Vector up, right, view_dir;

    view_dir = (at - from).normalized();
    right    = (world_up % view_dir).normalized();
    up       = (view_dir % right).normalized();

    CreateIdentity();

    m[0][0] = right.x;
    m[0][1] = right.y;
    m[0][2] = right.z;
    m[1][0] = up.x;
    m[1][1] = up.y;
    m[1][2] = up.z;
    m[2][0] = view_dir.x;
    m[2][1] = view_dir.y;
    m[2][2] = view_dir.z;

    //
    // The matrix so far will put us in the local coordinate system...
    // We want the inverse of that.
    //
    Inverse();

    // Don't forget the translation
    m[0][3] = from.x;
    m[1][3] = from.y;
    m[2][3] = from.z;
}
Example #2
0
	mat3 mat3::InvertMatrix()
	{
		const JFloat determinant = GetDeterminant();
		mat3 inverse;
		if (determinant != JFloat(0.0))
		{
			const JFloat inverseDeterminant = 1.0f / determinant;

			inverse.column0.x = inverseDeterminant * (column1.y * column2.z - column2.y * column1.z);
			inverse.column0.y = inverseDeterminant *-(column0.y * column2.z - column2.y * column0.z);
			inverse.column0.z = inverseDeterminant * (column0.y * column1.z - column0.z * column1.y);
								 
			inverse.column1.x = inverseDeterminant *-(column1.x * column2.z - column1.z * column2.x);
			inverse.column1.y = inverseDeterminant * (column0.x * column2.z - column0.z * column2.x);
			inverse.column1.z = inverseDeterminant *-(column0.x * column1.z - column0.z * column1.x);
								
			inverse.column2.x = inverseDeterminant * (column1.x * column2.y - column1.y * column2.x);
			inverse.column2.y = inverseDeterminant *-(column0.x * column2.y - column0.y * column2.x);
			inverse.column2.z = inverseDeterminant * (column0.x * column1.y - column1.x * column0.y);

			return inverse;
		}
		else
		{
			return CreateIdentity();
		}
	}
Example #3
0
void
Matrix::CreateView(const Vector &from, 
                  const Vector &at, 
                  const Vector &world_up)
{
    Vector up, right, view_dir;

    view_dir = (at - from).normalized();
    right    = (world_up % view_dir).normalized();
    up       = (view_dir % right).normalized();

    CreateIdentity();

    m[0][0] = right.x;
    m[0][1] = right.y;
    m[0][2] = right.z;
    m[1][0] = up.x;
    m[1][1] = up.y;
    m[1][2] = up.z;
    m[2][0] = view_dir.x;
    m[2][1] = view_dir.y;
    m[2][2] = view_dir.z;

    m[0][3] = -(right*from);
    m[1][3] = -(up*from);
    m[2][3] = -(view_dir*from);
}
Example #4
0
void
Matrix::Inverse()
{
    Matrix n, y;
    int    i, j, indx[4];
    float  d, col[4];

    n=*this;
    if (ludcmp(&n, indx, &d)) {
        CreateIdentity();
        return;
    }

    for (j=0; j<4; j++) {
        for (i=0; i<4; i++) {
            col[i] = 0.0f;
        }
        col[j] = 1.0f;
        lubksb(&n, indx, col);
        for (i=0; i<4; i++) {
            y.m[i][j] = col[i];
        }
    }
    *this = y;
    return;
}
Example #5
0
void
Matrix::CreateTranslate(float x,float y,float z)
{
    CreateIdentity();
    m[0][3] = x;
    m[1][3] = y;
    m[2][3] = z;
}
Example #6
0
void
Matrix::CreateScale(float x,float y,float z)
{
    CreateIdentity();
    m[0][0] = x;
    m[1][1] = y;
    m[2][2] = z;
}
Example #7
0
void
Matrix::CreateScale(float s)
{
    CreateIdentity();
    m[0][0] = s;
    m[1][1] = s;
    m[2][2] = s;
}
Example #8
0
IdentityToken_t *ShareSystem::CreateCoreIdentity()
{
	if (!m_CoreType)
	{
		m_CoreType = CreateIdentType("CORE");
	}

	return CreateIdentity(m_CoreType, this);
}
Matrix3 Matrix3::CreateScale(const Vector3& scale)
{
	Matrix3 newMatrix = CreateIdentity();

	newMatrix.m_array[0][0] = scale.x;
	newMatrix.m_array[1][1] = scale.y;

	return newMatrix;
}
Matrix3 Matrix3::CreateTranslation(const Vector3& translation)
{
	Matrix3 newMatrix = CreateIdentity();

	newMatrix.m_array[2][0] = translation.x;
	newMatrix.m_array[2][1] = translation.y;
	newMatrix.m_array[2][2] = 1.0f;

	return newMatrix;
}
Example #11
0
Matrix2 Matrix2::setRotateZ(float rad)
{
	*this = CreateIdentity();

	m[0][0] = cosf(rad);
	m[0][1] = -sinf(rad);
	m[1][0] = sinf(rad);
	m[1][1] = cosf(rad);

	return *this;
}
Matrix3 Matrix3::CreateRotation(float angle)
{
	Matrix3 newMatrix = CreateIdentity();

	newMatrix.m_array[0][0] = cosf(angle);
	newMatrix.m_array[0][1] = sinf(angle);
	newMatrix.m_array[1][0] = -sinf(angle);
	newMatrix.m_array[1][1] = cosf(angle);

	return newMatrix;
}
Example #13
0
void
Matrix::CreateOrthographicProjection(float size,
                                     float near_plane,
                                     float far_plane,
                                     float aspect)
{
    float d;
    d = far_plane - near_plane;

    CreateIdentity();
    m[0][0] = 2./(size*aspect);
    m[1][1] = 2./size;
    m[2][2] = 1./d;
    m[2][3] = -near_plane/d;
    m[3][3] = 1;
}
Example #14
0
bool CExtension::Load(char *error, size_t maxlength)
{
	CreateIdentity();
	if (!m_pAPI->OnExtensionLoad(this, &g_ShareSys, error, maxlength, !smcore.IsMapLoading()))
	{
		DestroyIdentity();
		return false;
	}
	else
	{
		/* Check if we're past load time */
		if (!smcore.IsMapLoading())
		{
			m_pAPI->OnExtensionsAllLoaded();
		}
	}

	return true;
}
// Test a message send????
nsresult nsEudoraCompose::SendTheMessage(nsIFile *pMailImportLocation, nsIFile **pMsg)
{
  nsresult rv = CreateComponents();
  if (NS_SUCCEEDED( rv))
    rv = CreateIdentity();
  if (NS_FAILED( rv))
    return( rv);

  // IMPORT_LOG0( "Outlook Compose created necessary components\n");

  nsString bodyType;
  nsString charSet;
  nsString headerVal;
  GetHeaderValue( m_pHeaders, m_headerLen, "From:", headerVal);
  if (!headerVal.IsEmpty())
    m_pMsgFields->SetFrom( headerVal);
  GetHeaderValue( m_pHeaders, m_headerLen, "To:", headerVal);
  if (!headerVal.IsEmpty())
    m_pMsgFields->SetTo( headerVal);
  GetHeaderValue( m_pHeaders, m_headerLen, "Subject:", headerVal);
  if (!headerVal.IsEmpty())
    m_pMsgFields->SetSubject( headerVal);
  GetHeaderValue( m_pHeaders, m_headerLen, "Content-type:", headerVal);
  bodyType = headerVal;
  ExtractType( bodyType);
  ExtractCharset( headerVal);
  // Use platform charset as default if the msg doesn't specify one
  // (ie, no 'charset' param in the Content-Type: header). As the last
  // resort we'll use the mail default charset.
  // (ie, no 'charset' param in the Content-Type: header) or if the
  // charset parameter fails a length sanity check.
  // As the last resort we'll use the mail default charset.
  if ( headerVal.IsEmpty() || (headerVal.Length() > kContentTypeLengthSanityCheck) )
  {
    CopyASCIItoUTF16(nsMsgI18NFileSystemCharset(), headerVal);
    if (headerVal.IsEmpty())
    { // last resort
      if (m_defCharset.IsEmpty())
      {
        nsString defaultCharset;
        NS_GetLocalizedUnicharPreferenceWithDefault(nsnull, "mailnews.view_default_charset",
                                                    NS_LITERAL_STRING("ISO-8859-1"), defaultCharset);
        m_defCharset = defaultCharset;
      }
      headerVal = m_defCharset;
    }
  }
  m_pMsgFields->SetCharacterSet( NS_LossyConvertUTF16toASCII(headerVal).get() );
  charSet = headerVal;
  GetHeaderValue( m_pHeaders, m_headerLen, "CC:", headerVal);
  if (!headerVal.IsEmpty())
    m_pMsgFields->SetCc( headerVal);
  GetHeaderValue( m_pHeaders, m_headerLen, "Message-ID:", headerVal);
  if (!headerVal.IsEmpty())
    m_pMsgFields->SetMessageId( NS_LossyConvertUTF16toASCII(headerVal).get() );
  GetHeaderValue( m_pHeaders, m_headerLen, "Reply-To:", headerVal);
  if (!headerVal.IsEmpty())
    m_pMsgFields->SetReplyTo( headerVal);

  // what about all of the other headers?!?!?!?!?!?!
  char *pMimeType;
  if (!bodyType.IsEmpty())
    pMimeType = ToNewCString(bodyType);
  else
    pMimeType = ToNewCString(m_bodyType);

  // IMPORT_LOG0( "Outlook compose calling CreateAndSendMessage\n");
  nsMsgAttachedFile *pAttach = GetLocalAttachments();


  /*
    l10n - I have the body of the message in the system charset,
    I need to "encode" it to be the charset for the message
    *UNLESS* of course, I don't know what the charset of the message
    should be?  How do I determine what the charset should
    be if it doesn't exist?

  */

  nsString uniBody;
  NS_CopyNativeToUnicode( nsDependentCString(m_pBody), uniBody);

  nsCString body;

  rv = nsMsgI18NConvertFromUnicode( NS_LossyConvertUTF16toASCII(charSet).get(),
                                    uniBody, body);
  if (NS_FAILED( rv)) {
    // in this case, if we did not use the default compose
    // charset, then try that.
    if (!charSet.Equals( m_defCharset)) {
      body.Truncate();
      rv = nsMsgI18NConvertFromUnicode( NS_LossyConvertUTF16toASCII(charSet).get(),
                                        uniBody, body);
    }
  }
  uniBody.Truncate();


  // See if it's a draft msg (ie, no From: or no To: AND no Cc: AND no Bcc:).
  // Eudora saves sent and draft msgs in Out folder (ie, mixed) and it does
  // store Bcc: header in the msg itself.
  nsMsgDeliverMode mode = nsIMsgSend::nsMsgDeliverNow;
  nsAutoString from, to, cc, bcc;
  rv = m_pMsgFields->GetFrom(from);
  rv = m_pMsgFields->GetTo(to);
  rv = m_pMsgFields->GetCc(cc);
  rv = m_pMsgFields->GetBcc(bcc);
  if ( from.IsEmpty() || to.IsEmpty() && cc.IsEmpty() && bcc.IsEmpty() )
    mode = nsIMsgSend::nsMsgSaveAsDraft;

  // We only get the editor interface when there's embedded content.
  // Otherwise pEditor remains NULL. That way we only import with the pseudo
  // editor when it helps.
  nsRefPtr<nsEudoraEditor>  pEudoraEditor = new nsEudoraEditor(m_pBody, pMailImportLocation);
  nsCOMPtr<nsIEditor>       pEditor;

  if (pEudoraEditor->HasEmbeddedContent())
    // There's embedded content that we need to import, so query for the editor interface
    pEudoraEditor->QueryInterface( NS_GET_IID(nsIEditor), getter_AddRefs(pEditor) );

  if (NS_FAILED( rv)) {

    rv = m_pSendProxy->CreateAndSendMessage(
                          pEditor.get(),                // pseudo editor shell when there's embedded content
                          s_pIdentity,                  // dummy identity
                          nsnull,                       // account key
                          m_pMsgFields,                 // message fields
                          PR_FALSE,                     // digest = NO
                          PR_TRUE,                      // dont_deliver = YES, make a file
                          mode,                         // mode
                          nsnull,                       // no message to replace
                          pMimeType,                    // body type
                          m_pBody,                      // body pointer
                          m_bodyLen,                    // body length
                          nsnull,                       // remote attachment data
                          pAttach,                      // local attachments
                          nsnull,                       // related part
                          nsnull,                       // parent window
                          nsnull,                       // progress listener
                          m_pListener,                  // listener
                          nsnull,                       // password
                          EmptyCString(),               // originalMsgURI
                          nsnull);                      // message compose type

  }
  else {
    rv = m_pSendProxy->CreateAndSendMessage(
                          pEditor.get(),                // pseudo editor shell when there's embedded content
                          s_pIdentity,                  // dummy identity
                          nsnull,                       // account key
                          m_pMsgFields,                 // message fields
                          PR_FALSE,                     // digest = NO
                          PR_TRUE,                      // dont_deliver = YES, make a file
                          mode,                         // mode
                          nsnull,                       // no message to replace
                          pMimeType,                    // body type
                          body.get(),                   // body pointer
                          body.Length(),                // body length
                          nsnull,                       // remote attachment data
                          pAttach,                      // local attachments
                          nsnull,                       // related part
                          nsnull,                       // parent window
                          nsnull,                       // progress listener
                          m_pListener,                  // listener
                          nsnull,                       // password
                          EmptyCString(),               // originalMsgURI
                          nsnull);                      // message compose type

  }

  // IMPORT_LOG0( "Returned from CreateAndSendMessage\n");

  if (pAttach)
    delete [] pAttach;

  EudoraSendListener *pListen = (EudoraSendListener *)m_pListener;
  if (NS_FAILED( rv)) {
    IMPORT_LOG1( "*** Error, CreateAndSendMessage FAILED: 0x%lx\n", rv);
    // IMPORT_LOG1( "Headers: %80s\n", m_pHeaders);
  }
  else {
    // wait for the listener to get done!
    PRInt32 abortCnt = 0;
    PRInt32 cnt = 0;
    PRInt32 sleepCnt = 1;
    while (!pListen->m_done && (abortCnt < kHungAbortCount)) {
      PR_Sleep( sleepCnt);
      cnt++;
      if (cnt > kHungCount) {
        abortCnt++;
        sleepCnt *= 2;
        cnt = 0;
      }
    }

    if (abortCnt >= kHungAbortCount) {
      IMPORT_LOG0( "**** Create and send message hung\n");
      IMPORT_LOG1( "Headers: %s\n", m_pHeaders);
      IMPORT_LOG1( "Body: %s\n", m_pBody);
      rv = NS_ERROR_FAILURE;
    }

  }

  if (pMimeType)
    NS_Free( pMimeType);

  if (pListen->m_location) {
    pListen->m_location->Clone(pMsg);
    rv = NS_OK;
  }
  else {
    rv = NS_ERROR_FAILURE;
    IMPORT_LOG0( "*** Error, Outlook compose unsuccessful\n");
  }

  pListen->Reset();

  return( rv);
}
Example #16
0
	mat3 mat3::RotateMatrix(JFloat angle, JChar axis)
	{
		mat3 temp;

		if (axis == 'x' || axis == 'X')
		{
			//Rotate about the X axis when axis is equal to 1
			mat3 rotateByFloat(
				vec3(1.0f, 0.0f, 0.0f), 
				vec3(0.0f, j_Cos((angle * 3.141592653589793f) / 180.0f), j_Sin((angle * 3.141592653589793f) / 180.0f)),
				vec3(0.0f, -j_Sin((angle * 3.141592653589793f) / 180.0f), j_Cos((angle * 3.141592653589793f) / 180.0f)));

			temp = rotateByFloat;
			return temp;
		}

		if (axis == 'y' || axis == 'Y')
		{
			//Rotate about the Y axis when axis is equal to 2
			mat3 rotateByFloat(
				vec3(j_Cos((angle * 3.141592653589793f) / 180.0f), j_Sin((angle * 3.141592653589793f) / 180.0f), 0.0f), 
				vec3(-j_Sin((angle * 3.141592653589793f) / 180.0f), j_Cos((angle * 3.141592653589793f) / 180.0f), 0.0f), 
				vec3(0.0f, 0.0f, 1.0f));

			temp = rotateByFloat;
			return temp;
		}

		if (axis == 'z' || axis == 'Z')
		{
			//Rotate about the Z axis when axis is equal to 3
			mat3 rotateByFloat(
				vec3(j_Cos((angle * 3.141592653589793f) / 180.0f), 0.0f, -j_Sin((angle * 3.141592653589793f) / 180.0f)),
				vec3(0.0f, 1.0f, 0.0f),
				vec3(j_Sin((angle * 3.141592653589793f) / 180.0f), 0.0f, j_Cos((angle * 3.141592653589793f) / 180.0f)));
				
			temp = rotateByFloat;
			return temp;
		}

		return ((axis == 'x' || axis == 'X') || (axis == 'y' || axis == 'Y') || (axis == 'z' || axis == 'Z')) ? temp : CreateIdentity();
	}
Example #17
0
void
Matrix::CreateTrackball(float p1x,float p1y,  float p2x, float p2y)
{
#define RADIUS       0.8        /* z value at x = y = 0.0  */
#define COMPRESSION  3.5        /* multipliers for x and y */
#define AR3 (RADIUS*RADIUS*RADIUS)

    float   q[4];   // quaternion
    Vector  p1, p2; // pointer loactions on trackball
    Vector  axis;   // axis of rotation
    double  phi;    // rotation angle (radians)
    double  t;

    // Check for zero mouse movement
    if (p1x==p2x && p1y==p2y)
    {
        CreateIdentity();
        return;
    }


    // Compute z-coordinates for projection of P1 and P2 onto
    // the trackball.
    p1 = Vector(p1x, p1y, AR3/((p1x*p1x+p1y*p1y)*COMPRESSION+AR3));
    p2 = Vector(p2x, p2y, AR3/((p2x*p2x+p2y*p2y)*COMPRESSION+AR3));

    // Compute the axis of rotation and temporarily store it
    // in the quaternion.
    axis = (p2 % p1).normalized();

    // Figure how much to rotate around that axis.
    t = (p2 - p1).norm();
    t = MIN(MAX(t, -1.0), 1.0);
    phi = -2.0*asin(t/(2.0*RADIUS));

    axis *= sin(phi/2.0);
    q[0]  = axis.x;
    q[1]  = axis.y;
    q[2]  = axis.z;
    q[3]  = cos(phi/2.0);

    // normalize quaternion to unit magnitude
    t =  1.0 / sqrt(q[0]*q[0] + q[1]*q[1] + q[2]*q[2] + q[3]*q[3]);
    q[0] *= t;
    q[1] *= t;
    q[2] *= t;
    q[3] *= t;

    //q[2]*=-1;   //  This is needed in a LH coordinate system

    // create the rotation matrix from the quaternion
    CreateIdentity();

    m[0][0] = 1.0 - 2.0 * (q[1]*q[1] + q[2]*q[2]);
    m[0][1] = 2.0 * (q[0]*q[1] + q[2]*q[3]);
    m[0][2] = (2.0 * (q[2]*q[0] - q[1]*q[3]) );

    m[1][0] = 2.0 * (q[0]*q[1] - q[2]*q[3]);
    m[1][1] = 1.0 - 2.0 * (q[2]*q[2] + q[0]*q[0]);
    m[1][2] = (2.0 * (q[1]*q[2] + q[0]*q[3]) );

    m[2][0] = (2.0 * (q[2]*q[0] + q[1]*q[3]) );
    m[2][1] = (2.0 * (q[1]*q[2] - q[0]*q[3]) );
    m[2][2] = (1.0 - 2.0 * (q[1]*q[1] + q[0]*q[0]) );
}
Example #18
0
Matrix::Matrix()
{
    CreateIdentity();
}