AnoPlib - Animlets are not Particles library
 All Data Structures Namespaces Files Functions Variables
AnoPstarfield1.h
Go to the documentation of this file.
00001 /* *************************************************************************
00002    @file       AnoPstarfield1.h
00003    @project    AnoPlib
00004    @module     AnoPstarfield1
00005    @brief      Old-style c64 stars scroller
00006    @date       23.11.2010
00007    @copyright  Daniel Krajzewicz
00008    @licence    GPL
00009    @author     Daniel Krajzewicz
00010    @email      d.krajzewicz@googlemail.com
00011    ------------------------------------------------------------------
00012     AnoPlib - small "animlet" library, see http://sf.net/projects/anoplib
00013     Copyright (C) 2009-2010 Daniel Krajzewicz
00014 
00015     This program is free software: you can redistribute it and/or modify
00016     it under the terms of the GNU General Public License as published by
00017     the Free Software Foundation, either version 3 of the License, or
00018     (at your option) any later version.
00019 
00020     This program is distributed in the hope that it will be useful,
00021     but WITHOUT ANY WARRANTY; without even the implied warranty of
00022     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023     GNU General Public License for more details.
00024 
00025     You should have received a copy of the GNU General Public License
00026     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00027    ------------------------------------------------------------------
00028    Remarks:
00029    ------------------------------------------------------------------
00030    ToDo:
00031  * *********************************************************************** */
00032 #ifndef ANOP_STARFIELD1
00033 #define ANOP_STARFIELD1
00034 
00035 
00036 /* =========================================================================
00037  * included modules
00038  * ======================================================================= */
00039 #include <AnoP.h>
00040 #include <GL/gl.h>
00041 
00042 
00043 /* =========================================================================
00044  * class and struct definitions
00045  * ======================================================================= */
00046 // @brief The animlet definition structure
00047 struct starfield1Struct {
00049     double pos[2];
00051     double speed;
00052 };
00053     
00054     
00058 class AnoPstarfield1 : public AnoP::AnoPsystem<starfield1Struct> {
00059 public:
00063     AnoPstarfield1(unsigned int bufSize=10) : AnoP::AnoPsystem<starfield1Struct>(bufSize) {}
00064 
00065 
00068     void preRender() throw() {
00069         glMatrixMode(GL_PROJECTION);
00070         glLoadIdentity();
00071         glMatrixMode(GL_MODELVIEW);
00072         glLoadIdentity();
00073         glTranslated(-1,-1,0);
00074         glScaled(1./20, 1./20, 1.);
00075         glTranslated(0,15,0);
00076     }
00077 
00078 
00084     bool render(starfield1Struct &s, unsigned int timeDiff, void * const something) throw() {
00085         glColor3d(1,1,1);
00086         glBegin(GL_POINTS);
00087         glVertex3f(s.pos[0], s.pos[1], 0);
00088         glEnd();
00089         s.pos[0] = s.pos[0] - s.speed;
00090         if(s.pos[0]<0) {
00091             s.pos[0] = 40;
00092         }
00093         return true;
00094     }
00095 };
00096 
00097 #endif