Beispiel #1
0
void applyRotationalMapping(QPainterPath& linePath, const CLLineEnding* ending, QPointF point, QPointF second)
{
  if (!ending->getIsEnabledRotationalMapping())
    return;

  QPointF directionVector(point.x() - second.x(), point.y() - second.y());
  directionVector = normalizePoint(directionVector);

  if (directionVector.x() == 0 && directionVector.y() == 0)
    return;

  QPointF orthogonlVector;

  if (directionVector.x() == 0)
    orthogonlVector = QPointF(directionVector.y(), 0);
  else
    orthogonlVector = QPointF(-directionVector.y() * directionVector.x(),
                              1 - directionVector.y() * directionVector.y());

  orthogonlVector = normalizePoint(orthogonlVector);

  QTransform rotateMatrix(directionVector.x(), directionVector.y(), orthogonlVector.x(),
                          orthogonlVector.y(), 0, 0);

  linePath = rotateMatrix.map(linePath);
}
Beispiel #2
0
ActionLabel::ActionLabel(QWidget *parent)
    : QLabel(parent)
{
    int iconSize=Icon::dlgIconSize();
    int labelSize=Icon::stdSize((int)((iconSize*1.333333333)+0.5));

    setMinimumSize(labelSize, labelSize);
    setMaximumSize(labelSize, labelSize);
    setAlignment(Qt::AlignCenter);

    if(0==theUsageCount++) {
        QImage img(Icons::self()->audioFileIcon.pixmap(iconSize, iconSize).toImage());
        double increment=360.0/constNumIcons;

        for(int i=0; i<constNumIcons; ++i) {
            theIcons[i]=new QPixmap(QPixmap::fromImage(0==i ? img
                                                            : img.transformed(rotateMatrix(img.width(), img.height(), increment*i),
                                                                              Qt::SmoothTransformation)));
        }
    }

    setPixmap(*theIcons[0]);
    timer=new QTimer(this);
    connect(timer, SIGNAL(timeout()), SLOT(rotateIcon()));
}
Beispiel #3
0
int matchMatrixRotated(Matrix *subject, Matrix *pattern) {
    for (int i = 0; i < 4; ++i) {
        if (matchMatrix(*subject, *pattern))
            return 1;
        rotateMatrix(pattern);
    }
    return 0;
}
Beispiel #4
0
void test(int size)
{
    std::vector<std::vector<int>> m(size, std::vector<int>(size, 0));
    for(unsigned r = 0; r < size; ++r){
        for(unsigned c = 0; c < size; ++c){
            m[r][c] = size * r + c + 1;
        }
    }

    std::cout << rotateMatrix(m) << std::endl;
}
Beispiel #5
0
int main() {
    Pixel matrix[N][N];
    int val = 1;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            matrix[i][j] = Pixel(val++);
        }
    }
    printMatrix(matrix);
    std::cout << "Rotate 90 degrees clockwise." << std::endl;
    rotateMatrix(matrix);
    printMatrix(matrix);
    return 0;
}
//
// 根据输入的平移, 旋转, 缩放分量创建出位置变换矩阵.
//
void FairyEditorFrame::BuildTransformMatrix(Ogre::Matrix4& Matrix,  const Ogre::Vector3& position, const Ogre::Quaternion rotate, const Ogre::Vector3 scale)
{

	Ogre::Matrix4 posMatrix;
	Ogre::Matrix4 scaleMatrix;
	Ogre::Matrix4 rotateMatrix(rotate);

	posMatrix = Ogre::Matrix4::IDENTITY;
	posMatrix.setTrans(position);

	scaleMatrix = Ogre::Matrix4::IDENTITY;
	scaleMatrix.setScale(scale);

	// 最终的变换矩阵.	
	Matrix = posMatrix * rotateMatrix * scaleMatrix;


}
Beispiel #7
0
int main(){
	int array[LENGTH][LENGTH];

	// generates the 1,2,3,4,5,6,7,8,9
	for(int i = 0; i < LENGTH; i++)
		for(int j = 0; j< LENGTH;j++)
			array[i][j] = (j+1)+3*i; 

	printf("Original matrix:\n");
	printMatrix(array);
	
	printf("\nRotating with return:\n");
	printMatrixPointer(returnRotateMatrix(array));

	printf("\nRotating with void:\n");
	rotateMatrix(array);
	printMatrix(array);
}
Beispiel #8
0
//-----------------------------------------------------------------------------
//!	描画
//-----------------------------------------------------------------------------
void EnemyBase::Render(bool isShadow)
{
	// 死亡フラグが立っていたら処理しない
	if( _isDead ) return;
	// カリングされるかどうか
	Sphere hitSphere = *_myCollision.getHitSphere();
	if (GmRender()->isRender(hitSphere)) return;

	// 移動用マトリックス
	Matrix	offsetMatrix(_pTaskModel->getWorldMatrix());
	offsetMatrix = offsetMatrix.translate(_position);
	Matrix rotateMatrix(_pTaskModel->getRotateMatrix());
	rotateMatrix = rotateMatrix.rotateY(Degree(_rotation._y) );
	_pTaskModel->setWorldMatrix(offsetMatrix);
	_pTaskModel->setRotateMatrix(rotateMatrix);
	
	_pTaskModel->render(isShadow);
}
int main()
{
	int matrix[4][4] = {
		{1, 2, 3, 4},
		{5, 6, 7, 8},
		{9, 10, 11, 12},
		{13, 14, 15, 16}
	};
	rotateMatrix(matrix, 4);
	for (int i = 0; i < 4; ++i)
	{
		for (int j = 0; j < 4; ++j)
		{
			printf("%d ", matrix[i][j]);
		}
		printf("\n");
	}
	return 0;
}
Matrix generateTransform(const TwoPoints *source, const TwoPoints *dest, int reflect){
    double sourceMidX = (source->x1 + source->x2)*0.5;
    double sourceMidY = (source->y1 + source->y2)*0.5;
    double destMidX = (dest->x1 + dest->x2)*0.5;
    double destMidY = (dest->y1 + dest->y2)*0.5;
    Matrix translate1 = translateMatrix(-sourceMidX, -sourceMidY); /* translate the left point to the origin */
    Matrix translate2 = translateMatrix(destMidX, destMidY); /* translate the origin to the left destination */

    /* compute the scale that needs to be applyed to the image */
    double sdist = sqrt(SQR(source->x1 - source->x2) + SQR(source->y1 - source->y2));
    double ddist = sqrt(SQR(dest->x1 - dest->x2) + SQR(dest->y1 - dest->y2));
    double s = ddist/sdist; 
    Matrix scale = scaleMatrix(s);

    /* compute the rotation that needs to be applyed to the image */
    double stheta = atan((source->y2 -source->y1)/(source->x2 - source->x1));
    double dtheta = atan((dest->y2 -dest->y1)/(dest->x2 - dest->x1));
    double theta  = dtheta - stheta;
    Matrix rotate = rotateMatrix(theta);

    /* compute the reflection if nessicary */
    Matrix reflection = reflectMatrix(reflect,0);

    /* build the final transformation */
    Matrix tmp1 = multiplyMatrix(scale, translate1);
    Matrix tmp2 = multiplyMatrix(rotate, tmp1);
    Matrix tmp3 = multiplyMatrix(reflection, tmp2);
    Matrix transform = multiplyMatrix(translate2,tmp3);

    /* free temporary matricies */
    freeMatrix(translate1);
    freeMatrix(translate2);
    freeMatrix(scale);
    freeMatrix(rotate);
    freeMatrix(reflection);
    freeMatrix(tmp1);
    freeMatrix(tmp2);
    freeMatrix(tmp3);

    /* return final transformation */
    return transform;
}
Beispiel #11
0
CActionLabel::CActionLabel(QWidget *parent)
            : QLabel(parent)
{
    static const int constIconSize(48);

    setMinimumSize(constIconSize, constIconSize);
    setMaximumSize(constIconSize, constIconSize);
    setAlignment(Qt::AlignCenter);

    if(0==theUsageCount++)
    {
        QImage img(KIconLoader::global()->loadIcon("application-x-font-ttf", KIconLoader::NoGroup, 32).toImage());
        double increment=360.0/constNumIcons;

        for(int i=0; i<constNumIcons; ++i)
            theIcons[i]=new QPixmap(QPixmap::fromImage(0==i ? img : img.transformed(rotateMatrix(img.width(), img.height(), increment*i))));
    }

    setPixmap(*theIcons[0]);
    itsTimer=new QTimer(this);
    connect(itsTimer, SIGNAL(timeout()), SLOT(rotateIcon()));
}
Beispiel #12
0
int main(int argc, char** argv) {
    FILE* fp;
    if(argc != 2) {
        printf("USAGE: MatrixRotation <fileContainingTestVectors>\n");
        return 1;
    }
    fp = fopen(argv[1], "r");
    if(fp == NULL) {
        printf("Failed to open the input file '%s' for reading!\n", argv[1]);
        return 2;
    }
    while(!feof(fp)) {
        int len = readMatrix(fp);
        if(len <= 0) {
            continue;
        }
        int dim = squareRoot(len);
        rotateMatrix(dim);
        printMatrix(len);
    }
    fclose(fp);
    return 0;
}
Beispiel #13
0
int main()
{
    /*
     * Test case
     *
     * Null matrix, 5x5 matrix
     */
    int a[N][N] = {{1,2,3,4,5},{6,7,8,9,10},{11,12,13,14,15},{16,17,18,19,20},{21,22,23,24,25}};
    print2DArray(a);

    printf("\nRotation by line: \n");

    // Rotate by line
    rotateMatrix(a);
    print2DArray(a);

    printf("\nRotation by number: \n");

    // Rotate by line
    rotateMatrix2(a);
    print2DArray(a);

    return 0;
}
void ObstacleCombinator::generateObstacleFromCurrentCluster(std::vector<ObstacleModel::Obstacle>& obstacles)
{
  Vector2<int>& c = currentCluster.cells[0];
  int xMin(c.x);
  int yMin(c.y);
  int xMax(c.x);
  int yMax(c.y);
  float rightAngle = 10.0;
  float leftAngle = -10.0;
  Vector2<int> rightCorner;
  Vector2<int> leftCorner;
  Vector2<> centerCells;
  Vector2<int> robotPosition(USObstacleGrid::GRID_LENGTH / 2, USObstacleGrid::GRID_LENGTH / 2);
  Vector2<int> closestPoint(USObstacleGrid::GRID_LENGTH, USObstacleGrid::GRID_LENGTH);
  int closestPointSqrDist(USObstacleGrid::GRID_SIZE * 2);
  for(unsigned int i = 0; i < currentCluster.cells.size(); ++i)
  {
    c = currentCluster.cells[i];
    centerCells.x += c.x;
    centerCells.y += c.y;
    Vector2<int> point(c.x - robotPosition.x, c.y - robotPosition.y);
    int sqrDistToRobot = sqr(point.x) + sqr(point.y);
    float angleToRobot = atan2(static_cast<float>(point.y), static_cast<float>(point.x));
    if(angleToRobot < rightAngle)
    {
      rightAngle = angleToRobot;
      rightCorner = Vector2<int>(c.x, c.y);
    }
    if(angleToRobot > leftAngle)
    {
      leftAngle = angleToRobot;
      leftCorner = Vector2<int>(c.x, c.y);
    }
    if(sqrDistToRobot < closestPointSqrDist)
    {
      closestPoint = c;
      closestPointSqrDist = sqrDistToRobot;
    }
    if(c.x < xMin)
      xMin = c.x;
    else if(c.x > xMax)
      xMax = c.x;
    if(c.y < yMin)
      yMin = c.y;
    else if(c.y > yMax)
      yMax = c.y;
  }
  centerCells /= static_cast<float>(currentCluster.cells.size());

  const float angleToCenterPoint = Geometry::angleTo(Pose2D(USObstacleGrid::GRID_LENGTH / 2, USObstacleGrid::GRID_LENGTH / 2), centerCells); //calculates the angle to the center of the cluster in grid coordinate system (independent of robot rotation)
  const float cosinus = cos(-angleToCenterPoint);
  const float sinus = sin(-angleToCenterPoint);
  float newX;
  float newY;

  //initializing of the rectangle
  float xMinRotated(FLT_MAX);
  float yMinRotated(FLT_MAX);
  float xMaxRotated(-FLT_MAX);
  float yMaxRotated(-FLT_MAX);

  for(unsigned int i = 0; i < currentCluster.cells.size(); ++i)
  {
    newX = cosinus * currentCluster.cells[i].x - sinus * currentCluster.cells[i].y; // rotates each cell of the cluster
    newY = sinus * currentCluster.cells[i].x + cosinus * currentCluster.cells[i].y;
    //sets new values for rectangle
    if(newX < xMinRotated)
      xMinRotated = newX;
    else if(newX > xMaxRotated)
      xMaxRotated = newX;
    if(newY < yMinRotated)
      yMinRotated = newY;
    else if(newY > yMaxRotated)
      yMaxRotated = newY;
  }

  Vector2<> closestPointWorld = gridToWorld(Vector2<>(closestPoint.x + 0.5f, closestPoint.y + 0.5f));
  Vector2<> centerWorld = gridToWorld(centerCells);

  //expansion (length of x- and y-axis through the center point) and orientation (dependent on robot rotation) of the cluster
  Vector3<> covarianceEllipse(((xMaxRotated - xMinRotated) * USObstacleGrid::CELL_SIZE) * parameters.covarianceFactor, ((yMaxRotated - yMinRotated) * USObstacleGrid::CELL_SIZE) * parameters.covarianceFactor, atan2(centerWorld.y, centerWorld.x));
  Matrix2x2<> covariance(covarianceEllipse.x, 0, 0, covarianceEllipse.y); // covariance is initialised with uncorrelated values (only expansion of cluster as variances)
  rotateMatrix(covariance, covarianceEllipse.z); // rotates the covariance so that it fits to the orientation and expansion of the cluster

  obstacles.push_back(ObstacleModel::Obstacle(gridToWorld(Vector2<>((float)(leftCorner.x), (float)(leftCorner.y))),
                      gridToWorld(Vector2<>((float)(rightCorner.x), (float)(rightCorner.y))), centerWorld, closestPointWorld,
                      static_cast<int>(currentCluster.cells.size()), covariance));
}
void DrawRoundedTriangle::execute(DrawStackArgList argList) {
	// set up geometry
	Vector2 position = *((Vector2*) argList["position"]);
	float rotation = *((float*) argList["rotation"]);
	Vector2 size = *((Vector2*) argList["size"]);

	float triangleHeight = cos(asin(size.x * gameGraphics->aspectRatio * 0.5f / size.y)) * size.y;
	float cutOutHeight = tan(asin(triangleHeight / size.y) - radians(45.0f)) * (size.x * gameGraphics->aspectRatio * 0.5f);

	std::vector<VertexEntry> triangleVertices;

	VertexEntry entry;
	entry.highlight = false;
	entry.concave = false;
	entry.curveOriginCoord = Vector2(0.0f, 0.0f);

	entry.position = Vector2(-size.x / 2.0f, -size.y / 2.0f + (size.y - triangleHeight));
	entry.primCoord = Vector2(
			cos(atan(triangleHeight / (size.x * (float) gameGraphics->aspectRatio / 2.0f)) + radians(90.0f)) * 2.0f,
			sin(atan(triangleHeight / (size.x * (float) gameGraphics->aspectRatio / 2.0f)) + radians(90.0f)) * 2.0f
		);
	triangleVertices.push_back(entry);

	entry.position = Vector2(0.0f, size.y / 2.0f);
	triangleVertices.push_back(entry);

	entry.position = Vector2(0.0f, -size.y / 2.0f + (size.y - (triangleHeight - cutOutHeight)));
	entry.primCoord = Vector2(
			entry.primCoord.x / 2.0f * (2.0f - sin(atan(size.x * (float) gameGraphics->aspectRatio / 2.0f / triangleHeight)) * (triangleHeight - cutOutHeight) / size.y * 2.0f),
			entry.primCoord.y / 2.0f * (2.0f - sin(atan(size.x * (float) gameGraphics->aspectRatio / 2.0f / triangleHeight)) * (triangleHeight - cutOutHeight) / size.y * 2.0f)
		);
	triangleVertices.push_back(entry);

	entry.position = Vector2(0.0f, size.y / 2.0f);
	entry.primCoord = Vector2(
			-cos(atan(triangleHeight / (size.x * (float) gameGraphics->aspectRatio / 2.0f)) + radians(90.0f)) * 2.0f,
			sin(atan(triangleHeight / (size.x * (float) gameGraphics->aspectRatio / 2.0f)) + radians(90.0f)) * 2.0f
		);
	triangleVertices.push_back(entry);

	entry.position = Vector2(size.x / 2.0f, -size.y / 2.0f + (size.y - triangleHeight));
	triangleVertices.push_back(entry);

	entry.position = Vector2(0.0f, -size.y / 2.0f + (size.y - (triangleHeight - cutOutHeight)));
	entry.primCoord = Vector2(
			entry.primCoord.x / 2.0f * (2.0f - sin(atan(size.x * (float) gameGraphics->aspectRatio / 2.0f / triangleHeight)) * (triangleHeight - cutOutHeight) / size.y * 2.0f),
			entry.primCoord.y / 2.0f * (2.0f - sin(atan(size.x * (float) gameGraphics->aspectRatio / 2.0f / triangleHeight)) * (triangleHeight - cutOutHeight) / size.y * 2.0f)
		);
	triangleVertices.push_back(entry);

	entry.curveOriginCoord = Vector2(0.0f, 1.0f);

	entry.position = Vector2(-size.x / 2.0f, -size.y / 2.0f + (size.y - triangleHeight));
	entry.primCoord = Vector2(-2.0f * size.x * (float) gameGraphics->aspectRatio / 2.0f / size.y, 1.0f - 2.0f * cos(asin(size.x * (float) gameGraphics->aspectRatio / 2.0f / size.y)));
	triangleVertices.push_back(entry);

	entry.position = Vector2(0.0f, -size.y / 2.0f + (size.y - (triangleHeight - cutOutHeight)));
	entry.primCoord = Vector2(0.0f, 1.0f - 2.0f * (triangleHeight - cutOutHeight) / size.y);
	triangleVertices.push_back(entry);

	entry.position = Vector2(0.0f, -size.y / 2.0f);
	entry.primCoord = Vector2(0.0f, -1.0f);
	triangleVertices.push_back(entry);

	entry.position = Vector2(0.0f, -size.y / 2.0f);
	entry.primCoord = Vector2(0.0f, -1.0f);
	triangleVertices.push_back(entry);

	entry.position = Vector2(0.0f, -size.y / 2.0f + (size.y - (triangleHeight - cutOutHeight)));
	entry.primCoord = Vector2(0.0f, 1.0f - 2.0f * (triangleHeight - cutOutHeight) / size.y);
	triangleVertices.push_back(entry);

	entry.position = Vector2(size.x / 2.0f, -size.y / 2.0f + (size.y - triangleHeight));
	entry.primCoord = Vector2(2.0f * size.x * (float) gameGraphics->aspectRatio / 2.0f / size.y, 1.0f - 2.0f * cos(asin(size.x * (float) gameGraphics->aspectRatio / 2.0f / size.y)));
	triangleVertices.push_back(entry);

	entry.position = Vector2(-size.x / 2.0f, -size.y / 2.0f);
	entry.primCoord = Vector2(-2.0f * size.x * (float) gameGraphics->aspectRatio / 2.0f / size.y, -1.0f);
	triangleVertices.push_back(entry);

	entry.position = Vector2(-size.x / 2.0f, -size.y / 2.0f + (size.y - triangleHeight));
	entry.primCoord = Vector2(-2.0f * size.x * (float) gameGraphics->aspectRatio / 2.0f / size.y, 1.0f - 2.0f * cos(asin(size.x * (float) gameGraphics->aspectRatio / 2.0f / size.y)));
	triangleVertices.push_back(entry);

	entry.position = Vector2(0.0f, -size.y / 2.0f);
	entry.primCoord = Vector2(0.0f, -1.0f);
	triangleVertices.push_back(entry);

	entry.position = Vector2(size.x / 2.0f, -size.y / 2.0f + (size.y - triangleHeight));
	entry.primCoord = Vector2(2.0f * size.x * (float) gameGraphics->aspectRatio / 2.0f / size.y, 1.0f - 2.0f * cos(asin(size.x * (float) gameGraphics->aspectRatio / 2.0f / size.y)));
	triangleVertices.push_back(entry);

	entry.position = Vector2(size.x / 2.0f, -size.y / 2.0f);
	entry.primCoord = Vector2(2.0f * size.x * (float) gameGraphics->aspectRatio / 2.0f / size.y, -1.0f);
	triangleVertices.push_back(entry);

	entry.position = Vector2(0.0f, -size.y / 2.0f);
	entry.primCoord = Vector2(0.0f, -1.0f);
	triangleVertices.push_back(entry);

	// apply rotation
	Matrix4 rotationMatrix; rotationMatrix.identity();
	scaleMatrix(gameGraphics->aspectRatio, 1.0f, 1.0f, rotationMatrix);
	rotateMatrix(Vector3(0.0f, 0.0f, 1.0f), radians(rotation), rotationMatrix);
	scaleMatrix(1.0f / gameGraphics->aspectRatio, 1.0f, 1.0f, rotationMatrix);

	for(int i = 0; i < triangleVertices.size(); ++i) {
		Vector4 oldPosition(triangleVertices[i].position.x, triangleVertices[i].position.y, 0.0f, 0.0f);
		oldPosition = oldPosition * rotationMatrix;
		triangleVertices[i].position = Vector2(oldPosition.x, oldPosition.y);
	}

	// update vertex buffers
	GLuint* triangleElementBufferArray = new GLuint[triangleVertices.size()];
	for(size_t i = 0; i < triangleVertices.size(); ++i)
		triangleElementBufferArray[i] = i;

	size_t triangleVertexBufferArraySize = triangleVertices.size() * 8;
	GLfloat* triangleVertexBufferArray = new GLfloat[triangleVertexBufferArraySize];

	for(size_t i = 0; i < triangleVertices.size(); ++i) {
		triangleVertexBufferArray[i * 8 + 0] = triangleVertices[i].position.x + position.x;
		triangleVertexBufferArray[i * 8 + 1] = triangleVertices[i].position.y + position.y;
		triangleVertexBufferArray[i * 8 + 2] = triangleVertices[i].primCoord.x;
		triangleVertexBufferArray[i * 8 + 3] = triangleVertices[i].primCoord.y;
		triangleVertexBufferArray[i * 8 + 4] = triangleVertices[i].curveOriginCoord.x;
		triangleVertexBufferArray[i * 8 + 5] = triangleVertices[i].curveOriginCoord.y;
		triangleVertexBufferArray[i * 8 + 6] = 2.0f - *((float*) argList["border"]) * 2.0f / (size.y / 2.0f * (float) gameGraphics->resolutionY);
		triangleVertexBufferArray[i * 8 + 7] = 2.0f;
	}

	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vertexBuffers["elements"]);

	glBufferData(GL_ELEMENT_ARRAY_BUFFER, triangleVertices.size() * sizeof(GLuint), triangleElementBufferArray,
			GL_STREAM_DRAW);

	delete[] triangleElementBufferArray;

	glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers["vertices"]);

	glBufferData(GL_ARRAY_BUFFER, triangleVertexBufferArraySize * sizeof(GLfloat), triangleVertexBufferArray,
			GL_STREAM_DRAW);

	delete[] triangleVertexBufferArray;

	// state
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glDisable(GL_CULL_FACE);
	glDisable(GL_DEPTH_TEST);
	if(gameGraphics->supportsMultisampling) glDisable(GL_MULTISAMPLE);
	glDisable(GL_SCISSOR_TEST);
	glDisable(GL_TEXTURE_2D);

	// enable shader
	glUseProgram(gameGraphics->getProgramID("hudContainer"));

	// set uniforms
	Vector4 insideColor = *((Vector4*) argList["insideColor"]);
	Vector4 borderColor = *((Vector4*) argList["borderColor"]);
	Vector4 outsideColor = *((Vector4*) argList["outsideColor"]);
	glUniform4f(glGetUniformLocation(gameGraphics->getProgramID("hudContainer"), "insideColor"), insideColor.x, insideColor.y, insideColor.z, insideColor.w);
	glUniform4f(glGetUniformLocation(gameGraphics->getProgramID("hudContainer"), "borderColor"), borderColor.x, borderColor.y, borderColor.z, borderColor.w);
	glUniform4f(glGetUniformLocation(gameGraphics->getProgramID("hudContainer"), "outsideColor"), outsideColor.x, outsideColor.y, outsideColor.z, outsideColor.w);
	glUniform1f(glGetUniformLocation(gameGraphics->getProgramID("hudContainer"), "softEdge"), *((float*) argList["softEdge"]) * 2.0f / (size.y / 2.0f * (float) gameGraphics->resolutionY));

	// draw the data stored in GPU memory
	glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers["vertices"]);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vertexBuffers["elements"]);

	glVertexAttribPointer(glGetAttribLocation(gameGraphics->getProgramID("hudContainer"), "position"), 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*) 0);
	glVertexAttribPointer(glGetAttribLocation(gameGraphics->getProgramID("hudContainer"), "primCoord"), 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*) (2 * sizeof(GLfloat)));
	glVertexAttribPointer(glGetAttribLocation(gameGraphics->getProgramID("hudContainer"), "curveOriginCoord"), 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*) (4 * sizeof(GLfloat)));
	glVertexAttribPointer(glGetAttribLocation(gameGraphics->getProgramID("hudContainer"), "border1Dist"), 1, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*) (6 * sizeof(GLfloat)));
	glVertexAttribPointer(glGetAttribLocation(gameGraphics->getProgramID("hudContainer"), "border2Dist"), 1, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*) (7 * sizeof(GLfloat)));

	glEnableVertexAttribArray(glGetAttribLocation(gameGraphics->getProgramID("hudContainer"), "position"));
	glEnableVertexAttribArray(glGetAttribLocation(gameGraphics->getProgramID("hudContainer"), "primCoord"));
	glEnableVertexAttribArray(glGetAttribLocation(gameGraphics->getProgramID("hudContainer"), "curveOriginCoord"));
	glEnableVertexAttribArray(glGetAttribLocation(gameGraphics->getProgramID("hudContainer"), "border1Dist"));
	glEnableVertexAttribArray(glGetAttribLocation(gameGraphics->getProgramID("hudContainer"), "border2Dist"));

	glDrawElements(GL_TRIANGLES, triangleVertices.size(), GL_UNSIGNED_INT, NULL);

	glDisableVertexAttribArray(glGetAttribLocation(gameGraphics->getProgramID("hudContainer"), "position"));
	glDisableVertexAttribArray(glGetAttribLocation(gameGraphics->getProgramID("hudContainer"), "primCoord"));
	glDisableVertexAttribArray(glGetAttribLocation(gameGraphics->getProgramID("hudContainer"), "curveOriginCoord"));
	glDisableVertexAttribArray(glGetAttribLocation(gameGraphics->getProgramID("hudContainer"), "border1Dist"));
	glDisableVertexAttribArray(glGetAttribLocation(gameGraphics->getProgramID("hudContainer"), "border2Dist"));
}
Beispiel #16
0
int Render_SSD(SCENE *ascene, CAMERA *acamera)
{
  /* We clear all pixels  */
  glClearColor(ascene->bcolor.rgba[0], ascene->bcolor.rgba[1],
	       ascene->bcolor.rgba[2], ascene->bcolor.rgba[3]);
  glClear (GL_COLOR_BUFFER_BIT);
  	int i,j;
	double matrixFinal[4][4],mTransform[4][4];
	double intermediaM[4][4],mCam[4][4],mInverse[4][4],tmpMatrix[4][4];
	double mTranslate[4][4],mRotate[4][4],mScale[4][4];
	double homo_coordinates[4] = {0,0,0,1};
	//double mInverse[4][4];
	
	matrixInitial(matrixFinal);
	matrixInitial(mTransform);
	matrixInitial(mTranslate);
	matrixInitial(mRotate);
	matrixInitial(mScale);
	
	int screenW = ascene->screen_w;
	int screenH = ascene->screen_h;

	buffer = (HIDDEN *)malloc(sizeof(HIDDEN) * screenW * screenH);


	for(i = 0;i < screenW * screenH;i++)
	{
		buffer[i].rgba[0] = ascene->bcolor.rgba[0];
		buffer[i].rgba[1] = ascene->bcolor.rgba[1];
		buffer[i].rgba[2] = ascene->bcolor.rgba[2];
		buffer[i].z = 9999;
	}

	/* Camera View */
	int ii;
	matrixInitial(mInverse);
	matrixInitial(tmpMatrix);
	matrixInitial(intermediaM);
	matrixInitial(mCam);
	double u[3],v[3],w[3];
	double gaze[3] = {acamera->gaze.xyzw[0],acamera->gaze.xyzw[1],acamera->gaze.xyzw[2]};
	double upVector[3] = {acamera->upVector.xyzw[0],acamera->upVector.xyzw[1],acamera->upVector.xyzw[2]};
	
	vecUnitization(gaze,w);

	for(ii = 0; ii < 3; ii++){
		w[ii] = -w[ii];
	}
	vecCross(upVector,w,u);
	vecUnitization(u,u);
	vecCross(w,u,v);
	ii = 0;
	for(ii = 0; ii < 3; ii++){
		intermediaM[0][ii] = u[ii];
		intermediaM[1][ii] = v[ii];
		intermediaM[2][ii] = w[ii];
		mCam[ii][3] = -acamera->eye.xyzw[ii];
	}	
	matrixMultiply(intermediaM,mCam,0);
	
	/*inverse  matrixMultiply() 0:normal  1:inverse */
	matrixInitial(intermediaM);
	ii = 0;
	for(ii = 0; ii < 3; ii++){
		intermediaM[ii][0] = u[ii];
		intermediaM[ii][1] = v[ii];
		intermediaM[ii][2] = w[ii];
		tmpMatrix[ii][3] = acamera->eye.xyzw[ii];
	}	
	matrixMultiply(mInverse,tmpMatrix,1);
	matrixMultiply(mInverse,intermediaM,1);


	/*Persective(1) and Orthographic(0) Projection matrix*/
	double anglePers, nearPers, farPers, rightOrtho, topOrtho, farOrtho, nearOrtho,pjType;
	double screenWidth,screenHeight;
	screenWidth = ascene->screen_w;
	screenHeight = ascene->screen_h;
	anglePers = ascene->persp.angle;
	nearPers = ascene->persp.near;
	farPers = ascene->persp.far; 
	rightOrtho = ascene->ortho.right;
	topOrtho = ascene->ortho.top;
	farOrtho = ascene->ortho.far; 
	nearOrtho = ascene->ortho.near;
	pjType = ascene->pjType;

	getFinalTransformMatrix(anglePers, nearPers, farPers, rightOrtho, topOrtho, farOrtho, nearOrtho, pjType, screenWidth, screenHeight, mCam, matrixFinal,mInverse);

	double vpInverse[4][4];
	matrixInitial(vpInverse);
	vpInverse[0][0] = (double)2/ascene->screen_w;
	vpInverse[0][3] = (double)(1-ascene->screen_w)/ascene->screen_w;
	vpInverse[1][1] = (double)2/ascene->screen_h;
	vpInverse[1][3] = (double)(1-ascene->screen_h)/ascene->screen_h;
	matrixMultiply(mInverse,vpInverse,1);

	/* Draw floor */
	double xmin,xmax,ymin,ymax,floorEdge;
	int nX,nY;

	xmin = ascene->floor.xmin;
	xmax = ascene->floor.xmax;
	ymin = ascene->floor.ymin;
	ymax = ascene->floor.ymax;
	floorEdge = ascene->floor.size;
	nY = ((xmax-xmin)/floorEdge) + 1;
	nX = ((ymax-ymin)/floorEdge) + 1;
	Line floor[nX + nY];
	
	glLineWidth(2);
	glBegin(GL_LINES);
	glColor3f(ascene->floor.color.rgba[0],ascene->floor.color.rgba[1],ascene->floor.color.rgba[2]);
	drawFloor(xmin,xmax,ymin,ymax,nX,nY,floorEdge,matrixFinal,floor);
	glEnd();

	/* draw axis*/
	glLineWidth(ascene->axis.width);
	glBegin(GL_LINES);
	if(ascene->isAxis == 1){
		double origin[4] = {0,0,0,1};
		double axisX[4] = {ascene->axis.length,0,0,1};
		double axisY[4] = {0,ascene->axis.length,0,1};
		double axisZ[4] = {0,0,ascene->axis.length,1};
		
		matrixApply(matrixFinal,origin);
		matrixApply(matrixFinal,axisX);
		matrixApply(matrixFinal,axisY);
		matrixApply(matrixFinal,axisZ);

		glColor3f(1,0,0);
		glVertex2d(origin[0]/origin[3],origin[1]/origin[3]);
		glVertex2d(axisX[0]/axisX[3],axisX[1]/axisX[3]);
		glColor3f(0,1,0);
		glVertex2d(origin[0]/origin[3],origin[1]/origin[3]);
		glVertex2d(axisY[0]/axisY[3],axisY[1]/axisY[3]);
		glColor3f(0,0,1);
		glVertex2d(origin[0]/origin[3],origin[1]/origin[3]);
		glVertex2d(axisZ[0]/axisZ[3],axisZ[1]/axisZ[3]);
	}
	glEnd();

	/* implement objects*/
	int nT = 0;
	int nR = 0;
	int nS = 0;
	int nM = 0;
	for(i = 0; i < ascene->nidentities; i++){
		matrixInitial(mTransform);
		for(j = 0; j < ascene->identities[i].inStr_num; j++){
			if(ascene->identities[i].instr[j] == TRANSLATE_KEY){
					matrixInitial(mTranslate);
					mTranslate[0][3] = ascene->translate[nT].xyz[0];
					mTranslate[1][3] = ascene->translate[nT].xyz[1];
					mTranslate[2][3] = ascene->translate[nT].xyz[2];
					matrixMultiply(mTranslate,mTransform,0);
					nT++;
			}
			else if(ascene->identities[i].instr[j] == ROTATE_KEY){
					double axis[3];
					axis[0] = ascene->rotate[nR].xyz[0];
					axis[1] = ascene->rotate[nR].xyz[1];
					axis[2] = ascene->rotate[nR].xyz[2];
					double Pi = 3.141592653;
					double radian = (ascene->rotate[nR].angle/(double)180) * Pi;
					rotateMatrix(axis,mRotate,mTransform,radian);
					nR++;
					
			}
			else if(ascene->identities[i].instr[j] == SCALE_KEY){
					matrixInitial(mScale);
					mScale[0][0] = ascene->scale[nS].xyz[0];
					mScale[1][1] = ascene->scale[nS].xyz[1];
					mScale[2][2] = ascene->scale[nS].xyz[2];
					matrixMultiply(mScale,mTransform,0);
					nS++;
			}
			else if(ascene->identities[i].instr[j] == MESH_KEY){			
					double tM[4][4];
					matrixInitial(tM);
					matrixMultiply(mTransform,tM,0);
					matrixMultiply(matrixFinal,tM,0);
					int k,l,d;

					/*apply transform matrix to all vertices in world coordinates*/
					COLOR_VERTEX colorVertices[ascene->mesh[nM].nvertices];
					for(k = 0; k < ascene->mesh[nM].nvertices; k++){
						colorVertices[k] = ascene->mesh[nM].vertices[k];
						matrixApply(mTransform,colorVertices[k].xyzw);
					}

					//flat shading
					if(ascene->mesh[nM].shading == 0){
						for(k = 0; k < ascene->mesh[nM].npolygons; k++){				
								COLOR_VERTEX vertices[3] = {colorVertices[ascene->mesh[nM].polygons[k].num[0]],
																						colorVertices[ascene->mesh[nM].polygons[k].num[1]],
																						colorVertices[ascene->mesh[nM].polygons[k].num[2]]};
								
								double normal[3]; 
								triangleNormal(vertices[0].xyzw,vertices[1].xyzw,vertices[2].xyzw,normal);
								double center[3];
								center[0] = (vertices[0].xyzw[0] + vertices[1].xyzw[0] + vertices[2].xyzw[0])/(double)3;
								center[1] = (vertices[0].xyzw[1] + vertices[1].xyzw[1] + vertices[2].xyzw[1])/(double)3;
								center[2] = (vertices[0].xyzw[2] + vertices[1].xyzw[2] + vertices[2].xyzw[2])/(double)3;
										Illumination(normal,ascene->mesh[nM].diffuse,ascene->mesh[nM].specular,center);	
	int i;
								for(i = 0; i < 3; i++){			matrixApply(matrixFinal,vertices[i].xyzw);
								}				
								toScreen(vertices[0].xyzw,vertices[1].xyzw,vertices[2].xyzw);								triRendering(vertices[0].xyzw,vertices[1].xyzw,vertices[2].xyzw,0,0,0,0,0,0,mInverse);

						}
					}

					//phong shading
					else if (ascene->mesh[nM].shading == 2){
						double vertex_normal[ascene->mesh[nM].nvertices][3];
						for(k = 0; k < ascene->mesh[nM].nvertices; k++){
						double composeNormal[3] = {0,0,0};
							for(l = 0; l < ascene->mesh[nM].npolygons; l++){
								for(d = 0; d < ascene->mesh[nM].polygons[l].nvertices; d++){
									if(ascene->mesh[nM].polygons[l].num[d] == k){
									COLOR_VERTEX vertices[3] = {colorVertices[ascene->mesh[nM].polygons[l].num[0]],
																								colorVertices[ascene->mesh[nM].polygons[l].num[1]],
																								colorVertices[ascene->mesh[nM].polygons[l].num[2]]};
									double normal[3];
										triangleNormal(vertices[0].xyzw,vertices[1].xyzw,vertices[2].xyzw,normal);
													composeNormal[0] += normal[0];
										composeNormal[1] += normal[1];
										composeNormal[2] += normal[2];
									}
								}
							}										vecUnitization(composeNormal,composeNormal);
						int i=0;			
						for(i = 0; i < 3; i++){
							colorVertices[k].rgba[i] = composeNormal[i];
							}
						}
	setBuffer(colorVertices,matrixFinal,nM,ascene->mesh[nM].diffuse,ascene->mesh[nM].specular,2,mInverse);				
					}
					//smooth shading
					else{
					   for(k = 0; k < ascene->mesh[nM].nvertices; k++){
						double composeNormal[3] = {0,0,0};
						for(l = 0; l < ascene->mesh[nM].npolygons; l++){
						   for(d = 0; d < ascene->mesh[nM].polygons[l].nvertices; d++){
																		       if(ascene->mesh[nM].polygons[l].num[d] == k){
							     COLOR_VERTEX vertices[3] = {colorVertices[ascene->mesh[nM].polygons[l].num[0]],
																								colorVertices[ascene->mesh[nM].polygons[l].num[1]],
																								colorVertices[ascene->mesh[nM].polygons[l].num[2]]};
							     double normal[3];
					triangleNormal(vertices[0].xyzw,vertices[1].xyzw,vertices[2].xyzw,normal);	
														composeNormal[0] += normal[0];								composeNormal[1] += normal[1];								composeNormal[2] += normal[2];
							  }
						      }
						  }
	vecUnitization(composeNormal,composeNormal);
	Illumination(composeNormal,ascene->mesh[nM].diffuse,ascene->mesh[nM].specular,colorVertices[k].xyzw);

	colorVertices[k].rgba[0] = illuColor[0];
	colorVertices[k].rgba[1] = illuColor[1];
	colorVertices[k].rgba[2] = illuColor[2];
						}	
	setBuffer(colorVertices,matrixFinal,nM,0,0,1,mInverse);		
					}
					glLineWidth(ascene->mesh[nM].width);
					glBegin(GL_POINTS);
					for(k = 0; k < ascene->screen_h; k++){
						for(l = 0; l < ascene->screen_w; l++){
						   	if(buffer[k*(ascene->screen_w)+l].z < 9999){										glColor3f(buffer[k*(ascene->screen_w) + l].rgba[0],buffer[k*(ascene->screen_w) + l].rgba[1],buffer[k*(ascene->screen_w) + l].rgba[2]);										glVertex2i(l,k);
							}
						} 					
					}
					glEnd();
					nM++;

			}		
		}
	}


  for(i = 0; i < ascene->nlines; i++){
	ascene->lines[i].vertices[0].xyzw[3] = 1;
	ascene->lines[i].vertices[1].xyzw[3] = 1;
	COLOR_VERTEX vertices[2];
	vertices[0] = ascene->lines[i].vertices[0];
	vertices[1] = ascene->lines[i].vertices[1];
	matrixApply(matrixFinal,vertices[0].xyzw);
	matrixApply(matrixFinal,vertices[1].xyzw);

	glLineWidth(ascene->lines[i].width);
	glBegin(GL_LINES);
	glColor3f(vertices[0].rgba[0],vertices[0].rgba[1],vertices[0].rgba[2]);
	glVertex2d(vertices[0].xyzw[0]/vertices[0].xyzw[3],vertices[0].xyzw[1]/vertices[0].xyzw[3]);
	glColor3f(vertices[1].rgba[0],vertices[1].rgba[1],vertices[1].rgba[2]);
	glVertex2d(vertices[1].xyzw[0]/vertices[1].xyzw[3],vertices[1].xyzw[1]/vertices[1].xyzw[3]);
	glEnd();
	}

  free(buffer);
  glFlush ();
  glutSwapBuffers();
  return 0;
}
void ShipRenderer::execute(DrawStackArgList arguments) {
	// state
	glDisable(GL_BLEND);
	glEnable(GL_CULL_FACE);
	glFrontFace(GL_CW);
	glEnable(GL_DEPTH_TEST);
	if(gameGraphics->supportsMultisampling) glEnable(GL_MULTISAMPLE);
	glDisable(GL_SCISSOR_TEST);
	glEnable(GL_TEXTURE_2D);

	// enable shader
	glUseProgram(gameGraphics->getProgramID("colorTextureLighting"));

	// set uniforms
	glUniform1i(glGetUniformLocation(gameGraphics->getProgramID("colorTextureLighting"), "texture"), 0);
	glUniform3f(glGetUniformLocation(gameGraphics->getProgramID("colorTextureLighting"), "ambientColor"), 0.15f, 0.15f, 0.15f);
	glUniform3f(glGetUniformLocation(gameGraphics->getProgramID("colorTextureLighting"), "diffuseColor"), 0.5f, 0.5f, 0.5f);
	glUniform3f(glGetUniformLocation(gameGraphics->getProgramID("colorTextureLighting"), "specularColor"), 0.8f, 0.8f, 0.8f);
	Vector4 lightPosition = Vector4(1.0f, 1.0f, -1.0f, 0.0f) * gameGraphics->currentCamera->lightMatrix;
	glUniform3f(glGetUniformLocation(gameGraphics->getProgramID("colorTextureLighting"), "lightPosition"), lightPosition.x, lightPosition.y, lightPosition.z);
	glUniform1f(glGetUniformLocation(gameGraphics->getProgramID("colorTextureLighting"), "shininess"), 10.0f);

	// set the overall drawing state
	glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers["vertices"]);

	glVertexAttribPointer(glGetAttribLocation(gameGraphics->getProgramID("colorTextureLighting"), "position"), 3, GL_FLOAT, GL_FALSE, 12 * sizeof(GLfloat), (GLvoid*) 0);
	glVertexAttribPointer(glGetAttribLocation(gameGraphics->getProgramID("colorTextureLighting"), "normal"), 3, GL_FLOAT, GL_FALSE, 12 * sizeof(GLfloat), (GLvoid*) (3 * sizeof(GLfloat)));
	glVertexAttribPointer(glGetAttribLocation(gameGraphics->getProgramID("colorTextureLighting"), "texCoord"), 2, GL_FLOAT, GL_FALSE, 12 * sizeof(GLfloat), (GLvoid*) (6 * sizeof(GLfloat)));
	glVertexAttribPointer(glGetAttribLocation(gameGraphics->getProgramID("colorTextureLighting"), "color"), 4, GL_FLOAT, GL_FALSE, 12 * sizeof(GLfloat), (GLvoid*) (8 * sizeof(GLfloat)));

	glEnableVertexAttribArray(glGetAttribLocation(gameGraphics->getProgramID("colorTextureLighting"), "position"));
	glEnableVertexAttribArray(glGetAttribLocation(gameGraphics->getProgramID("colorTextureLighting"), "normal"));
	glEnableVertexAttribArray(glGetAttribLocation(gameGraphics->getProgramID("colorTextureLighting"), "texCoord"));
	glEnableVertexAttribArray(glGetAttribLocation(gameGraphics->getProgramID("colorTextureLighting"), "color"));

	for(size_t i = 0; i < gameState->ships.size(); ++i) {
		// calculate the matrix for this ship position
		Matrix4 shipMatrix; shipMatrix.identity();
		rotateMatrix(Vector3(0.0f, 1.0f, 0.0f), radians(gameState->ships[i].rotation), shipMatrix);
		translateMatrix(gameState->ships[i].position.x, gameState->ships[i].position.y, gameState->ships[i].position.z, shipMatrix);

		Matrix4 mvMatrix = shipMatrix * gameGraphics->currentCamera->mvMatrix;
		float mvMatrixArray[] = {
				mvMatrix.m11, mvMatrix.m12, mvMatrix.m13, mvMatrix.m14,
				mvMatrix.m21, mvMatrix.m22, mvMatrix.m23, mvMatrix.m24,
				mvMatrix.m31, mvMatrix.m32, mvMatrix.m33, mvMatrix.m34,
				mvMatrix.m41, mvMatrix.m42, mvMatrix.m43, mvMatrix.m44
			};

		// draw the ship
		for(
				std::map<std::string, std::vector<Mesh::Face> >::iterator itr =
					shipMesh.faceGroups.begin();
				itr != shipMesh.faceGroups.end();
				++itr
			) {
			// don't draw the missile origin or submerged portion
			if(itr->first == "missileorigin" || itr->first == "submerged")
				continue;

			// set the texture
			glActiveTexture(GL_TEXTURE0);
			glBindTexture(GL_TEXTURE_2D, gameGraphics->getTextureID(std::string("structure/" + itr->first).c_str()));

			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

			glUniformMatrix4fv(glGetUniformLocation(gameGraphics->getProgramID("colorTextureLighting"), "mvMatrix"), 1, GL_FALSE, mvMatrixArray);
			glUniformMatrix4fv(glGetUniformLocation(gameGraphics->getProgramID("colorTextureLighting"), "pMatrix"), 1, GL_FALSE, (gameState->binoculars ? gameGraphics->ppBinoMatrixArray : gameGraphics->ppMatrixArray));

			// draw the geometry
			glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vertexBuffers[std::string("elements_" + itr->first).c_str()]);

			glDrawElements(GL_TRIANGLES, itr->second.size() * 3, GL_UNSIGNED_INT, NULL);
		}
	}

	glDisableVertexAttribArray(glGetAttribLocation(gameGraphics->getProgramID("colorTextureLighting"), "position"));
	glDisableVertexAttribArray(glGetAttribLocation(gameGraphics->getProgramID("colorTextureLighting"), "normal"));
	glDisableVertexAttribArray(glGetAttribLocation(gameGraphics->getProgramID("colorTextureLighting"), "texCoord"));
	glDisableVertexAttribArray(glGetAttribLocation(gameGraphics->getProgramID("colorTextureLighting"), "color"));
}
Beispiel #18
0
int cuda_objTest() {
	std::vector<Point> vertices1;
	const unsigned int numDimensions = 3;
	unsigned int numElements1 = loadObj("res/muscleman/obj/Kneel.000001.obj", &vertices1);
	//numElements1 = 5000;
	unsigned int numElements2 = numElements1;
	const unsigned int maxNumElements = std::max(numElements1, numElements2);

	std::vector<Point> vertices2;
	loadObj("res/muscleman/obj/Kneel.000001.obj", &vertices2);

	//static_assert(numElements1 == numElements2, "The number of points do not match!");
	float* pointList1[numElements1*numDimensions];
	float* pointList2[numElements1*numDimensions];
	for(unsigned int i = 0; i < numElements1; i++) {
		pointList1[i*numDimensions] = &vertices1[0].x;
		pointList1[i*numDimensions + 1] = &vertices1[0].y;
		pointList1[i*numDimensions + 2] = &vertices1[0].z;

		pointList2[i*numDimensions] = &vertices2[0].x;
		pointList2[i*numDimensions + 1] = &vertices2[0].y;
		pointList2[i*numDimensions + 2] = &vertices2[0].z;
	}
	
	float testRotation[9] = {1,0,0,0,0,-1,0,1,0};
	rotateMatrix(numElements1, *pointList2, testRotation);
	/*
	const unsigned int numElements1 = 8;
	const unsigned int numElements2 = 8;
	const unsigned int maxNumElements = std::max(numElements1, numElements2);

	const unsigned int numDimensions = 3;
	float* pointList1 = new float[numElements1*numDimensions];
	float* pointList2 = new float[numElements2*numDimensions];
// 2x1x1 cube
	pointList1[0 + 0] = 0; pointList1[0 + 1] = 0; pointList1[0 + 2] = 0;
	pointList1[3 + 0] = 2; pointList1[3 + 1] = 0; pointList1[3 + 2] = 0;
	pointList1[6 + 0] = 2; pointList1[6 + 1] = 1; pointList1[6 + 2] = 0;
	pointList1[9 + 0] = 0; pointList1[9 + 1] = 1; pointList1[9 + 2] = 0;
	pointList1[12 + 0] = 0; pointList1[12 + 1] = 0; pointList1[12 + 2] = 1;
	pointList1[15 + 0] = 2; pointList1[15 + 1] = 0; pointList1[15 + 2] = 1;
	pointList1[18 + 0] = 2; pointList1[18 + 1] = 1; pointList1[18 + 2] = 1;
	pointList1[21 + 0] = 0; pointList1[21 + 1] = 1; pointList1[21 + 2] = 1;

	// 1x1x2 cube
	pointList2[0 + 0] = 0; pointList2[0 + 1] = 0; pointList2[0 + 2] = 0;
	pointList2[3 + 0] = 0; pointList2[3 + 1] = 0; pointList2[3 + 2] = 2;
	pointList2[6 + 0] = 0; pointList2[6 + 1] = 1; pointList2[6 + 2] = 2;
	pointList2[9 + 0] = 0; pointList2[9 + 1] = 1; pointList2[9 + 2] = 0;
	pointList2[12 + 0] = -1; pointList2[12 + 1] = 0; pointList2[12 + 2] = 0;
	pointList2[15 + 0] = -1; pointList2[15 + 1] = 0; pointList2[15 + 2] = 2;
	pointList2[18 + 0] = -1; pointList2[18 + 1] = 1; pointList2[18 + 2] = 2;
	pointList2[21 + 0] = -1; pointList2[21 + 1] = 1; pointList2[21 + 2] = 0;
	*/

	// CUDA specific starting from here

	float** d_pointList1 = getDevicePointList1();
	float** d_pointList2 = getDevicePointList2();
	//float* d_pointList1;
	//float* d_pointList2;
	float centroid1[3] = {0,0,0};
	float centroid2[3] = {0,0,0};

	std::cout << "CUDA:" << std::endl;
	cuda_initPointLists(numElements1, numDimensions, *pointList1, *pointList2);

	cuda_downloadPointList(numElements1, numDimensions, *pointList1, *d_pointList1);
	cuda_downloadPointList(numElements2, numDimensions, *pointList2, *d_pointList2);

	/*
	std::cout << "CUDA (before translation):" << std::endl;
	std::cout << "First:" << std::endl;
	printMatrix(numElements1, numDimensions, *pointList1);
	std::cout << "Second:" << std::endl;
	printMatrix(numElements2, numDimensions, *pointList2);
	*/

	cuda_findOriginDistance(numElements1, numDimensions, *d_pointList1, centroid1);
	cuda_findOriginDistance(numElements2, numDimensions, *d_pointList2, centroid2);

	std::cout << "Centroids:" << std::endl;
	std::cout << centroid1[0] << " " << centroid1[1] << " " << centroid1[2] << std::endl;
	std::cout << centroid2[0] << " " << centroid2[1] << " " << centroid2[2] << std::endl;

	cuda_translate(numElements1, numDimensions, *d_pointList1, centroid1);
	cuda_translate(numElements2, numDimensions, *d_pointList2, centroid2);

	cuda_downloadPointList(numElements1, numDimensions, *pointList1, *d_pointList1);
	cuda_downloadPointList(numElements2, numDimensions, *pointList2, *d_pointList2);

/*
	std::cout << "CUDA (after translation):" << std::endl;
	std::cout << "First:" << std::endl;
	printMatrix(numElements1, numDimensions, *pointList1);
	std::cout << "Second:" << std::endl;
	printMatrix(numElements2, numDimensions, *pointList2);
	*/

	/*
	float pointList1Transposed[numElements1*numDimensions];
	memset(pointList1Transposed, 0, sizeof(float)*numElements1*numDimensions);

	float* d_pointList1Transposed;
	gpuErrchk(cudaMalloc(&d_pointList1Transposed, bytes1));
	gpuErrchk(cudaMemset(d_pointList1Transposed, 0, bytes1));

	kernel_transpose<<<gridSize, blockSize>>>(numElements1, numDimensions, d_pointList1, d_pointList1Transposed);

	cudaMemcpy(pointList1Transposed, d_pointList1Transposed, bytes1, cudaMemcpyDeviceToHost);

	std::cout << "First transposed:" << std::endl;
	printMatrix(numDimensions, numElements1, pointList1Transposed);
	
	cudaFree(d_pointList1Transposed);
	*/
	float covariance[numDimensions*numDimensions];
	memset(covariance, 0, sizeof(float)*numDimensions*numDimensions);
	cuda_findCovariance(maxNumElements, numDimensions, *d_pointList1, *d_pointList2, covariance);

	std::cout << "Covariance: " << std::endl;
	printMatrix(numDimensions, numDimensions, covariance);

	rotationMatrix rotation;
	svdMethod(numDimensions, covariance, rotation);

	for(unsigned int i = 0; i < numDimensions*numDimensions; i++) {
		rotation[i] = (rotation[i] < 0.0001 && rotation[i] > -0.0001)?0:rotation[i];
	}

	std::cout << "Rotation: " << std::endl;
	printMatrix(numDimensions, numDimensions, rotation);
	std::cout << "Num Elements: " << numElements1 << std::endl;
	
	cuda_destroyPointList(*d_pointList1);
	cuda_destroyPointList(*d_pointList2);

	return 0;
}