Node* tree_trunk(int number, float radius, float height, mat4 m) { Node *head = new Node[number+1]; //------------- //memory manage head->gar=garb; garb=head; //------------- int t_index=0; float width = 2.0f * sin( M_PI/ number ) * radius ; // scaled width float step = 360.0f/float(number); mat4 rec_scal = Scale( height, width, 1.0f ) ; // scale matrix head[t_index] = Node( m , blank, NULL, &head[1]); //head for(int i=0; i< number-1 ;i++) { m = RotateZ(step*i)*Translate ( radius * cos(M_PI/number) , -width/2.0f , 0.0f )*RotateY(-90.0) * rec_scal; head[i+1] = Node( m, rectangleB, &head[i+2], NULL); } m = RotateZ(step*(number-1))*Translate ( radius * cos(M_PI/number) , -width/2 , 0.0f )*RotateY(-90.0) * rec_scal; head[number] = Node( m, rectangleB, NULL, NULL); // end return head; }
Node* tree_top(int number, float radius, float height, mat4 m) { Node *head = new Node[number+1]; //------------- //memory manage head->gar=garb; garb=head; //------------- int t_index=0; float width = 2.0f * sin( M_PI/ number ) * radius ; // scaled width float step = 360.0f/float(number); float shift = radius * cos(M_PI/number); // triangle shift to the position float len = 2* sqrt ( shift*shift + height * height ); // height of triangle float cita = atan(height/shift)/M_PI*180.0f; mat4 rec_scal = Scale( - len , width, 1.0f ) ; // scale matrix head[t_index] = Node( m , blank, NULL, &head[1]); //head for(int i=0; i< number-1 ;i++) { m = RotateZ(step*i)*Translate ( shift , 0.0f , 0.0f )* RotateY(cita) * rec_scal; head[i+1] = Node( m, triangleG, &head[i+2], NULL); } m = RotateZ(step*(number-1))*Translate ( shift , 0.0f , 0.0f )*RotateY(cita) * rec_scal; head[number] = Node( m, triangleG, NULL, NULL); // end return head; }
Node * org_scen() { Node *head = new Node[6]; //------------- //memory manage head->gar=garb; garb=head; //------------- mat4 m = Translate(0.0,0.0,0)*RotateZ(45); head[0] = Node( m, blank , NULL, &head[1]); m = Translate(10,10,0); head[1] = Node( m , blank , &head[2], org_house_tree(1.0)); m = Translate(10.0,-10.0,0)* RotateZ(35); head[2] = Node( m , blank , &head[3], org_house_tree(0.5)); m = Translate(-10.0,10.0,0)* RotateZ(95); head[3] = Node( m , blank , &head[4], org_house_tree(1.3)); m = Translate(-10.0,-10.0,0)* RotateZ(15); head[4] = Node( m , blank , &head[5], org_house_tree(0.8)); m = Translate(0.0,0.0,0)* RotateZ(0); head[5] = Node( m , blank , NULL, org_house_tree(0.7)); return head; }
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); } }
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(); }
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); } }
Node* org_house_tree(float fac1) // 5 { Node *head = new Node[6]; //------------- //memory manage head->gar=garb; garb=head; //------------- mat4 m = Translate(-3.0,3.0,0)*RotateZ(0); head[0] = Node( m, blank , NULL, &head[1]); m = Translate(1.5,1.5,0); head[1] = Node( m , blank , &head[2], init_tree(0.3*fac1,6.0,0.2,4)); m = Translate(-3.0,-3.0,0)* RotateZ(45); head[2] = Node( m , blank , &head[3], inithouseNode(2.3,2.1*fac1,1.2)); m = Translate(-3.0,3.0,0)* RotateZ(95); head[3] = Node( m , blank , &head[4], init_tree(0.2,5.0,0.4,6*fac1)); m = Translate(3.0,-3.0,0)* RotateZ(180); head[4] = Node( m , blank , &head[5], inithouseNode(2.3*fac1,2.1,3.2)); m = Translate(-5.0,0.0,0)* RotateZ(0); head[5] = Node( m , blank , NULL, inithouseNode(1.3,5.0*fac1,1.2)); return head; }
void drawFlower() { float theta; mvstack.push(model_view); for (int i = 0; i <8; i++){ theta =5*sin(30*DegreesToRadians*TIME); model_view *= RotateZ(theta); model_view *= Translate(0.0f, 1, 0.0f); mvstack.push(model_view); model_view *= Scale(1, 2, 1); set_colour(0.545f, 0.271f, 0.075f); drawCube(); model_view = mvstack.top(); mvstack.pop(); model_view *= Translate(0.0f, 1, 0.0f); if (i == 7) { model_view *= RotateZ(theta); model_view *= Translate(0, 2, 0); model_view *= Scale(2, 2, 2); set_colour(1.0f, 0.0f, 0.0f); drawSphere(); } } model_view = mvstack.top(); mvstack.pop(); }
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); } }
/* * 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]; } } } }
void drawGrass(void) { mvstack.push(model_view); set_colour(0.5f, 1.0f, 0.5f); model_view *= RotateZ(grassSway); drawGcube(); model_view *= RotateZ(-grassSway); model_view *= Translate(1.0f, 0.0f, 0.0f); model_view *= RotateZ(grassSway); drawGcube(); model_view *= RotateZ(-grassSway); model_view *= Translate(1.0f, 0.0f, 0.0f); model_view *= RotateZ(grassSway); drawGcube(); model_view = mvstack.pop(); }
void CRotationMatrix::SetRotation(double angles[3]) { Null(); RotateZ(angles[0]); RotateX(angles[1]); RotateY(angles[2]); }
// rotire fata de centru, la o distanta generica 5 void Camera::RotateZCenter (GLfloat Angle) { float distance = 5; MoveForward(distance); RotateZ(Angle); MoveBackward(distance); }
CMatrix44f::CMatrix44f(const float& rotX, const float& rotY, const float& rotZ) { LoadIdentity(); RotateX(rotX); RotateY(rotY); RotateZ(rotZ); }
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ // Name : 初期化 // Description : 初期化 // Arguments : // Returns : //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ void CFlower::Init(D3DXVECTOR3 pos,D3DXVECTOR3 dir,const LPCTSTR pszFName) { m_kuki = CObject2D::Create(pszFName); //m_kuki->Init(D3DXVECTOR3(1,1,0)); // キャラクターの初期化 CCharacter::Init(); Resize(D3DXVECTOR2(FLOWER_SIZE_X,FLOWER_SIZE_Y)); pos += dir * (FLOWER_SIZE_X / 2); Translate(pos); m_angle = AngleOf2Vector(pos,D3DXVECTOR3(0,1,0)); if(m_angle > 0) RotateZ((float)m_angle); m_lastTime = CTimer::GetTime(); if(rand() % 2 == 0) m_rotSpd = 3; else if(rand() % 2 == 1) m_rotSpd = -3; // アニメーション初期化 StartAnimation(); UVDivision(0, FLOWER_ANIME_SIZE_X, FLOWER_ANIME_SIZE_Y); }
void CRotationMatrix::SetRotation3(CVector3 rotation) { Null(); RotateZ(rotation.x); RotateY(rotation.y); RotateX(rotation.z); }
// 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; }
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; } }
/** Reset the scene rotation */ void resetRotationMatrix() { rotationMat = mat4(); vec3 r(INITIAL_ROTATION); rotationMat *= RotateX(r[0]); rotationMat *= RotateY(r[1]); rotationMat *= RotateZ(-r[2]); }
mat4 SpelchkCamera::getModelViewMatrix() { _modelViewMatrix = RotateX( _xAngle ) * RotateY( _yAngle ) * RotateZ( _zAngle ) * RotateX( _xHeadAngle ) * RotateY( _yHeadAngle ) * Translate( _translationVector ) * RotateX( -_xHeadAngle ) * RotateY( -_yHeadAngle ); return _modelViewMatrix; }
void CRotationMatrix::SetRotation(double alpha, double beta, double gamma) { Null(); RotateZ(alpha); RotateX(beta); RotateY(gamma); }
void drawDSHearts(void) { mvstack.push(model_view); if(timeline > 56) model_view *= RotateY(-90); if((timeline > 15.5f && timeline < 16.0f)) { mvstack.push(model_view); model_view *= Translate(0.0f, 2.0f, 0.0f); drawLoveHeart(); model_view = mvstack.pop(); } if((timeline > 15.75f && timeline < 16.25f)) { mvstack.push(model_view); model_view *= Translate(1.0f, 2.0f, 0.0f); model_view *= RotateZ(-15); drawLoveHeart(); model_view = mvstack.pop(); } if((timeline > 16.0f && timeline < 16.5f)) { mvstack.push(model_view); model_view *= Translate(-2.0f, 2.5f, 0.0f); model_view *= RotateZ(15); drawLoveHeart(); model_view = mvstack.pop(); } if((timeline > 16.25f && timeline < 16.75f)) { mvstack.push(model_view); if(timeline > 56.75) model_view *= Translate(0.0f, 3.0f+temp3, 0.0f); else model_view *= Translate(0.0f, 3.0f, 0.0f); model_view = mvstack.pop(); } if(timeline>17) { mvstack.push(model_view); if(timeline>42) set_colour(1,1,1); set_colour(1.3,0,2.55); model_view*=Translate(0,-1.5,0); drawLoveHeart(); model_view = mvstack.pop(); } model_view = mvstack.pop(); }
void viewControl::cam_RotateZ(const float& cita) { mat4 rot = RotateZ(cita); _n = normalize(rot*_n); _v = normalize(rot*_v); _u = normalize(rot*_u); _cam_view = LookAt(_cam_pos,_cam_pos+_n,_v); }
void update_upper_arm(Model* m){ mat4 rotation = Translate(0.0,-LOWER_ARM_HEIGHT - 0.5*UPPER_ARM_HEIGHT,0.0) * RotateZ(upper_arm_theta) * RotateY(upper_arm_delta) * Translate(0.0,LOWER_ARM_HEIGHT + 0.5*UPPER_ARM_HEIGHT,0.0); mat4 rotation2 = Translate(0.0,-UPPER_ARM_HEIGHT/2.0,0.0) * RotateZ(upper_arm_beta) * Translate(0.0,UPPER_ARM_HEIGHT/2.0,0.0); mat4 instance = Translate( 0.0, 0.5 * UPPER_ARM_HEIGHT + LOWER_ARM_HEIGHT + BASE_HEIGHT, 0.0 ) * rotation * rotation2 * Scale(UPPER_ARM_WIDTH, UPPER_ARM_HEIGHT, UPPER_ARM_WIDTH); m->instance_mat = instance; }
void drawHeart(void) { mvstack.push(model_view); set_colour(1.0f, 0.0f, 1.0f); model_view *= RotateZ(-45); drawHcube(); model_view = mvstack.pop(); }
static PixelViewCone Transform(const vec3_t& pos, K rot_sin, K rot_cos, const PixelViewCone& pvc) { return PixelViewCone { pos + pvc.ray_start, RotateZ(rot_sin, rot_cos, pvc.ray_dir), pvc.opening_angle, pvc.weight }; }
void drawLeg(void) { mvstack.push(model_view); set_colour(0,0,0); model_view *= RotateY(90); //glRotatef(90,0,1,0); model_view *= RotateZ(45); //glRotatef(45,0,0,1); model_view *= Scale(0.25f, 0.75f, 0.25f); //glScalef(0.25,0.75,0.25); drawCube(); model_view *= Scale(1.0f, 0.4f, 1.0f); //glScalef(1,0.4,1); model_view *= RotateZ(-67.5); //glRotatef(-67.5,0,0,1); model_view *= Translate(0.5f, -0.66f, 0.0f); //glTranslatef(0.5,-0.66,0); model_view *= RotateZ(pathLegs); //glRotatef(pathLegs,0,0,1); model_view *= Translate(1.0f, -1.5f, 0.0f); //glTranslatef(1,-1.5,0); model_view *= Scale(1.0f, 3.0f, 1.0f); //glScalef(1,3,1); drawCube(); model_view = mvstack.pop(); }
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(); }
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; }
void drawFlowerHead() { mvstack.push(model_view); set_colour(1.0, 0.0, 0.0); model_view *= RotateZ(12*sin(TIME)); model_view *= Translate(0, 9.9, 0); model_view *= Scale(1.5, 1.5, 1.5); drawSphere(); model_view = mvstack.pop(); }