//! Billboard object class /*! * Quick and easy class for displaying billboards */ /* Copyright (C) 2010 Alejandro Valenzuela Roca, * * This file is part of MotorJ, a free framework for videogame creation. * * * * MotorJ is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * MotorJ is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with MotorJ. If not, see . */ #include "billboard-class.h" mjBillboard::mjBillboard(vector3 * cameraPos) { cPos = cameraPos; v3_i(&drawUp); v3_1(&scale); r.u = 1; r.v = 1; bList = glGenLists(1); glNewList(bList, GL_COMPILE); glBegin(GL_QUADS); glTexCoord2f(1,1); glVertex2f(0.5, 0.5); glTexCoord2f(1,0); glVertex2f(-0.5, 0.5); glTexCoord2f(0,0); glVertex2f(-0.5, -0.5); glTexCoord2f(0,1); glVertex2f(0.5, -0.5); glEnd(); //mjPlane(r.u, r.v); glEndList(); } mjBillboard::~mjBillboard() { glDeleteLists(bList, 1); } void mjBillboard::Draw() { // drawUpdate dir to camera vec_copy(*cPos,&drawDir); vec_sum(-1, p, &drawDir); //drawDir.y = 0; normalize(&drawDir); drawUp.x = -0.5*drawDir.y*drawDir.z; drawUp.y = drawDir.x*drawDir.z; drawUp.z = -0.5*drawDir.y*drawDir.x; normalize(&drawUp); push(); obj_pos_rot(p, drawDir, drawUp); glBindTexture(GL_TEXTURE_2D, tex); glScalef(scale.x, scale.y, scale.z); glCallList(bList); glBindTexture(NULL, tex); pop(); }