mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-10-13 10:00:43 +00:00
initial commit. This is icculus version 5542b94cae02a6333845854bbbd1abe0a259f1a4
This commit is contained in:
commit
3096eaf5e2
2519 changed files with 816064 additions and 0 deletions
94
Aquaria/Strand.cpp
Normal file
94
Aquaria/Strand.cpp
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
Copyright (C) 2007, 2010 - Bit-Blot
|
||||
|
||||
This file is part of Aquaria.
|
||||
|
||||
Aquaria 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 "Segmented.h"
|
||||
|
||||
Strand::Strand(const Vector &position, int segs, int dist) : RenderObject(), Segmented(dist, dist)
|
||||
{
|
||||
cull = false;
|
||||
segments.resize(segs);
|
||||
for (int i = 0; i < segments.size(); i++)
|
||||
{
|
||||
segments[i] = new RenderObject;
|
||||
}
|
||||
initSegments(position);
|
||||
}
|
||||
|
||||
void Strand::destroy()
|
||||
{
|
||||
RenderObject::destroy();
|
||||
for (int i = 0; i < segments.size(); i++)
|
||||
{
|
||||
segments[i]->destroy();
|
||||
delete segments[i];
|
||||
}
|
||||
segments.clear();
|
||||
}
|
||||
|
||||
void Strand::onUpdate(float dt)
|
||||
{
|
||||
RenderObject::onUpdate(dt);
|
||||
updateSegments(position);
|
||||
}
|
||||
|
||||
void Strand::onRender()
|
||||
{
|
||||
#ifdef BBGE_BUILD_OPENGL
|
||||
const int numSegments = segments.size();
|
||||
if (numSegments == 0) return;
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glTranslatef(-position.x, -position.y, 0);
|
||||
glLineWidth(1);
|
||||
|
||||
glBegin(GL_LINE_STRIP);
|
||||
//glColor4f(0.25,0.25,0.5,1);
|
||||
// Use fixed-point math to speed things up. --achurch
|
||||
unsigned int r = (unsigned int)(color.x * (255<<8));
|
||||
unsigned int g = (unsigned int)(color.y * (255<<8));
|
||||
unsigned int b = (unsigned int)(color.z * (255<<8));
|
||||
unsigned int a = (255<<8);
|
||||
unsigned int dr = r/50;
|
||||
unsigned int dg = g/50;
|
||||
unsigned int db = b/50;
|
||||
unsigned int da = a/numSegments;
|
||||
glColor4ub(r>>8, g>>8, b>>8, a>>8);
|
||||
glVertex2f(position.x, position.y);
|
||||
glVertex2f(segments[0]->position.x, segments[0]->position.y);
|
||||
const int colorLimit = numSegments<50 ? numSegments : 50;
|
||||
int i;
|
||||
for (i = 1; i < colorLimit; i++)
|
||||
{
|
||||
r -= dr;
|
||||
g -= dg;
|
||||
b -= db;
|
||||
a -= da;
|
||||
glColor4ub(r>>8, g>>8, b>>8, a>>8);
|
||||
glVertex2f(segments[i]->position.x, segments[i]->position.y);
|
||||
}
|
||||
for (; i < numSegments; i++)
|
||||
{
|
||||
a -= da;
|
||||
glColor4ub(0, 0, 0, a>>8);
|
||||
glVertex2f(segments[i]->position.x, segments[i]->position.y);
|
||||
}
|
||||
glEnd();
|
||||
#endif
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue