Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

The normals in the hand are not quite correct. Something I do not und…

…erstand.

If normals are not ok, neither are collisions.  Perhaps I did not output
obj file correctly from Blender.
  • Loading branch information...
commit 960059f779a6f5c289e524a21b3d95a0ae09d62d 1 parent 607024e
erlebach authored
View
11,427 data/arm1_faces.txt
5,713 additions, 5,714 deletions not shown
View
11,474 data/arm1_normal.txt
5,737 additions, 5,737 deletions not shown
View
54 rtpslib/materials_lights.h
@@ -0,0 +1,54 @@
+const GLfloat light_ambient[] = { 0.4f, 0.4f, 0.04, 1.0f };
+const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
+const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
+const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };
+
+const GLfloat mat_ambient[] = { 0.2f, 0.2f, 1.0f, 1.0f };
+const GLfloat mat_diffuse[] = { 0.2f, 0.8f, 1.0f, 1.0f };
+const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
+const GLfloat high_shininess[] = { 100.0f };
+
+const GLfloat mat_ambient_back[] = { 0.5f, 0.2f, 0.2f, 1.0f };
+const GLfloat mat_diffuse_back[] = { 1.0f, 0.2f, 0.2f, 1.0f };
+
+// Program entry point
+
+
+void define_lights_and_materials()
+{
+
+ // Ambient: color in the absence of light
+ glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
+ glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
+ glLightfv(GL_LIGHT0, GL_POSITION, light_position);
+
+ glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
+ glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
+ glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
+ glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
+
+ glMaterialfv(GL_BACK, GL_AMBIENT, mat_ambient_back);
+ glMaterialfv(GL_BACK, GL_DIFFUSE, mat_diffuse_back);
+ glMaterialfv(GL_BACK, GL_SPECULAR, mat_specular);
+ glMaterialfv(GL_BACK, GL_SHININESS, high_shininess);
+
+ // lighting only has effect if lighting is on
+ // color of vertices have no effect without material
+ // if phone is one (GL_SMOOTH)
+
+ glEnable(GL_LIGHT0);
+ glEnable(GL_LIGHT_MODEL_TWO_SIDE);
+
+ // I don't really undersand GL_COLOR_MATERIAL
+ glEnable(GL_COLOR_MATERIAL);
+ //glEnable(GL_LIGHTING);
+ glEnable(GL_NORMALIZE); // makes sure normal remain unit length
+
+ // Blending is only active when blending mode is ON
+ // Page 129 in GLUT course
+ //glEnable(GL_BLEND);
+ //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+}
+//------------------------------------------------------
+
View
28 rtpslib/render/Render.cpp
@@ -112,8 +112,8 @@ namespace rtps
glDepthMask(GL_TRUE);
glEnable(GL_LIGHTING);
renderPointCloud(); //GE
- glDepthMask(GL_FALSE);
glDisable(GL_LIGHTING);
+ glDepthMask(GL_FALSE);
if (blending)
@@ -189,18 +189,36 @@ namespace rtps
glBegin(GL_QUADS);
for (int i=0; i < nb_faces; i++) {
int4& vertices = (*cloud_faces)[i];
+ int4& normals = (*cloud_faces_normals)[i];
+ //vertices.print("v");
+ //normals.print("n");
//printf("ver: %d, %d, %d, %d\n", vertices.x, vertices.y, vertices.z, vertices.w);
float4& v1 = (*cloud_positions)[vertices.x];
- //v1.print("v1");
+ float4& n1 = (*cloud_normals)[normals.x];
+ v1.print("v1");
+ n1.print("n1");
+ glNormal3f(n1.x, n1.y, n1.z);
glVertex3f(v1.x, v1.y, v1.z);
+
float4& v2 = (*cloud_positions)[vertices.y];
- //v2.print("v2");
+ float4& n2 = (*cloud_normals)[normals.y];
+ v2.print("v2");
+ n2.print("n2");
+ glNormal3f(n2.x, n2.y, n2.z);
glVertex3f(v2.x, v2.y, v2.z);
+
float4& v3 = (*cloud_positions)[vertices.z];
- //v3.print("v3");
+ float4& n3 = (*cloud_normals)[normals.z];
+ v3.print("v3");
+ n3.print("n3");
+ glNormal3f(n3.x, n3.y, n3.z);
glVertex3f(v3.x, v3.y, v3.z);
+
float4& v4 = (*cloud_positions)[vertices.w];
- //v4.print("v4");
+ float4& n4 = (*cloud_normals)[normals.w];
+ v4.print("v4");
+ n4.print("n4");
+ glNormal3f(n4.x, n4.y, n4.z);
glVertex3f(v4.x, v4.y, v4.z);
}
glEnd();
View
3  rtpslib/render/Render.h
@@ -112,6 +112,7 @@ namespace rtps
std::vector<float4>* cloud_positions;
std::vector<float4>* cloud_normals;
std::vector<int4>* cloud_faces;
+ std::vector<int4>* cloud_faces_normals;
int cloud_num;
protected:
@@ -167,12 +168,14 @@ namespace rtps
std::vector<float4>& setCloudData(std::vector<float4>& cloud_positions,
std::vector<float4>& cloud_normals,
std::vector<int4>& cloud_faces,
+ std::vector<int4>& cloud_faces_normals,
int nb_points)
{
// cloud_positions.size() >= cloud_num;
this->cloud_positions = &cloud_positions;
this->cloud_normals = &cloud_normals;
this->cloud_faces = &cloud_faces;
+ this->cloud_faces_normals = &cloud_faces_normals;
this->cloud_num = nb_points;
}
protected:
View
30 rtpslib/system/SPH.cpp
@@ -154,7 +154,7 @@ namespace rtps
//addHollowBall(2000, center, radius_in, radius_out, scaled, cloud_normals);
int nn = 4000;
//addNewxyPlane(nn, scaled, cloud_normals);
- readPointCloud(cloud_positions, cloud_normals, cloud_faces);
+ readPointCloud(cloud_positions, cloud_normals, cloud_faces, cloud_faces_normals);
// ADD A SWITCH TO HANDLE CLOUD IF PRESENT
// Must be called after a point cloud has been created.
@@ -172,7 +172,7 @@ namespace rtps
// only needs to be done once if cloud not moving
// ideally, cloud should be stored in vbos.
cl_cloud_position_u.copyToHost(cloud_positions);
- renderer->setCloudData(cloud_positions, cloud_normals, cloud_faces, cloud_num);
+ renderer->setCloudData(cloud_positions, cloud_normals, cloud_faces, cloud_faces_normals, cloud_num);
}
SPH::~SPH()
@@ -996,11 +996,18 @@ printf("cloud_positions size: %d\n", cloud_normals.size());
//----------------------------------------------------------------------
void SPH::readPointCloud(std::vector<float4>& cloud_positions,
std::vector<float4>& cloud_normals,
- std::vector<int4>& cloud_faces)
+ std::vector<int4>& cloud_faces,
+ std::vector<int4>& cloud_faces_normals)
{
- std::string file_vertex = "/Users/erlebach/arm1_vertex.txt";
- std::string file_normal = "/Users/erlebach/arm1_normal.txt";
- std::string file_face = "/Users/erlebach/arm1_faces.txt";
+ //std::string file_vertex = "/Users/erlebach/arm1_vertex.txt";
+ //std::string file_normal = "/Users/erlebach/arm1_normal.txt";
+ //std::string file_face = "/Users/erlebach/arm1_faces.txt";
+
+ std::string base = "/Users/erlebach/Documents/src/blender-particles/EnjaParticles/data/";
+
+ std::string file_vertex = base + "arm1_vertex.txt";
+ std::string file_normal = base + "arm1_normal.txt";
+ std::string file_face = base + "arm1_faces.txt";
// I should really do: resize(cloud_num) which is initially zero
cloud_positions.resize(0);
@@ -1008,6 +1015,10 @@ printf("cloud_positions size: %d\n", cloud_normals.size());
cloud_faces.resize(0);
FILE* fd = fopen((const char*) file_vertex.c_str(), "r");
+ if (fd == 0) {
+ printf("cannot open: %s\n", file_vertex.c_str());
+ exit(1);
+ }
int nb = 5737;
float x, y, z;
for (int i=0; i < nb; i++) {
@@ -1096,17 +1107,12 @@ printf("cloud_positions size: %d\n", cloud_normals.size());
//exit(1);
//printf("--------------------\n");
cloud_faces.push_back(int4(v1,v2,v3,v4)); // forms a face
+ cloud_faces_normals.push_back(int4(n1,n2,n3,n4)); // forms a face
}
- //printf("cloud_faces.size= %d\n", cloud_faces.size());
- //cloud_faces[0].print("cloud faces[0]");
- //exit(0);
-
// push onto GPU
pushCloudParticles(cloud_positions, cloud_normals);
-printf("*** cloud_num= %d\n", cloud_num);
-//exit(1);
}
//----------------------------------------------------------------------
View
4 rtpslib/system/SPH.h
@@ -76,7 +76,8 @@ namespace rtps
void readPointCloud(std::vector<float4>& cloud_positions,
std::vector<float4>& cloud_normals,
- std::vector<int4>& cloud_faces);
+ std::vector<int4>& cloud_faces,
+ std::vector<int4>& cloud_faces_normals);
//wrapper around Hose.h
int addHose(int total_n, float4 center, float4 velocity, float radius, float4 color=float4(1.0, 0.0, 0.0, 1.0f));
@@ -160,6 +161,7 @@ namespace rtps
std::vector<float4> cloud_positions;
std::vector<float4> cloud_normals;
std::vector<int4> cloud_faces;
+ std::vector<int4> cloud_faces_normals;
Buffer<float4> cl_cloud_position_u;
Buffer<float4> cl_cloud_position_s;
Buffer<float4> cl_cloud_normal_u;
View
17 test/main.cpp
@@ -23,8 +23,10 @@
using namespace rtps;
-int window_width = 640;
-int window_height = 480;
+//int window_width = 640;
+//int window_height = 480;
+int window_width = 640*2;
+int window_height = 480*2;
int glutWindowHandle = 0;
@@ -113,8 +115,9 @@ rtps::RTPS* ps;
#define DT .003f
-//float4 color = float4(0.1, 0.1, 0.73, .05);
-float4 color = float4(1., 0.5, 0.0, 1.);
+// contorl
+float4 color = float4(0.1, 0.1, 0.73, .05);
+//float4 color = float4(1., 0.5, 0.0, 1.);
int hindex;
@@ -123,7 +126,7 @@ int hindex;
//GE::Time *ts[3];
//================
-//#include "materials_lights.h"
+#include "materials_lights.h"
//----------------------------------------------------------------------
float rand_float(float mn, float mx)
@@ -157,7 +160,7 @@ int main(int argc, char** argv)
glutMotionFunc(appMotion);
glutReshapeFunc(resizeWindow);
- //define_lights_and_materials();
+ define_lights_and_materials();
// initialize necessary OpenGL extensions
glewInit();
@@ -188,7 +191,7 @@ int main(int argc, char** argv)
settings->setRenderType(RTPSettings::SCREEN_SPACE_RENDER);
//settings->setRenderType(RTPSettings::RENDER);
//settings.setRenderType(RTPSettings::SPRITE_RENDER);
- settings->setRadiusScale(0.5);
+ settings->setRadiusScale(0.2);
settings->setBlurScale(1.0);
settings->setUseGLSL(1);
Please sign in to comment.
Something went wrong with that request. Please try again.