Skip to content

Commit

Permalink
Subclass Element to TexturedElement
Browse files Browse the repository at this point in the history
  • Loading branch information
Fudge committed Mar 17, 2008
1 parent d64924a commit 2c60be1
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 11 deletions.
17 changes: 14 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#############################################################################
# Makefile for building: ../bin/gltrail
# Generated by qmake (2.01a) (Qt 4.3.2) on: Mon Mar 17 11:53:50 2008
# Generated by qmake (2.01a) (Qt 4.3.2) on: Mon Mar 17 15:20:17 2008
# Project: src.pro
# Template: app
# Command: /usr/bin/qmake -unix -o Makefile src.pro
Expand Down Expand Up @@ -45,6 +45,7 @@ OBJECTS_DIR = ./
SOURCES = main.cpp \
activity.cpp \
element.cpp \
textured_element.cpp \
window.cpp \
glwidget.cpp \
background_updater.cpp \
Expand All @@ -60,6 +61,7 @@ SOURCES = main.cpp \
OBJECTS = main.o \
activity.o \
element.o \
textured_element.o \
window.o \
glwidget.o \
background_updater.o \
Expand Down Expand Up @@ -169,7 +171,7 @@ qmake: FORCE

dist:
@$(CHK_DIR_EXISTS) .tmp/gltrail1.0.0 || $(MKDIR) .tmp/gltrail1.0.0
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/gltrail1.0.0/ && $(COPY_FILE) --parents input.h element.h activity.h relation.h window.h glwidget.h background_updater.h inputs/ssh.h inputs/digg.h inputs/twitter.h .tmp/gltrail1.0.0/ && $(COPY_FILE) --parents main.cpp activity.cpp element.cpp window.cpp glwidget.cpp background_updater.cpp input.cpp inputs/ssh.cpp inputs/digg.cpp inputs/twitter.cpp .tmp/gltrail1.0.0/ && (cd `dirname .tmp/gltrail1.0.0` && $(TAR) gltrail1.0.0.tar gltrail1.0.0 && $(COMPRESS) gltrail1.0.0.tar) && $(MOVE) `dirname .tmp/gltrail1.0.0`/gltrail1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/gltrail1.0.0
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/gltrail1.0.0/ && $(COPY_FILE) --parents input.h element.h textured_element.h activity.h relation.h window.h glwidget.h background_updater.h inputs/ssh.h inputs/digg.h inputs/twitter.h .tmp/gltrail1.0.0/ && $(COPY_FILE) --parents main.cpp activity.cpp element.cpp textured_element.cpp window.cpp glwidget.cpp background_updater.cpp input.cpp inputs/ssh.cpp inputs/digg.cpp inputs/twitter.cpp .tmp/gltrail1.0.0/ && (cd `dirname .tmp/gltrail1.0.0` && $(TAR) gltrail1.0.0.tar gltrail1.0.0 && $(COMPRESS) gltrail1.0.0.tar) && $(MOVE) `dirname .tmp/gltrail1.0.0`/gltrail1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/gltrail1.0.0


clean:compiler_clean
Expand Down Expand Up @@ -258,11 +260,20 @@ element.o: element.cpp element.h \
relation.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o element.o element.cpp

textured_element.o: textured_element.cpp textured_element.h \
element.h \
input.h \
glwidget.h \
activity.h \
relation.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o textured_element.o textured_element.cpp

window.o: window.cpp window.h \
glwidget.h \
input.h \
inputs/ssh.h \
inputs/digg.h
inputs/digg.h \
inputs/twitter.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o window.o window.cpp

glwidget.o: glwidget.cpp glwidget.h \
Expand Down
7 changes: 4 additions & 3 deletions src/element.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,20 @@
/**
@author Erlend Simonsen <mr@fudgie.org>
*/
class Element{
class Element {

public:
Element() {};
Element(Input *h, QString name, QColor col, bool referrer = false);

virtual ~Element();

void render(GLWidget *gl);
void renderRelations(GLWidget *gl);
virtual void render(GLWidget *gl);
virtual void renderRelations(GLWidget *gl);

void update(GLWidget *gl);
void update_stats(void);

bool contains(GLWidget *gl, Element *e);
void repulsive_check(GLWidget *gl, Element *e);
void attractive_check(GLWidget *gl, Element *e);
Expand Down
10 changes: 5 additions & 5 deletions src/glwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
***************************************************************************/
#include "glwidget.h"
#include "element.h"
#include "textured_element.h"
#include <QHash>

using namespace std;

#include <iostream>
#include <stdlib.h>
#include <list>
Expand All @@ -31,6 +29,8 @@ using namespace std;
#include <sys/time.h>
#include <math.h>

using namespace std;

Elements elements;
Nodes nodes;

Expand Down Expand Up @@ -110,7 +110,7 @@ void GLWidget::initializeGL()
// glEnable(GL_LIGHTING);
// glEnable(GL_LIGHT0);

glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_2D);

glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
Expand Down Expand Up @@ -413,7 +413,7 @@ void GLWidget::addRelation(Input *h, QString &url, QString &ref, bool external)

if( elements.contains(h->getDomain() + url) == false ) {
QColor color = h->getColor();
elements[h->getDomain() + url] = new Element(h, url, color);
elements[h->getDomain() + url] = new TexturedElement(this, h, url, color);
nodes.push_back( elements[h->getDomain() + url] );
}

Expand Down
2 changes: 2 additions & 0 deletions src/src.pro
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CONFIG += debug
SOURCES += main.cpp \
activity.cpp \
element.cpp \
textured_element.cpp \
window.cpp \
glwidget.cpp \
background_updater.cpp \
Expand All @@ -14,6 +15,7 @@ SOURCES += main.cpp \

HEADERS += input.h \
element.h \
textured_element.h \
activity.h \
relation.h \
window.h \
Expand Down
90 changes: 90 additions & 0 deletions src/textured_element.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/***************************************************************************
* Copyright (C) 2008 by Erlend Simonsen *
* mr@fudgie.org *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "textured_element.h"
#include <iostream>
#include <stdlib.h>
#include <math.h>

using namespace std;

TexturedElement::TexturedElement(GLWidget *glWidget, Input *h, QString name, QColor col, bool referrer)
: Element(h, name, col, referrer)
{
gl = glWidget;

QImage img("/home/erlends/src/ruby/cit/public/images/add.png");

texId = gl->bindTexture(img);
}

TexturedElement::~TexturedElement()
{
gl->deleteTexture(texId);
}

void TexturedElement::render(GLWidget *gl) {
GLfloat r = 0.004 + (size - 1.0) / 100;


glColor4f(1.0, 1.0, 1.0, 1.0);
glBindTexture(GL_TEXTURE_2D, texId);
glBegin(GL_QUADS);

glTexCoord2d(0,0);
glVertex3d( x-r, y-r, 0.0);

glTexCoord2d(1,0);
glVertex3d( x+r, y-r, 0.0);

glTexCoord2d(1,1);
glVertex3d( x+r, y+r, 0.0);

glTexCoord2d(0,1);
glVertex3d( x-r, y+r, 0.0);

glEnd();

if( activity_queue.size() > 0 && rand() % (60/activity_queue.size()) == 0 ) {

Activity *a = activity_queue.takeFirst();
activities << a;
if( gl->useRecoil() ) {
a->fire();
}
}

glBegin(GL_POINTS);
for(Activities::iterator it = activities.begin(); it != activities.end(); ++it) {
if( (*it)->render(gl) ) {
if( gl->useRecoil() ) {
(*it)->impact();
}
delete *it;
it = activities.erase(it);
}
}
glEnd();
glPointSize(1.0);
}

void TexturedElement::renderRelations(GLWidget *gl) {
Element::renderRelations(gl);
}

49 changes: 49 additions & 0 deletions src/textured_element.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/***************************************************************************
* Copyright (C) 2008 by Erlend Simonsen *
* mr@fudgie.org *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef TEXTURED_ELEMENT_H
#define TEXTURED_ELEMENT_H

#include <list>
#include <QWidget>
#include <QtOpenGL>
#include "element.h"

/**
@author Erlend Simonsen <mr@fudgie.org>
*/

class TexturedElement : public Element {

public:
TexturedElement(GLWidget *glWidget, Input *h, QString name, QColor col, bool referrer = false);

~TexturedElement();

void render(GLWidget *gl);
void renderRelations(GLWidget *gl);

private:
GLuint texId;
GLWidget *gl;

};


#endif

0 comments on commit 2c60be1

Please sign in to comment.