void drawBee() { mvstack.push(model_view); //rotate bee model_view *= RotateY(-10*TIME); model_view *= Translate(0, 5, 0); model_view *= Translate(5, .5*sin(100+TIME), 0); model_view *= RotateY(90); //draw bee parts drawBody(); drawHead(); drawTail(); drawWings(); drawLegz(); 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 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); } }
void XM_CALLCONV Camera::Update( float deltaTime ) { if( GetAsyncKeyState( VK_HOME ) ) { SetCamType(); } if( GetCamType()==1 ) { if( GetAsyncKeyState( VK_LEFT ) ) { RotateY( 5.0f * deltaTime ); } if( GetAsyncKeyState( VK_RIGHT ) ) { RotateY( -5.0f * deltaTime ); } if( GetAsyncKeyState( VK_UP ) ) { Walk( -15.0f * deltaTime ); } if( GetAsyncKeyState( VK_DOWN ) ) { Walk( 15.0f * deltaTime ); } if( GetAsyncKeyState( VK_PRIOR ) ) { Pitch( 1.0f * deltaTime ); } if( GetAsyncKeyState( VK_NEXT ) ) { Pitch( -1.0f * deltaTime ); } if( GetAsyncKeyState( VK_OEM_COMMA ) ) { Strafe( -15.0f * deltaTime ); } if( GetAsyncKeyState( VK_OEM_PERIOD ) ) { Strafe( 15.0f * deltaTime ); } } else { // default camera //XMStoreFloat3( &target1, goblin1Pos); //XMVECTOR posV = XMLoadFloat3( &pos ); //XMVECTOR targetV = goblin1Pos; //XMVECTOR upV = GetUpXM(); //LookAt( posV, targetV, upV ); } UpdateViewMatrix(); }
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 GLWidget::DoRotate(QPoint desc, QPoint orig) { //TODO: adjust the camera position so the viewport is rotated double YRot = (desc.x() - orig.x()) * RadPerPixel; double ZRot = -1 * (desc.y() - orig.y()) * RadPerPixel; RotateY(&CameraPos, YRot); RotateZ(&CameraPos, ZRot); }
void drawLeaf(void) { mvstack.push(model_view); set_colour(0.4f, 1.0f, 0.4f); model_view *= Scale(1.0f, 0.1f, 0.5f); model_view *= RotateY(45); drawCube(); model_view = mvstack.pop(); }
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]; }
//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(); }
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; }
/* 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; }
mat4 getCurrentRotation() { return mat4(); // rotate around the current axis mat4 rotation; if (currentAxis == XAxis) rotation = RotateX(degrees); else if (currentAxis == YAxis) rotation = RotateY(degrees); else rotation = RotateZ(degrees); return rotation; }
// rotire fata de centru, aflat in fata la o distanta data void Camera::RotateYCenter (GLfloat angle, float distance) { if(type!=CameraTypeORBIT) { fprintf(stderr, "Rotatie fata de un centru nepermisa. Tipul curent al camerei: %d\n",type); return ; } MoveForward(distance); RotateY(angle); MoveBackward(distance); }
void cCamera::Update(bool keys[],int mouseX,int mouseY, object *plane) { float angle; float alfa; Map = plane; if(mouseX!=middleX) { angle = (middleX - mouseX) / 50.0f; RotateY(angle); } if(mouseY!=middleY) { angle = (middleY - mouseY) / 50.0f; RotateX(angle); } if (keys['w']) MoveForwards(-speed); if (keys['s']) MoveForwards(speed); if (keys['a']) StrafeRight(-speed); if (keys['d']) StrafeRight(speed); if (keys[' ']) Jump(); // JUMP & GRAVITY if (jumping) { jump_alfa += JUMP_STEP; if (jump_alfa == 180) { jumping = false; Position.y = jump_y; } else { alfa = ((float)jump_alfa) * 0.017453f; Position.y = jump_y + (int)(((float)JUMP_HEIGHT) * sin(alfa)); if (jump_alfa > 90) { //Over floor? jumping = !CollidesMap(GetCollider(), Map); } } } else { //Over floor? if (!CollidesMap(GetCollider(), Map)) Position.y -= (2 * 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]); colorcube(); glBufferSubData( GL_ARRAY_BUFFER, 0, sizeof(points), points ); glBufferSubData( GL_ARRAY_BUFFER, sizeof(points), sizeof(quad_color), quad_color ); glDrawArrays(GL_TRIANGLES, 0, NumVertices); glutSwapBuffers(); }
/************************************************************************ * This is the recursive ray tracer - you need to implement this! * You should decide what arguments to use. ************************************************************************/ RGB_float recursive_ray_trace(Point &pos, Vector &ray, int num, bool inside=false) { IntersectionInfo end; const Object *s = getClosestObject(pos, ray, end); if (s == nullptr) { return background_clr; } Vector norm = s->getNormal(end); if (inside) { norm *= -1; } RGB_float color = phong(end.pos, ray, norm, s); if (num <= step_max) { Vector h; RGB_float ref({0,0,0}); RGB_float ract({0,0,0}); if (!inside && reflect_on) { h = vec_reflect(ray, norm); ref = recursive_ray_trace(end.pos, h, num + 1); } if (stochdiff_on) { RGB_float diff = {0,0,0}; std::default_random_engine generator; std::uniform_int_distribution<int> distribution(-10,10); for (int i = 0; i < STOCH_RAYS; ++i) { h = vec_reflect(ray, norm); h = RotateX(distribution(generator)) * RotateY(distribution(generator)) * RotateZ(distribution(generator)) * h; diff += recursive_ray_trace(end.pos, h, num+1); } diff /= 6; color += (diff*s->reflectance); } if (refract_on) { if (inside) { h = vec_refract(ray, norm, 1.5, 1); } else { h = vec_refract(ray, norm, 1, 1.5); } ract = recursive_ray_trace(end.pos, h, num + 1, !inside); } float reflectWeight = s->reflectance; float refractWeight = 0; if (refract_on && s->transparency > 0) { refractWeight = s->transparency; reflectWeight = (1-refractWeight)*s->reflectance; } color += (ref * reflectWeight + ract * refractWeight); } return color; }
void Cylinder::draw(bool edges, bool mesh) { // Use current object's program glUseProgram(m_program); // Bind buffers #ifdef __APPLE__ glBindVertexArrayAPPLE(m_vertexArrayObject); #else glBindVertexArray(m_vertexArrayObject); #endif glBindBuffer(GL_ARRAY_BUFFER, m_vertexBufferObject); glBindTexture(GL_TEXTURE_2D, m_textureBufferObject); // Get transformation matrices (POSSIBLE ERRORS -> ROTATION AROUND Y) mat4 transform = RotateY(m_rotAngle.y) * Translate(m_location) * RotateZ(m_rotAngle.z) * RotateX(m_rotAngle.x) * Scale(m_size); // Pass uniform data to the shader program glUniformMatrix4fv(glGetUniformLocation(m_program, "wMo"), 1, GL_TRUE, transform); glUniformMatrix4fv(glGetUniformLocation(m_program, "cMw"), 1, GL_TRUE, m_camPtr->getTranslation()); glUniformMatrix4fv(glGetUniformLocation(m_program, "proj"), 1, GL_TRUE, m_camPtr->getPerspective()); // vShader glUniform4fv(glGetUniformLocation(m_program, "camPos"), 1, m_camPtr->getPosition()); glUniform4fv(glGetUniformLocation(m_program, "lightPos"), 1, m_lightPtr->getPosition()); // fShader glUniform1f(glGetUniformLocation(m_program, "Ambient"), m_ambient); glUniform1f(glGetUniformLocation(m_program, "Diffuse"), m_diffuse); glUniform1f(glGetUniformLocation(m_program, "Specular"), m_specular); glUniform1f(glGetUniformLocation(m_program, "Shininess"), m_shininess); glUniform4fv(glGetUniformLocation(m_program, "lightColor"), 1, m_lightPtr->getColor()); // Draw edges if(edges) { glUniform4fv(glGetUniformLocation(m_program, "Color"), 1, vec4(0.0, 0.0, 1.0, 1.0)); glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(0.5, 0.5); glDrawArrays(GL_LINES, m_numVertices, m_numEdges); glDisable(GL_POLYGON_OFFSET_FILL); } // Draw objects if(m_textureOn) glUniform1i(glGetUniformLocation(m_program, "EnableTex"), 1); glUniform4fv(glGetUniformLocation(m_program, "Color"), 1, m_color); if(mesh) glDrawArrays(GL_LINE_STRIP, 0, m_numVertices); else glDrawArrays(GL_TRIANGLES, 0, m_numVertices); glUniform1i(glGetUniformLocation(m_program, "EnableTex"), 0); }
void display( void ){ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); mat4 mv = RotateY(Theta[Yaxis]) * RotateX(Theta[Xaxis]); mat4 rot; glUniformMatrix4fv( model_view, 1, GL_TRUE, mv ); int i,j,k; int offset_points=0; int offset_bytes=0; int num_points = myCube->getNumPoints(); points = myCube->getPoints(); colors = myCube->getColors(); glBufferSubData( GL_ARRAY_BUFFER, 0, sizeof(point4)*num_points, points ); glBufferSubData( GL_ARRAY_BUFFER, sizeof(point4)*num_points, sizeof(color4)*num_points, colors ); bool complete = myCube->checkComplete(); for (i=0;i<3;i++){ for (j=0;j<3;j++){ for (k=0;k<3;k++){ rot = myCube->getRotation(i,j,k); glUniformMatrix4fv( face_rotations, 1, GL_TRUE, rot); glDrawArrays( GL_TRIANGLES, offset_points, num_points/27 ); offset_bytes += sizeof(point4) * num_points/27; offset_points += num_points/27; } } } if (complete){ glutPrint(-0.55f, 0.65f, glutFonts[6], "Congratulations! The Cube is Complete", 0.0f, 0.0f, 0.0f, 1.0f); } glutPrint(-0.8f, -0.5f, glutFonts[5], "Directions", 0.0f, 0.0f, 0.0f, 1.0f); glutPrint(-0.9f, -0.55f, glutFonts[5], "Rotate Face With Red Center: <a>", 0.0f, 0.0f, 0.0f, 1.0f); glutPrint(-0.9f, -0.60f, glutFonts[5], "Rotate Face With Yellow Center: <z>", 0.0f, 0.0f, 0.0f, 1.0f); glutPrint(-0.9f, -0.65f, glutFonts[5], "Rotate Face With Blue Center: <s>", 0.0f, 0.0f, 0.0f, 1.0f); glutPrint(-0.9f, -0.70f, glutFonts[5], "Rotate Face With White Center: <x>", 0.0f, 0.0f, 0.0f, 1.0f); glutPrint(-0.9f, -0.75f, glutFonts[5], "Rotate Face With Green Center: <d>", 0.0f, 0.0f, 0.0f, 1.0f); glutPrint(-0.9f, -0.80f, glutFonts[5], "Rotate Face With Orange Center: <c>", 0.0f, 0.0f, 0.0f, 1.0f); glutPrint(-0.9f, -0.85f, glutFonts[5], "Undo Last Move: <u>", 0.0f, 0.0f, 0.0f, 1.0f); glutPrint(-0.9f, -0.90f, glutFonts[5], "Save Cube: <w> followed by command line input", 0.0f, 0.0f, 0.0f, 1.0f); glutPrint(-0.9f, -0.95f, glutFonts[5], "Exit Program: <esc>", 0.0f, 0.0f, 0.0f, 1.0f); glutPrint(-0.1f, -0.60f, glutFonts[5], "Note: Perform opposite rotation with <shift><rotation key>", 0.0f, 0.0f, 0.0f, 1.0f); glutPrint(-0.1f, -0.65f, glutFonts[5], "Rotate entire cube with left click and drag or arrow keys", 0.0f, 0.0f, 0.0f, 1.0f); glutSwapBuffers(); }
void mouseMotion(int x, int y) { vec2 mousePos = vec2(x,y); GLuint index; // If right mouse pressed, changes in mouse position will rotate scene if (middleMousePressed) { vec2 d = mousePos - mousePosPrev; d *= -ROTATION_FACTOR_MOUSE; rotationMat *= RotateY(d[0]); rotationMat *= RotateX(d[1]); mousePosPrev = mousePos; } }
void openglWidget::mouseMoveEvent(QMouseEvent *event) { int dx = event->x() - lastPos.x(); int dy = event->y() - lastPos.y(); if (event->buttons() & Qt::LeftButton) { RotateX(dx); RotateY(dy); } lastPos = event->pos(); updateGL(); }
void SetupCamera() { glEnable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-1.0,1.0,-1.0,1.0);// i'm not sure about these 1.0 values glViewport(0,0,800,600); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); RotateY(45.0f); TranslateCamera(0,0,0); }
void Camera::SetPolar(Pointf3 dz, Pointf3 dx, double d, double a, double b, double r) { Pointf3 dy = dz % dx; Pointf3 az = RotateX(Pointf3(0, 0, -1), -b); az = d * RotateY(az, a); Pointf3 loc = az * Matrixf3(dx, dy, dz, target); Pointf3 dir = Unit(target - loc); Pointf3 su = Orthogonal(dy, dir); if(Length(su) <= 1e-10) su = Orthogonal(FarthestAxis(dir), dir); su = Unit(su); Location(loc).Upwards(Rotate(su, dir, r)); }
void EnemyShipBase::manToPosition(D3DXVECTOR3 epos) { D3DXVECTOR3 man = epos - position; distance = D3DXVec3Length(&man); D3DXVECTOR3 uman; D3DXVec3Normalize(&uman, &man); angle = acos(D3DXVec3Dot(&uman, &look)); if (angle >= 0) { FLOAT lr = D3DXVec3Dot(&uman, &right); if (lr > 0) RotateY(rotAngle); else RotateY(-rotAngle); FLOAT ud = D3DXVec3Dot(&uman, &up); if (ud > 0) RotateX(-rotAngle); else RotateX(rotAngle); } }
Matrix ModelCompositeW(HomVector T, HomVector R, HomVector S){ Matrix Trans, Sc, TR, Rx, Ry, Rxy, Rz, Rxyz, W; Trans = Translation(T.x, T.y, T.z); Rx = RotateX(R.x); Ry = RotateY(R.y); Rz = RotateZ(R.z); Sc = Scale(S.x, S.y, S.z); Rxy = MatMatMul(Rx, Ry); Rxyz = MatMatMul(Rxy, Rz); TR = MatMatMul(Trans, Rxyz); W = MatMatMul(TR, Sc); return W; }
void CApp::OnRender() { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); mat4 modelViewCamera = LookAt(eye, eye-n, v); glUseProgram(program); // Bind the Ka/Kd/Ks to the shader glUniform4fv( glGetUniformLocation(program, "AmbientProduct"),1, ambient_product); glUniform4fv( glGetUniformLocation(program, "DiffuseProduct"),1, diffuse_product); glUniform4fv( glGetUniformLocation(program, "SpecularProduct"),1,specular_product); glUniform1f( glGetUniformLocation(program, "mat_shininess"), material_shininess); glUniform4fv( glGetUniformLocation(program, "lightPosition"),1, light_position); // Retrieve transformation uniform variable locations ModelViewCam = glGetUniformLocation( program, "modelView" ); ModelViewObj = glGetUniformLocation(program, "ModelViewObj"); Projection = glGetUniformLocation( program, "projection" ); NormalTransformation = glGetUniformLocation( program, "normalTransformation" ); glUniformMatrix4fv(ModelViewCam, 1, GL_TRUE, modelViewCamera); mat4 modelViewObject = RotateZ(roll)*RotateY(yaw)*RotateX(pitch)*Scale(1.0, 2.2, 1.0); mat4 normalMatrix = modelViewCamera*RotateZ(roll)*RotateY(yaw)*RotateX(pitch)*Scale(1.0, 1.0/2.2, 1.0); glUniformMatrix4fv( ModelViewObj, 1, GL_TRUE, modelViewObject ); glUniformMatrix4fv(NormalTransformation , 1, GL_TRUE, normalMatrix); glBindVertexArray( vao ); glDrawArrays( GL_TRIANGLES, 0, NumVertices ); SDL_GL_SwapWindow(Main_window); glUseProgram(0); glBindVertexArray(0); }
Matrix ModelOrigin(){ Vector T = {0.0f, 0.0f, 0.0f}, S = {1.0f, 1.0f, 1.0f}, R = {0.0f, 0.0f, 0.0f}; Matrix Trans, Sc, TR, Rx, Ry, Rxy, Rz, Rxyz, W; Trans = Translation(T.x, T.y, T.z); Rx = RotateX(R.x); Ry = RotateY(R.y); Rz = RotateZ(R.z); Sc = Scale(S.x, S.y, S.z); Rxy = MatMatMul(Rx, Ry); Rxyz = MatMatMul(Rxy, Rz); TR = MatMatMul(Trans, Rxyz); W = MatMatMul(TR, Sc); return W; }
void GameObject::update(float dt) { Matrix rotXM, rotYM, rotZM, transM, scaleM; position += velocity * dt; Identity(&world); RotateX(&rotXM,rotation.x); RotateY(&rotYM,rotation.y); RotateZ(&rotZM,rotation.z); Scale(&scaleM,scale.x,scale.y,scale.z); Translate(&transM, position.x, position.y, position.z); world = scaleM * transM * rotXM * rotYM * rotZM; }
void VineLeaf::draw() { enableTex(true); enableBump(true); enableGloss(true); bindTexture(vine->leaf_texture, TEX_UNIT); bindTexture(vine->leaf_gloss, GLOSS_UNIT); bindTexture(vine->leaf_normal, BUMP_UNIT); setTextureAlpha(1.0); set_colour(1.0, 1.0, 1.0); set_specular(vec4(0.3f)); setBumpScale(0.5f); mstack.push(mModel); mModel *= Translate(0, parent->getLength() * length_along_parent, 0) * RotateY(angle_roll) * Translate(-vine->stem_radius/2, 0, 0) * RotateZ(angle_pitch) * RotateY(angle_turn) * Scale(width, height, width * height); vine->getLeafShape()->draw(); mModel = mstack.pop(); }
Matrix4 Camera::getModelViewMatrix() { GameObject* targetToUse = lookAtTarget; if (lookAtTarget == nullptr) { targetToUse = defaultTarget; } if (position == targetToUse->position) { warnWithMessage("In Camera::getModelViewMatrix(): Camera in same position as lookAtTarget"); } Vector3 worldRot = getWorldRotation(); Vector4 up = RotateX(worldRot.x) * Vector3(0, 1, 0); up = RotateY(worldRot.y) * up; return LookAt(getWorldPosition(), targetToUse->getWorldPosition(), up); }
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(); }