[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/libs/kgllib/examples/earth
From: Rivo Laks <rivolaks () hot ! ee>
Date: 2008-02-01 15:56:47
Message-ID: 1201881407.301473.6207.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 769504 by rivol:
Add some simple stars
M +26 -1 earth.cpp
M +2 -0 earth.h
--- trunk/playground/libs/kgllib/examples/earth/earth.cpp #769503:769504
@@ -37,7 +37,7 @@
Earth::Earth() : GLWidget()
{
mDiffuseTex = 0;
- mMesh = 0;
+ mMesh = mStarsMesh = 0;
mRotation = 0;
}
@@ -45,6 +45,7 @@
{
delete mDiffuseTex;
delete mMesh;
+ delete mStarsMesh;
}
void Earth::mousePressEvent(QMouseEvent* e)
@@ -75,6 +76,8 @@
mMesh = createMesh(6);
mMesh->setTexture(mDiffuseTex);
glEnable(GL_CULL_FACE);
+
+ mStarsMesh = createStarMesh(2000);
}
void Earth::render()
@@ -84,6 +87,8 @@
// Rotate 20 degrees/sec
mRotation += fpsCounter()->timeElapsed() * 20;
glRotatef(mRotation, 0, 1, 0);
+ mStarsMesh->render();
+ glColor4f(1, 1, 1, 1);
mMesh->render();
int ty = 17;
@@ -192,5 +197,25 @@
return m;
}
+Mesh* Earth::createStarMesh(int stars)
+{
+ Vector3f* vertices = new Vector3f[stars];
+ Vector3f* colors = new Vector3f[stars];
+ for (int i = 0; i < stars; i++) {
+ vertices[i].loadRandomUnit();
+ vertices[i] *= 50;
+ float c = 0.1f + rand()/(float)RAND_MAX * 0.6;
+ colors[i].x() = colors[i].y() = colors[i].z() = c;
+ }
+
+ Mesh* m = new Mesh();
+ m->setVertices(vertices);
+ m->setColors(colors);
+ m->setVertexCount(stars);
+ m->setPrimitiveType(GL_POINTS);
+ return m;
+}
+
+
#include "earth.moc"
--- trunk/playground/libs/kgllib/examples/earth/earth.h #769503:769504
@@ -45,9 +45,11 @@
virtual void mouseMoveEvent(QMouseEvent* e);
Mesh* createMesh(int detail);
+ Mesh* createStarMesh(int stars);
private:
Mesh* mMesh;
+ Mesh* mStarsMesh;
TrackBall trackball;
Texture* mDiffuseTex;
float mRotation;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic