Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
227 changes: 43 additions & 184 deletions README.md

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions objs/dragon.mtl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
newmtl initialShadingGroup
illum 4
Kd 0.50 0.50 0.50
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
6 changes: 6 additions & 0 deletions objs/test.mtl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
newmtl initialShadingGroup
illum 4
Kd 0.50 0.50 0.50
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
2 changes: 1 addition & 1 deletion objs/tri.obj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
v 0 0 0
v 0.1 0 0
v 0 0.1 0
v 0 -0.1 0

vn 0 0 1

Expand Down
66 changes: 65 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
//-------------MAIN--------------
//-------------------------------

camera cam;
int mouse_old_x, mouse_old_y;
int pressed = -1;
float t = 0;

int main(int argc, char** argv){

bool loadedScene = false;
Expand All @@ -29,6 +34,14 @@ int main(int argc, char** argv){
return 0;
}

cam.aspectRatio = (float)width/(float)height;
cam.fovy = 60;
cam.zNear = 0.1;
cam.zFar = 1000;
cam.eye = glm::vec3(0,0.5,1);
cam.center = glm::vec3(0,0.5,0);
cam.up = glm::vec3(0,1,0);

frame = 0;
seconds = time (NULL);
fpstracker = 0;
Expand Down Expand Up @@ -93,13 +106,17 @@ void runCuda(){
ibo = mesh->getIBO();
ibosize = mesh->getIBOsize();

nbo = mesh->getNBO();
nbosize = mesh->getNBOsize();

cudaGLMapBufferObject((void**)&dptr, pbo);
cudaRasterizeCore(dptr, glm::vec2(width, height), frame, vbo, vbosize, cbo, cbosize, ibo, ibosize);
cudaRasterizeCore(dptr, glm::vec2(width, height), frame, vbo, vbosize, cbo, cbosize, ibo, ibosize, nbo, nbosize, cam);
cudaGLUnmapBufferObject(pbo);

vbo = NULL;
cbo = NULL;
ibo = NULL;
nbo = NULL;

frame++;
fpstracker++;
Expand All @@ -126,6 +143,8 @@ bool init(int argc, char* argv[]) {
}
glfwMakeContextCurrent(window);
glfwSetKeyCallback(window, keyCallback);
glfwSetMouseButtonCallback(window, mouseButtonCallback);
glfwSetCursorPosCallback(window, mouseMotionCallback);

// Set up GL context
glewExperimental = GL_TRUE;
Expand Down Expand Up @@ -281,4 +300,49 @@ void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods
if(key == GLFW_KEY_ESCAPE && action == GLFW_PRESS){
glfwSetWindowShouldClose(window, GL_TRUE);
}
else if (key == GLFW_KEY_S){
glm::vec3 dir = cam.center - cam.eye;
cam.eye -= 0.05f*cam.up;
}
else if (key == GLFW_KEY_W){
glm::vec3 dir = cam.center - cam.eye;
cam.eye += 0.05f*cam.up;
}

std::cout<<cam.eye.x<<", "<<cam.eye.y<<", "<<cam.eye.z<<std::endl;
}

void mouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
{// left: 0. right: 1. middle: 2.
if(action == GLFW_PRESS)
{
pressed = button;
}
else if(action == GLFW_RELEASE)
{
pressed = -1;
}
}

void mouseMotionCallback(GLFWwindow* window, double x, double y)
{
if (pressed == 0){
glm::vec3 circlePoint;
if (x<mouse_old_x) t-=0.1f;
else t += 0.1f;
circlePoint.x = cos(t);
circlePoint.z = sin(t);
cam.eye.x = circlePoint.x;
cam.eye.z = circlePoint.z;
}
else if (pressed == 1){
glm::vec3 dir = cam.center - cam.eye;
if (y>mouse_old_y) cam.eye += 0.1f*cam.up;
else cam.eye -= 0.1f*cam.up;
}
else if (pressed = 2){
}

mouse_old_x = x;
mouse_old_y = y;
}
4 changes: 4 additions & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ float* cbo;
int cbosize;
int* ibo;
int ibosize;
float* nbo;
int nbosize;

//-------------------------------
//----------CUDA STUFF-----------
Expand Down Expand Up @@ -99,5 +101,7 @@ void deleteTexture(GLuint* tex);
void mainLoop();
void errorCallback(int error, const char *description);
void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods);
void mouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
void mouseMotionCallback(GLFWwindow* window, double x, double y);

#endif
Loading