Ejemplo n.º 1
0
void drawBouquet(float r, float g, float b)
{
	
	mvstack.push(model_view);
		model_view *= RotateX(-90);
		set_colour(r,g,b);
		drawCone();

		model_view *= RotateX(90);
		model_view *= Translate(0.0f, 2.0f, 0.0f);
		drawFlower();

		mvstack.push(model_view);
			model_view *= RotateZ(25);
			model_view *= Translate(-1.0f, 0.25f, 0.0f);
			drawFlower();
		model_view = mvstack.pop();

		mvstack.push(model_view);
			model_view *= RotateZ(-25);
			model_view *= Translate(1.0f, 0.25f, 0.0f);
			drawFlower();
		model_view = mvstack.pop();
	model_view = mvstack.pop();
}
Ejemplo n.º 2
0
void Joint::updateTransform(Animation *animation, int frameCounter, int &channelCounter)
{
	if(numChannels == 6)
	{
		Mat4f temp = Translate(animation->Frames[frameCounter].Tranformations[channelCounter], animation->Frames[frameCounter].Tranformations[channelCounter + 1], animation->Frames[frameCounter].Tranformations[channelCounter + 2]);
		TLocal = temp; 

		////so animations stay in one spot
		//Mat4f temp = Translate(0.0f, animation->Frames[frameCounter].Tranformations[channelCounter + 1], 0.0f);
		//TLocal = temp; 	

		Mat4f rZ = RotateZ(animation->Frames[frameCounter].Tranformations[channelCounter + 3]);	//z
		Mat4f rX = RotateX(animation->Frames[frameCounter].Tranformations[channelCounter + 4]);	//y
		Mat4f rY = RotateY(animation->Frames[frameCounter].Tranformations[channelCounter + 5]);	//x
		RLocal = rZ * rX * rY; //rZ * rY * rX

		channelCounter += 6;
	}
	else if(numChannels == 3)
	{
		Mat4f rZ = RotateZ(animation->Frames[frameCounter].Tranformations[channelCounter]);
		Mat4f rX = RotateX(animation->Frames[frameCounter].Tranformations[channelCounter + 1]);
		Mat4f rY = RotateY(animation->Frames[frameCounter].Tranformations[channelCounter + 2]);
		RLocal = rZ * rX * rY; 

		channelCounter += 3;
	}

	//update all of the childern
	for(unsigned int i = 0; i < this->Children.size(); i++)
	{
		Children[i]->updateTransform(animation, frameCounter, channelCounter);	
	}
}
Ejemplo n.º 3
0
void Joint::updateAdditiveTransform(Animation *animation1, Animation *animation2, int frameCounter, int &channelCounter)
{
	if(numChannels == 6)
	{
		Mat4f temp = Translate(animation1->Frames[frameCounter].Tranformations[channelCounter], animation1->Frames[frameCounter].Tranformations[channelCounter + 1], animation1->Frames[frameCounter].Tranformations[channelCounter + 2]);
		TLocal = temp; 

		Mat4f rZ = RotateZ(animation1->Frames[frameCounter].Tranformations[channelCounter + 3] + animation2->Frames[frameCounter].Tranformations[channelCounter + 3]);
		Mat4f rY = RotateY(animation1->Frames[frameCounter].Tranformations[channelCounter + 4] + animation2->Frames[frameCounter].Tranformations[channelCounter + 4]);
		Mat4f rX = RotateX(animation1->Frames[frameCounter].Tranformations[channelCounter + 5] + animation2->Frames[frameCounter].Tranformations[channelCounter + 5]);
		RLocal = rZ * rY * rX; 

		channelCounter += 6;
	}
	else if(numChannels == 3)
	{
		Mat4f rZ = RotateZ(animation1->Frames[frameCounter].Tranformations[channelCounter] + animation2->Frames[frameCounter].Tranformations[channelCounter]);
		Mat4f rY = RotateY(animation1->Frames[frameCounter].Tranformations[channelCounter + 1] + animation2->Frames[frameCounter].Tranformations[channelCounter + 1]);
		Mat4f rX = RotateX(animation1->Frames[frameCounter].Tranformations[channelCounter + 2] + animation2->Frames[frameCounter].Tranformations[channelCounter + 2]);
		RLocal = rZ * rY * rX; 

		channelCounter += 3;
	}

	//update all of the childern
	for(unsigned int i = 0; i < this->Children.size(); i++)
	{
		Children[i]->updateAdditiveTransform(animation1, animation2, frameCounter, channelCounter);	
	}
}
Ejemplo n.º 4
0
// rotate about u-axis 
Matrix4D Rotate(const Matrix4D &m,const Vector3D& u, float theta)
{
	float x, y, z,w;
	x = u.x;
	y = u.y;
	z = u.z;

	w=Magnitude(u);
	float ux, uy, uz,ud,xtheta,ytheta;
	ux = x / w;
	uy = y / w;
	uz = z / w;

	ud = pow(pow(uy, 2) + pow(uz, 2), 0.5);
	xtheta = acos(uy / ud);
	ytheta = acos(ud);

	Matrix4D temp;
	temp = Translate(x, y, z)*m;
	temp = RotateX(ytheta)*temp;
	temp = RotateY(ytheta)*temp;
	temp = RotateZ(theta)*temp;
	temp = Inverse(RotateY(ytheta))*temp;
	temp = Inverse(RotateX(xtheta))*temp;
	temp = Inverse(Translate(x, y, z))*temp;

	return temp;

}
Ejemplo n.º 5
0
mat4 SpelchkCamera::getModelViewMatrix() {
  _modelViewMatrix = RotateX( _xAngle ) * RotateY( _yAngle )
                     * RotateZ( _zAngle ) * RotateX( _xHeadAngle )
                     * RotateY( _yHeadAngle ) * Translate( _translationVector )
                     * RotateX( -_xHeadAngle ) * RotateY( -_yHeadAngle );
  return _modelViewMatrix;
}
Ejemplo n.º 6
0
void drawBanana1(void)
{
	mvstack.push(model_view);
	set_colour(.95, .9, .8);
	model_view *= Scale(0.08, 0.2, 0.1);
	model_view *= RotateX(90);
	drawSphere();
	model_view = mvstack.pop();

	mvstack.push(model_view);
	set_colour(.95, .9, .1);
	model_view *= Scale(0.1, 0.3, 0.112);
	model_view *= Translate (0, -.5, 0);
	model_view *= RotateX(90);
	drawSphere();
	model_view = mvstack.pop();

	mvstack.push(model_view);
	set_colour (.1, .1, .2);
	model_view *= Translate(0, -0.45, 0);
	model_view *= Scale(.025, .025,.025);
	drawSphere();
	model_view = mvstack.pop();


}
Ejemplo n.º 7
0
void drawBench(void)
{
	mvstack.push(model_view);
	drawWood();
	model_view *= Translate (0, -2.5 ,0);
	drawWood();

	model_view *= Translate (0, -1, 1);
	model_view *= RotateX(90);
	model_view *= Scale(1, 0.25, 2);
	drawWood();
	model_view *= Translate(0, 2, 0);
	drawWood();
	model_view *= Translate(0, 2, 0);
	drawWood();
	model_view *= Translate(0, 2, 0);
	drawWood();
	model_view *= Translate(0, 2, 0);
	drawWood();
	model_view = mvstack.pop();

	mvstack.push(model_view);
	set_colour(.2,.2,.2);
	model_view *= Translate (-6.5 , -.7 , 0.25);
	drawHandle();
	model_view *= Translate (0, -.7, 1.25);
	model_view *= RotateX(90);
	drawHandle();
	model_view *= Scale (1, 1, 1.5);
	model_view *= Translate (0, 1.3, 1.5);
	model_view *= RotateX(90);
	drawHandle();
	model_view = mvstack.pop();

	mvstack.push(model_view);
	model_view *= Translate(6.5, -.7, 0.25);
	drawHandle();
	model_view *= Translate (0, -.7, 1.25);
	model_view *= RotateX(90);
	drawHandle();
	model_view *= Scale (1, 1, 1.5);
	model_view *= Translate (0, 1.3, 1.5);
	model_view *= RotateX(90);
	drawHandle();
	model_view = mvstack.pop();

	mvstack.push(model_view);
	model_view *= Translate (6.5, -4.5, 1);
	drawHandle();
	model_view = mvstack.pop();

	mvstack.push(model_view);
	model_view *= Translate (-6.5, -4.5, 1);
	drawHandle();
	model_view = mvstack.pop();
}
Ejemplo n.º 8
0
//draws the body of the O
//@pre mv has been assigned
//@post draws an O to the world
//@param mv - the model view
//@usage drawBody(some_model_view)
void
Letter_O::drawBody(mat4& mv)
{
    mvMatrixStack.pushMatrix(mv);
    mv = mv * Translate(0.7, -0.5, 0);
    mv = mv * Scale(1.5, 1.25, 1);
    mvMatrixStack.pushMatrix(mv);
    mv = mv * Translate(-2, 0, 0);
    for (int i = 0; i < 5; i++) {
        mvMatrixStack.pushMatrix(mv);
        mv = mv * Translate(-1 + pow(i / 2.5, 2.0), i +6, 0);
        vec4 color(0, 0, 1, 1);
        mv = mv*Scale(cHeight,cLength,cWidth);
        glUniformMatrix4fv( model_view, 1, GL_TRUE, mv );
        shapes.drawCube(color);
        mv = mvMatrixStack.popMatrix();
    }

    for (int i = 0; i < 5; i++) {
        mvMatrixStack.pushMatrix(mv);
        mv = mv * RotateX(180);
        mv = mv * Translate(-1 + pow(i / 2.5, 2.0), i - 5, 0);
        vec4 color(0, 0, 1, 1);
        mv = mv*Scale(cHeight,cLength,cWidth);
        glUniformMatrix4fv( model_view, 1, GL_TRUE, mv );
        shapes.drawCube(color);
        mv = mvMatrixStack.popMatrix();
    }
    mvMatrixStack.popMatrix();

    mvMatrixStack.pushMatrix(mv);
    mv = mv * Translate(3, 0, 0);
    mv = mv * RotateY(180);
    for (int i = 0; i < 5; i++) {
        mvMatrixStack.pushMatrix(mv);
        mv = mv * Translate(-1 + pow(i / 2.5, 2.0), i +6, 0);
        vec4 color(0, 0, 1, 1);
        mv = mv*Scale(cHeight,cLength,cWidth);
        glUniformMatrix4fv( model_view, 1, GL_TRUE, mv );
        shapes.drawCube(color);
        mv = mvMatrixStack.popMatrix();
    }

    for (int i = 0; i < 5; i++) {
        mvMatrixStack.pushMatrix(mv);
        mv = mv * RotateX(180);
        mv = mv * Translate(-1 + pow(i / 2.5, 2.0), i - 5, 0);
        vec4 color(0, 0, 1, 1);
        mv = mv*Scale(cHeight,cLength,cWidth);
        glUniformMatrix4fv( model_view, 1, GL_TRUE, mv );
        shapes.drawCube(color);
        mv = mvMatrixStack.popMatrix();
    }
    mvMatrixStack.popMatrix();
    mvMatrixStack.popMatrix();
}
Ejemplo n.º 9
0
void keyboard(unsigned char key, int x, int y) {
	switch(key) {
	case 033: // Esc
	case 'q': 
		exit(EXIT_SUCCESS);
		break;
	case 'w': // Write
		saveState("savestate.rubiks");
		break;
	case 'e': // Edit
		loadState("savestate.rubiks");
		break;
	case 'r': // Reset
		resetRotationMatrix();
		break;

	// Scene rotation with arrow keys
	case 'k':
		rotationMat *= RotateX(ROTATION_FACTOR_KEYBOARD);
		break;
	case 'j':
		rotationMat *= RotateX(-ROTATION_FACTOR_KEYBOARD);
		break;
	case 'l':
		rotationMat *= RotateZ(ROTATION_FACTOR_KEYBOARD);
		break;
	case 'h':
		rotationMat *= RotateZ(-ROTATION_FACTOR_KEYBOARD);
		break;
	
	// Shift + number keys
	case '!': key = 1; break;
	case '@': key = 2; break;
	case '#': key = 3; break;
	case '$': key = 4; break;
	case '%': key = 5; break;
	case '^': key = 6; break;
	case '&': key = 7; break;
	case '*': key = 8; break;
	case '(': key = 9; break;
	}
	if (key <= 9) {
		key--;
		rotateSlice(positions,key/3,key%3,false);
	}
	if (key > '0' && key <='9') {
		int p = key - '1';
		rotateSlice(positions,p/3,p%3,true);
	}
}
Ejemplo n.º 10
0
void drawTree(void)
{
	mvstack.push(model_view);
	set_colour(.4, .2, .1);
	model_view *= Scale (3, 8, 3);
	model_view *= RotateX(90);
	drawTrunk();
	model_view = mvstack.pop();

	mvstack.push(model_view);
	model_view *= Translate(0, 5, 0);
	model_view *= RotateX(90);
	drawGreen();
	model_view = mvstack.pop();
}
Ejemplo n.º 11
0
//----------------------------------------------------------------------------
// The passive motion callback for a window is called when the mouse moves within the window while no mouse buttons are pressed.
void Win_PassiveMotion(int x, int y) {

	g_fPhi = (float)-M_PI*(x - HALF_SIZE)/(HALF_SIZE); // 轉換成 g_fPhi 介於 -PI 到 PI 之間 (-180 ~ 180 之間)
	g_fTheta = (float)M_PI*(float)y/SCREEN_SIZE;
	g_vEye.x = g_fRadius*sin(g_fTheta)*sin(g_fPhi);
	g_vEye.y = g_fRadius*cos(g_fTheta);
	g_vEye.z = g_fRadius*sin(g_fTheta)*cos(g_fPhi);


	mxT = Translate(0, 1.0f, 0.0f)  * RotateY((M_PI+g_fPhi)/DegreesToRadians) *RotateX(90) *Scale(2,2,2);
	printf("%f\n",g_fPhi/DegreesToRadians);

	g_mxModelView = LookAt( g_vEye, g_vAt, g_vUp );

	// Change ModelView Matrix
	g_pFloor->SetModelViewMatrix(g_mxModelView);
	g_pLight->SetModelViewMatrix(g_mxModelView);
	//TODO 
	vec4 tmp = vec4(0,0,-1,0.0);
	float f**k = dot(tmp,g_vEye-vec4(0,1,0,0));

	g_pAimal[0]->SetTRSMatrix(mxT);
	g_pAimal[0]->SetModelViewMatrix(g_mxModelView);

}
Ejemplo n.º 12
0
// rotire fata de centru, la o distanta generica 5
void Camera::RotateXCenter (GLfloat Angle)
{
	float distance = 10;
	MoveForward(distance);
	RotateX(Angle);
	MoveBackward(distance);
}
Ejemplo n.º 13
0
/*
 * Arguments    : const float euler[3]
 *                float C[9]
 * Return Type  : void
 */
static void Euler2C_One(const float euler[3], float C[9])
{
  float fv3[9];
  float fv4[9];
  float fv5[9];
  float fv6[9];
  int i3;
  int i4;
  int i5;

  /*  if ~exist('rotateOrder','var') || isempty(rotateOrder) */
  /*      rotateOrder = 'ZYX'; */
  /*  end */
  RotateX(euler[2], fv3);
  RotateZ(euler[1], fv4);
  RotateY(euler[0], fv5);
  for (i3 = 0; i3 < 3; i3++) {
    for (i4 = 0; i4 < 3; i4++) {
      fv6[i3 + 3 * i4] = 0.0F;
      for (i5 = 0; i5 < 3; i5++) {
        fv6[i3 + 3 * i4] += fv3[i3 + 3 * i5] * fv4[i5 + 3 * i4];
      }
    }

    for (i4 = 0; i4 < 3; i4++) {
      C[i3 + 3 * i4] = 0.0F;
      for (i5 = 0; i5 < 3; i5++) {
        C[i3 + 3 * i4] += fv6[i3 + 3 * i5] * fv5[i5 + 3 * i4];
      }
    }
  }
}
Ejemplo n.º 14
0
void drawPineTree(void)
{
	mvstack.push(model_view);
	mvstack.push(model_view);
	model_view *= Translate(0.0,19.0,0.0);
	model_view *= Scale(5.0,7.0,5.0);
	model_view *= RotateX(90);
	set_colour(0.0,0.8,0.3);
	drawCone();
	model_view = mvstack.pop();
	set_colour(.5,.5,.2);
	model_view *= Scale(1.0,13.0,1.0);
	model_view *= RotateX(90);
	drawCylinder();
	model_view = mvstack.pop();
}
Ejemplo n.º 15
0
CMatrix44f::CMatrix44f(const float& rotX, const float& rotY, const float& rotZ)
{
	LoadIdentity();
	RotateX(rotX);
	RotateY(rotY);
	RotateZ(rotZ);
}
Ejemplo n.º 16
0
void CRotationMatrix::SetRotation3(CVector3 rotation)
{
	Null();
	RotateZ(rotation.x);
	RotateY(rotation.y);
	RotateX(rotation.z);
}
Ejemplo n.º 17
0
void CRotationMatrix::SetRotation(double angles[3])
{
	Null();
	RotateZ(angles[0]);
	RotateX(angles[1]);
	RotateY(angles[2]);
}
Ejemplo n.º 18
0
void CRotationMatrix::SetRotation(double alpha, double beta, double gamma)
{
	Null();
	RotateZ(alpha);
	RotateX(beta);
	RotateY(gamma);
}
Ejemplo n.º 19
0
/** Reset the scene rotation */
void resetRotationMatrix() {
	rotationMat = mat4();
	vec3 r(INITIAL_ROTATION);
	rotationMat *= RotateX(r[0]);
	rotationMat *= RotateY(r[1]);
	rotationMat *= RotateZ(-r[2]);
}
Ejemplo n.º 20
0
void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	//Model Matrix
	Angel::mat4 model_ = mat4(1.0);
	Angel::vec3 scaleVec(scale_size,scale_size,scale_size);
	//Angel::vec3 transVec(4.0,0.0,0.0);
	Angel::vec3 transVec(u_disp,v_disp,0.0);
	Angel::mat4 scaleMat = Scale(scaleVec);
	Angel::mat4 xRotMat = RotateY(x_angle);
	Angel::mat4 yRotMat = RotateX(y_angle);
	Angel::mat4 transMat = Translate(transVec);
	model_ = scaleMat*xRotMat*yRotMat*transMat;

	//Viewing Matrix
	point4 at(0.0,0.0,0.0,1.0);
	point4 eye(0.0,5.0,3.0,1.0);
	vec4 up(0.0,0.0,1.0,0.0);
	mat4 view_ = LookAt(eye,at,up);

	mat4 modelView_ = model_*view_;
	glUniformMatrix4fv(ModelView,1,GL_TRUE,modelView_);

	glDrawArrays(GL_TRIANGLE_STRIP,0,numVertices);
	
	glutSwapBuffers();
}
Ejemplo n.º 21
0
void CSTransform::TransformByType(TransformType type, const double* args, bool concatenate)
{
	//Keep this in sync with GetTypeByName and TransformType!!!
	switch (type)
	{
	case SCALE:
		return Scale(args[0], concatenate);
	case SCALE3:
		return Scale(args, concatenate);
	case TRANSLATE:
		return Translate(args,concatenate);
	case ROTATE_ORIGIN:
		return RotateOrigin(args,args[3],concatenate);
	case ROTATE_X:
		return RotateX(args[0],concatenate);
	case ROTATE_Y:
		return RotateY(args[0],concatenate);
	case ROTATE_Z:
		return RotateZ(args[0],concatenate);
	case MATRIX:
		return SetMatrix(args,concatenate);
	default:
		return;
	}
}
Ejemplo n.º 22
0
void cCamera::Update(cInput *Input)
{
	int mx,my;
	int middleX,middleY;
	float angle;

	Input->GetMousePosition(&mx,&my);

	// Move the camera's view by the mouse
	middleX = width  >> 1;
	middleY = height >> 1;

	if(mx!=middleX)
	{
		angle = ((float)(middleX - mx)) / 50.0f;
		RotateY(angle);
	}
	if(my!=middleY)
	{
		angle = ((float)(middleY - my)) / 50.0f;
		RotateX(angle);
	}

	if(Input->KeyIsDown(GLUT_KEY_UP))		MoveForwards(-speed);				
	if(Input->KeyIsDown(GLUT_KEY_DOWN))		MoveForwards( speed);
	if(Input->KeyIsDown(GLUT_KEY_LEFT))		StrafeRight(-speed);
	if(Input->KeyIsDown(GLUT_KEY_RIGHT))	StrafeRight( speed);
}
void display( void )
{
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  /*clear the window */
     ctm = RotateX(theta[0])*RotateY(theta[1])*RotateZ(theta[2]);
     glUniformMatrix4fv(ctm_loc, 1, GL_TRUE, ctm);
     glDrawArrays(GL_TRIANGLES, 0, N);
     glutSwapBuffers();
}
Ejemplo n.º 24
0
void Camera::Input()
{
	float sensitivity = 0.001f;
	float movAmt = static_cast<float>(10 * Time::GetDelta());
	float rotAmt = static_cast<float>(1.5f * Time::GetDelta());

	if (Input::GetMouseDown(GLFW_MOUSE_BUTTON_1))
	{
		m_cursorStoredPos = Input::GetCursorPosition();
		vec2 centerPos = vec2((float)WIDTH / 2.0f, (float)WIDTH / 2.0f);
		Input::SetCursorPosition(centerPos);
		Input::SetCursorVisibility(false);
		m_mouselocked = true;
	}

	if (Input::GetMouseUp(GLFW_MOUSE_BUTTON_1))
	{
		Input::SetCursorPosition(m_cursorStoredPos);
		Input::SetCursorVisibility(true);
		m_mouselocked = false;
	}

	if (m_mouselocked)
	{
		vec2 centerPos = vec2((float)WIDTH / 2.0f, (float)WIDTH / 2.0f);
		vec2 currentPos = Input::GetCursorPosition();
		vec2 deltaPos = centerPos - currentPos;

		bool rotY = deltaPos.x != 0;
		bool rotX = deltaPos.y != 0;

		if (rotY)
			RotateY(deltaPos.x * sensitivity);
		if (rotX)
			RotateX(deltaPos.y * sensitivity);

		if (rotY || rotX)
			Input::SetCursorPosition(centerPos);
	}

	if (Input::GetKey(GLFW_KEY_W))
	{
		MoveUp(movAmt);
	}
	if (Input::GetKey(GLFW_KEY_S))
	{
		MoveUp(-movAmt);
	}
	if (Input::GetKey(GLFW_KEY_D))
	{
		MoveRight(movAmt);
	}
	if (Input::GetKey(GLFW_KEY_A))
	{
		MoveRight(-movAmt);
	}

}
Ejemplo n.º 25
0
void Quad::update(float dt)
{
	Matrix rotXM, rotYM, rotZM, transM;
	RotateX(&rotXM, rotX);
	RotateY(&rotYM, rotY);
	RotateZ(&rotZM, rotZ); 
	Translate(&transM, position.x, position.y, position.z);
	world = rotXM * rotYM * rotZM * transM;
}
Ejemplo n.º 26
0
void drawGreen(void)
{
	mvstack.push(model_view);
	set_colour(.1, .4, .1);
	model_view *= Scale (10, 7, 12);
	model_view *= RotateX(-90);
	drawLeaf();
	model_view = mvstack.pop();
}
Ejemplo n.º 27
0
Node* inithouseNode(int w, int h, int l)
{
    Node *head = new Node[11];

    //-------------
    //memory manage
    head->gar=garb;
    garb=head;
    //-------------

    mat4 m(1.0f);
    m = Scale(w,l,h);

    head[0] = Node(m, blank,NULL,&head[1]);
    m = Translate(1.5, -0.5, 0.0)*RotateY(-90.0);

    head[1] = Node( m, rectangleY, &head[2], NULL);
    m = Translate( 0.0, -0.5, 0.0)*RotateY(-90.0);

    head[2] = Node( m, rectangleY, &head[3], NULL);
    m = Translate(0.0, -0.5, 0.0)*RotateX(90.0)*Scale(1.5,1,1);

    head[3] = Node( m, rectangleY, &head[4], NULL);
    m = Translate(0.0, 0.5, 0.0)*RotateX(90.0)*Scale(1.5,1,1);

    head[4] = Node( m, rectangleY, &head[5], NULL);
    m = Translate(0.0, 0.0, 0.0);

    head[5] = Node( m, blank, NULL, &head[6]);
    m = Translate( 0.0, 0.0, 1.0)*RotateY(-90.0);

    head[6] = Node( m, triangle, &head[7], NULL);
    m = Translate( 1.5, 0.0, 1.0)*RotateY(-90.0);

    head[7] = Node( m, triangle, &head[8], NULL);
    m = Translate(0.0, -0.5, 1.0)*RotateX(45)*Scale(1.5, sqrt(0.5), 1.0);

    head[8] = Node( m, rectangleM, &head[9], NULL);
    m = Translate(0.0, 0.5, 1.0)*RotateX(135)*Scale(1.5, sqrt(0.5), 1.0);

    head[9] = Node( m, rectangleM, NULL, NULL);

    return &head[0];
}
Ejemplo n.º 28
0
MALIB_API MAT4x4 Rotate(float x, float y, float z)
{
	MAT4x4 m;

	if (x != 0.0f) m *= RotateX(x);
	if (y != 0.0f) m *= RotateY(y);
	if (z != 0.0f) m *= RotateZ(z);

	return m;
}
Ejemplo n.º 29
0
/* This function will update the model view matrix 
    and send it to the GPU.. now geometry object
    will rotate */
void Geometry::rotate(vec4 dir){
    if(length(dir) == 0)
            return;
        
    float theta_x = dTheta *  dir.x;
    float theta_y = dTheta * -dir.y;
    float theta_z = dTheta * -dir.z;

    vec4 dthetas = vec4(theta_x, theta_y, theta_z, 0); 

    constrict_angles(); 
    vec4 look = eye - at;
         look = vec4(look.x, look.y, look.z, 0);

    vec4 side = -cross( normalize(look), up);

    mat4 M = mat4(  normalize(side), 
                    normalize(up), 
                    normalize(look), 
                    vec4(0,0,0,0) ); //x y z w

    /* M is the basis matrix for the camera...
        M^-1 == transpose(M)   */
    mat4 CameraToStandardBasis_M = transpose(M);

    /* --- calculated by some change in theta/angle --- */

    vec4 thetas_prime = CameraToStandardBasis_M * dthetas;
    // YAW & PITCH (translate because at is not a vector.. its a point)
    at = Translate(eye.x, eye.y, eye.z) *  
        RotateX(thetas_prime.x) * 
        RotateY(thetas_prime.y) * 
        RotateZ(thetas_prime.z) * 
        Translate(-eye.x, -eye.y, -eye.z) * at;

    // PITCH & ROLL (luckily up is a vector..)
    look = eye - at;
    up = RotateX(thetas_prime.x) *
        RotateY(thetas_prime.y) * 
        RotateZ(thetas_prime.z) * up;

    
}
Ejemplo n.º 30
0
void init( void )
{
	mat4 mxT;
	vec4 vT, vColor;
	// 產生所需之 Model View 與 Projection Matrix

	g_mxModelView = LookAt( g_vEye, g_vAt, g_vUp );
	g_mxProjection = Perspective(60.0, (GLfloat)SCREEN_SIZE/(GLfloat)SCREEN_SIZE, 1.0, 1000.0);

	// 產生物件的實體
	g_pFloor = new CQuad;
	g_pFloor->SetShader(g_mxModelView, g_mxProjection);
	g_pFloor->SetTRSMatrix(Scale(30,1,30));
	g_pFloor->SetShadingMode(GOURAUD_SHADING);
	g_pFloor->SetTiling(30,30);
//	g_uiFTexID[0] = g_pFloor->LoadPngImageAndSetTextureObject("texture/checker.png");
//	g_uiFTexID[0] = png_load_LIBPNG("texture/checker.png",&g_iTexWidth, &g_iTexHeight, true);
	g_uiFTexID[0] = png_load_SOIL("texture/checker.png",&g_iTexWidth, &g_iTexHeight, true);
	// 設定貼圖
	g_pFloor->SetMaterials(vec4(0), vec4(0.85f, 0.85f, 0.85f, 1), vec4(1.0f, 1.0f, 1.0f, 1.0f));
	g_pFloor->SetKaKdKsShini(0, 0.8f, 0.5f, 1);

	g_pCube = new CSolidCube;
	g_pCube->SetShader(g_mxModelView, g_mxProjection);
	// 設定 Cube
	vT.x = 1.5f; vT.y = 1.01f; vT.z = -1.5f;
	mxT = Translate(vT);
	mxT._m[0][0] = 2.0f; mxT._m[1][1] = 2.0f; mxT._m[2][2] = 2.0f;
	g_pCube->SetTRSMatrix(mxT);
	g_pCube->SetShadingMode(GOURAUD_SHADING);
	// materials
	g_pCube->SetMaterials(vec4(0.35f, 0.35f, 0.35f, 1), vec4(0.85f, 0.85f, 0.85f, 1), vec4(1.0f, 1.0f, 1.0f, 1.0f));
	g_pCube->SetKaKdKsShini(0.25f, 0.8f, 0.2f, 2);
	g_pCube->LoadPngImageAndSetTextureObject("texture/Masonry.Brick.png");

	g_pSphere = new CSolidSphere(1, 16, 16);
	g_pSphere->SetShader(g_mxModelView, g_mxProjection);
	// 設定 Sphere
	vT.x = -3.5; vT.y = 2.0; vT.z = 1.5;
	mxT = Translate(vT)* RotateX(-90) * Scale(2,2,2);
	g_pSphere->SetTRSMatrix(mxT);
	g_pSphere->SetShadingMode(GOURAUD_SHADING);
	// materials
	g_pSphere->SetMaterials(vec4(0.15f, 0.15f, 0.15f, 1), vec4(0.85f, 0.85f, 0.85f, 1), vec4(1.0f, 1.0f, 1.0f, 1.0f));
	g_pSphere->SetKaKdKsShini(0.15f, 0.5f, 0.2f, 2);
	g_pSphere->LoadPngImageAndSetTextureObject("texture/earth.png");

	// 設定 代表 Light 的 WireSphere
	g_pLight = new CWireSphere(0.25f, 6, 3);
	g_pLight->SetShader(g_mxModelView, g_mxProjection);
	mxT = Translate(g_Light1.position);
	g_pLight->SetTRSMatrix(mxT);
	g_pLight->SetColor(g_Light1.diffuse);
	g_pLight->SetLightingDisable();
}