2009-11-04 07:06:36 -08:00
|
|
|
#include "libs.h"
|
|
|
|
#include "HyperspaceCloud.h"
|
|
|
|
#include "Pi.h"
|
|
|
|
#include "Ship.h"
|
|
|
|
#include "Serializer.h"
|
2010-03-10 11:55:35 -08:00
|
|
|
#include "Render.h"
|
2009-11-04 08:53:57 -08:00
|
|
|
#include "Space.h"
|
2009-11-05 06:49:26 -08:00
|
|
|
#include "perlin.h"
|
2009-11-04 07:06:36 -08:00
|
|
|
|
2009-11-04 08:53:57 -08:00
|
|
|
HyperspaceCloud::HyperspaceCloud(Ship *s, double dueDate, bool isArrival)
|
2009-11-04 07:06:36 -08:00
|
|
|
{
|
2009-11-05 06:49:26 -08:00
|
|
|
m_flags = Body::FLAG_CAN_MOVE_FRAME |
|
|
|
|
Body::FLAG_LABEL_HIDDEN;
|
2009-11-04 07:06:36 -08:00
|
|
|
m_ship = s;
|
|
|
|
m_pos = vector3d(0,0,0);
|
2009-11-05 06:49:26 -08:00
|
|
|
m_vel = (s ? s->GetVelocity() : vector3d(0.0));
|
2009-11-04 07:06:36 -08:00
|
|
|
m_birthdate = Pi::GetGameTime();
|
|
|
|
m_due = dueDate;
|
2009-11-05 06:49:26 -08:00
|
|
|
m_id = Pi::rng.Int32();
|
|
|
|
SetIsArrival(isArrival);
|
2009-11-04 07:06:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
HyperspaceCloud::HyperspaceCloud()
|
|
|
|
{
|
|
|
|
m_ship = 0;
|
|
|
|
m_pos = vector3d(0,0,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
HyperspaceCloud::~HyperspaceCloud()
|
|
|
|
{
|
|
|
|
if (m_ship) delete m_ship;
|
|
|
|
}
|
|
|
|
|
2009-11-05 06:49:26 -08:00
|
|
|
void HyperspaceCloud::SetIsArrival(bool isArrival)
|
|
|
|
{
|
|
|
|
m_isArrival = isArrival;
|
|
|
|
SetLabel(isArrival ? "Hyperspace arrival cloud" : "Hyperspace departure cloud");
|
|
|
|
}
|
|
|
|
|
2009-11-04 07:06:36 -08:00
|
|
|
vector3d HyperspaceCloud::GetPosition() const
|
|
|
|
{
|
|
|
|
return m_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HyperspaceCloud::SetPosition(vector3d p)
|
|
|
|
{
|
|
|
|
m_pos = p;
|
|
|
|
}
|
|
|
|
|
2010-05-22 10:26:25 -07:00
|
|
|
void HyperspaceCloud::Save(Serializer::Writer &wr)
|
2009-11-04 07:06:36 -08:00
|
|
|
{
|
2010-05-22 10:26:25 -07:00
|
|
|
Body::Save(wr);
|
|
|
|
wr.Vector3d(m_pos);
|
|
|
|
wr.Vector3d(m_vel);
|
|
|
|
wr.Double(m_birthdate);
|
|
|
|
wr.Double(m_due);
|
|
|
|
wr.Bool(m_isArrival);
|
|
|
|
wr.Bool(m_ship != 0);
|
|
|
|
if (m_ship) m_ship->Serialize(wr);
|
|
|
|
wr.Int32(m_id);
|
2009-11-04 07:06:36 -08:00
|
|
|
}
|
|
|
|
|
2010-05-22 10:26:25 -07:00
|
|
|
void HyperspaceCloud::Load(Serializer::Reader &rd)
|
2009-11-04 07:06:36 -08:00
|
|
|
{
|
2010-05-22 10:26:25 -07:00
|
|
|
Body::Load(rd);
|
|
|
|
m_pos = rd.Vector3d();
|
|
|
|
m_vel = rd.Vector3d();
|
|
|
|
m_birthdate = rd.Double();
|
|
|
|
m_due = rd.Double();
|
|
|
|
m_isArrival = rd.Bool();
|
|
|
|
if (rd.Bool()) {
|
|
|
|
m_ship = (Ship*)Body::Unserialize(rd);
|
2010-01-21 16:30:54 -08:00
|
|
|
}
|
2010-08-03 03:28:18 -07:00
|
|
|
m_id = rd.Int32();
|
2009-11-04 07:06:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void HyperspaceCloud::PostLoadFixup()
|
|
|
|
{
|
2010-01-21 16:30:54 -08:00
|
|
|
if (m_ship) m_ship->PostLoadFixup();
|
2009-11-04 07:06:36 -08:00
|
|
|
}
|
|
|
|
|
2009-11-04 08:53:57 -08:00
|
|
|
void HyperspaceCloud::TimeStepUpdate(const float timeStep)
|
|
|
|
{
|
|
|
|
m_pos += m_vel * timeStep;
|
|
|
|
|
2010-11-05 04:59:28 -07:00
|
|
|
if (m_isArrival && m_ship && (m_due < Pi::GetGameTime())) {
|
2009-11-04 08:53:57 -08:00
|
|
|
// spawn ship
|
|
|
|
m_ship->SetPosition(m_pos);
|
|
|
|
m_ship->SetVelocity(m_vel);
|
|
|
|
m_ship->SetFrame(GetFrame());
|
|
|
|
Space::AddBody(m_ship);
|
|
|
|
m_ship->Enable();
|
|
|
|
m_ship = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-05 06:49:26 -08:00
|
|
|
static void make_circle_thing(float radius, const Color &colCenter, const Color &colEdge)
|
|
|
|
{
|
|
|
|
glColor4fv(colCenter);
|
|
|
|
glBegin(GL_TRIANGLE_FAN);
|
|
|
|
glVertex3f(0,0,0);
|
|
|
|
glColor4fv(colEdge);
|
|
|
|
for (float ang=0; ang<M_PI*2.0; ang+=0.1) {
|
|
|
|
glVertex3f(radius*sin(ang), radius*cos(ang), 0.0f);
|
|
|
|
}
|
|
|
|
glVertex3f(0, radius, 0.0f);
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
2009-11-18 06:59:51 -08:00
|
|
|
void HyperspaceCloud::Render(const vector3d &viewCoords, const matrix4x4d &viewTransform)
|
2009-11-04 07:06:36 -08:00
|
|
|
{
|
2010-09-27 08:05:30 -07:00
|
|
|
Render::State::UseProgram(Render::simpleShader);
|
2009-11-04 07:06:36 -08:00
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glPushMatrix();
|
2009-11-18 06:59:51 -08:00
|
|
|
glTranslatef((float)viewCoords.x, (float)viewCoords.y, (float)viewCoords.z);
|
2009-11-05 06:49:26 -08:00
|
|
|
|
|
|
|
// face the camera dammit
|
2009-11-18 06:59:51 -08:00
|
|
|
vector3d zaxis = viewCoords.Normalized();
|
2009-11-05 06:49:26 -08:00
|
|
|
vector3d xaxis = vector3d::Cross(vector3d(0,1,0), zaxis).Normalized();
|
|
|
|
vector3d yaxis = vector3d::Cross(zaxis,xaxis);
|
|
|
|
matrix4x4d rot = matrix4x4d::MakeRotMatrix(xaxis, yaxis, zaxis).InverseOf();
|
|
|
|
glMultMatrixd(&rot[0]);
|
|
|
|
|
|
|
|
float radius = 1000.0f + 200.0f*noise(10.0*Pi::GetGameTime(), (double)(m_id&0xff), 0);
|
2009-11-04 08:53:57 -08:00
|
|
|
if (m_isArrival) {
|
2009-11-05 06:49:26 -08:00
|
|
|
make_circle_thing(radius, Color(1.0,1.0,1.0,1.0), Color(0.0,0.0,1.0,0.0));
|
2009-11-04 08:53:57 -08:00
|
|
|
} else {
|
2009-11-05 06:49:26 -08:00
|
|
|
make_circle_thing(radius, Color(1.0,1.0,1.0,1.0), Color(1.0,0.0,0.0,0.0));
|
2009-11-04 08:53:57 -08:00
|
|
|
}
|
2009-11-04 07:06:36 -08:00
|
|
|
glPopMatrix();
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
}
|