summaryrefslogtreecommitdiff
path: root/scene.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene.cpp')
-rw-r--r--scene.cpp83
1 files changed, 82 insertions, 1 deletions
diff --git a/scene.cpp b/scene.cpp
index f994627..0c31bc8 100644
--- a/scene.cpp
+++ b/scene.cpp
@@ -39,11 +39,20 @@ Scene::Scene() {
glUniform1i(markloc, 3);
glUseProgram(0);
+ GLFragmentShader selection_fragment("shaders/selection_fragment.glsl");
+ GLVertexShader selection_vertex("shaders/selection_vertex.glsl");
+ selection_program.attach(selection_fragment);
+ selection_program.attach(selection_vertex);
+ selection_program.link();
+
+ selection_particles = NULL;
+
/* load textures */
grass_texture = load_texture("textures/zooboing-366-grass.jpg");
rock_texture = load_texture("textures/zooboing-825-stone-modified.jpg");
soil_texture = load_texture("textures/zooboing-469-sand-modified.jpg");
marker_texture = load_texture("textures/cross.png");
+ circle_texture = load_texture("textures/circle.png");
/* load heightmap */
SDL_Surface *hm = IMG_Load("heightmap.png");
@@ -200,8 +209,11 @@ void Scene::events() {
case SDL_BUTTON_RIGHT:
if(dialog)
CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::RightButton);
- else
+ else {
show_selection = false;
+ delete selection_particles;
+ selection_particles = NULL;
+ }
break;
case SDL_BUTTON_WHEELUP:
if(dialog)
@@ -397,6 +409,71 @@ void Scene::render() {
do_select = false;
selected = Vector3(px, py, pz);
show_selection = true;
+ if(selection_particles)
+ delete selection_particles;
+ selection_particles = new ParticleGroup<SelectionParticle>(selected, Vector3(0, 1, 0), 1000);
+ }
+
+ float pdist;
+ if(selection_particles && (pdist = (selected.xz() - pos.xz()).length()) < 100) {
+ Quadtree::QuadNode *node = qt->find(selected.x, selected.z);
+ selected.y = node->get_height(selected.x, selected.z);
+ selection_particles->src = selected;
+ glPushMatrix();
+ glTranslatef(selection_particles->src.x, selection_particles->src.y, selection_particles->src.z);
+ GLdouble m[16];
+ glGetDoublev(GL_MODELVIEW_MATRIX, m);
+ Vector3 up(m[0], m[4], m[8]);
+ Vector3 right(m[1], m[5], m[9]);
+ GLdouble temp[3] = {m[3], m[7], m[11]};
+ m[3] = m[12];
+ m[7] = m[13];
+ m[11] = m[14];
+ m[12] = temp[0];
+ m[13] = temp[1];
+ m[14] = temp[2];
+ m[0] = 1; m[4] = 0; m[8] = 0;
+ m[1] = 0; m[5] = 1; m[9] = 0;
+ m[2] = 0; m[6] = 0; m[10] = 1;
+ //glLoadMatrixd(m);
+ //glRotatef(yaw*180/M_PI, 0, 1, 0);
+ //glTranslatef(selection_particles->src.x, selection_particles->src.y, selection_particles->src.z);
+ //glRotatef(-yaw*180/M_PI, 0, 1, 0);
+ //glRotatef(-yaw*180/M_PI+90, 0, 1, 0);
+
+ glDepthMask(GL_FALSE);
+ selection_particles->update(steps);
+ selection_program.use();
+ GLint dist = glGetUniformLocation(selection_program.get_program(), "dist");
+ glUniform1f(dist, pdist);
+ glPointSize(100);
+ const GLfloat att[3] = {1, .01, 0};
+ glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, att);
+ glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
+ glEnable(GL_POINT_SPRITE);
+ glEnable(GL_BLEND);
+ //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ //glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
+ glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D, circle_texture);
+ glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
+ glVertexPointer(4, GL_FLOAT, 0, selection_particles->vertices);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glDrawArrays(GL_POINTS, 0, selection_particles->count);
+ glDisableClientState(GL_VERTEX_ARRAY);
+ //glBegin(GL_QUADS);
+ /*glBegin(GL_POINTS);
+ for(std::list<Particle>::iterator it = selection_particles->particles.begin(); it != selection_particles->particles.end(); it++) {
+ glColor4f(1, 1, 1, it->alpha);
+ glVertex3f(it->pos.x, it->pos.y, it->pos.z);
+ }
+ glEnd();*/
+ glDisable(GL_TEXTURE_2D);
+ glDisable(GL_BLEND);
+ glUseProgram(0);
+ glDepthMask(GL_TRUE);
+ glPopMatrix();
}
video::ortho();
@@ -413,6 +490,10 @@ void Scene::render() {
font->Render(move_str.c_str());
glTranslatef(0, -height, 0);
font->Render(selected.str().c_str());
+ if(selection_particles) {
+ glTranslatef(0, -height, 0);
+ font->Render((boost::format("particles: %d") % selection_particles->count).str().c_str());
+ }
/*if(selected) {
glTranslatef(0, height, 0);
//font->Render((boost::format("(%s %s %s %s)") % selected->a->str() % selected->b->str() % selected->c->str() % selected->d->str()).str().c_str());