From patchwork Thu Jul 21 12:36:31 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandros Frantzis X-Patchwork-Id: 2989 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 2E78123F4D for ; Thu, 21 Jul 2011 12:43:51 +0000 (UTC) Received: from mail-qy0-f180.google.com (mail-qy0-f180.google.com [209.85.216.180]) by fiordland.canonical.com (Postfix) with ESMTP id F21EDA18326 for ; Thu, 21 Jul 2011 12:43:50 +0000 (UTC) Received: by mail-qy0-f180.google.com with SMTP id 30so845420qyk.11 for ; Thu, 21 Jul 2011 05:43:50 -0700 (PDT) Received: by 10.229.217.3 with SMTP id hk3mr209857qcb.38.1311252230761; Thu, 21 Jul 2011 05:43:50 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.229.217.78 with SMTP id hl14cs139563qcb; Thu, 21 Jul 2011 05:43:50 -0700 (PDT) Received: by 10.216.65.75 with SMTP id e53mr164407wed.69.1311251795125; Thu, 21 Jul 2011 05:36:35 -0700 (PDT) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id 21si2398860wel.27.2011.07.21.05.36.34; Thu, 21 Jul 2011 05:36:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) client-ip=91.189.90.139; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) smtp.mail=bounces@canonical.com Received: from loganberry.canonical.com ([91.189.90.37]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1QjsUS-0000DP-RN for ; Thu, 21 Jul 2011 12:36:33 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id 0FCA22E895C for ; Thu, 21 Jul 2011 12:36:31 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: glmark2 X-Launchpad-Branch: ~glmark2-dev/glmark2/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 16 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~glmark2-dev/glmark2/trunk] Rev 16: Add Matrix4f::perspective(), Matrix4f::identity() and copy constructor. Message-Id: <20110721123631.17019.49056.launchpad@loganberry.canonical.com> Date: Thu, 21 Jul 2011 12:36:31 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="13475"; Instance="initZopeless config overlay" X-Launchpad-Hash: 9e27b5127708a95257d08a2c9c05170a6c50bdc4 ------------------------------------------------------------ revno: 16 committer: Alexandros Frantzis timestamp: Thu 2010-07-08 15:51:29 +0300 message: Add Matrix4f::perspective(), Matrix4f::identity() and copy constructor. modified: matrix.cpp matrix.h --- lp:glmark2 https://code.launchpad.net/~glmark2-dev/glmark2/trunk You are subscribed to branch lp:glmark2. To unsubscribe from this branch go to https://code.launchpad.net/~glmark2-dev/glmark2/trunk/+edit-subscription === modified file 'matrix.cpp' --- matrix.cpp 2010-07-08 08:07:56 +0000 +++ matrix.cpp 2010-07-08 12:51:29 +0000 @@ -94,9 +94,9 @@ Matrix4f &Matrix4f::transpose() { GLfloat t[16] = { - m[0], m[4], m[8], m[12], - m[1], m[5], m[9], m[13], - m[2], m[6], m[10], m[14], + m[0], m[4], m[8], m[12], + m[1], m[5], m[9], m[13], + m[2], m[6], m[10], m[14], m[3], m[7], m[11], m[15]}; memcpy(m, t, sizeof(m)); @@ -104,6 +104,56 @@ return *this; } +/** + * Makes this matrix an identity matrix. + * + * @return reference to the matrix + */ +Matrix4f &Matrix4f::identity() +{ + m[0] = 1.0; m[4] = 0.0; m[8] = 0.0; m[12] = 0.0; + m[1] = 0.0; m[5] = 1.0; m[9] = 0.0; m[13] = 0.0; + m[2] = 0.0; m[6] = 0.0; m[10] = 1.0; m[14] = 0.0; + m[3] = 0.0; m[7] = 0.0; m[11] = 0.0; m[15] = 1.0; + + return *this; +} + +/** + * Makes this matrix a perspective projection matrix. + * + * @param fovy field of view angle in degrees in the y direction + * @param aspect aspect ratio of view + * @param zNear the distance from the viewer to the near clipping plane + * @param zFar the distance from the viewer to the far clipping plane + * + * @return reference to the matrix + */ +Matrix4f &Matrix4f::perspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar) +{ + GLfloat sine, cotangent, deltaZ; + GLfloat radians = fovy / 2 * M_PI / 180; + + deltaZ = zFar - zNear; + sine = sin(radians); + + if ((deltaZ == 0) || (sine == 0) || (aspect == 0)) { + return *this; + } + + cotangent = cos(radians) / sine; + + identity(); + m[0] = cotangent / aspect; + m[5] = cotangent; + m[10] = -(zFar + zNear) / deltaZ; + m[11] = -1; + m[14] = -2 * zNear * zFar / deltaZ; + m[15] = 0; + + return *this; +} + /** * Creates an empty matrix. * @@ -116,6 +166,11 @@ m[15] = 1.0; } +Matrix4f::Matrix4f(Matrix4f &mat) +{ + memcpy(m, mat.m, sizeof(m)); +} + /** * Creates a matrix with specified values in the diagonal. * @@ -141,7 +196,6 @@ */ void Matrix4f::display(const char *str) { - return; int r; if (str != NULL) printf("%s\n", str); === modified file 'matrix.h' --- matrix.h 2010-07-08 08:07:56 +0000 +++ matrix.h 2010-07-08 12:51:29 +0000 @@ -13,11 +13,14 @@ GLfloat m[16]; Matrix4f(); + Matrix4f(Matrix4f &mat); Matrix4f(GLfloat x, GLfloat y, GLfloat z); Matrix4f &translate(GLfloat x, GLfloat y, GLfloat z); Matrix4f &rotate(GLfloat angle, GLfloat x, GLfloat y, GLfloat z); Matrix4f &transpose(); + Matrix4f &perspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar); + Matrix4f &identity(); Matrix4f &operator*=(const Matrix4f &pM);