Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project4 done--Xinjie #7

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
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
183 changes: 50 additions & 133 deletions README.md

Large diffs are not rendered by default.

150,000 changes: 150,000 additions & 0 deletions objs/dragon.obj.bak

Large diffs are not rendered by default.

113,159 changes: 113,159 additions & 0 deletions objs/mouse.obj.bak

Large diffs are not rendered by default.

Binary file added performance.docx
Binary file not shown.
Binary file added screenshots/anti.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/anti_no.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/color interpolation.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/demo3.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/diffuss-light.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/firstTriangle.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/light.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/normal.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/paintfill.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/performance.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/rasterizationDemo.mp4
Binary file not shown.
Binary file added screenshots/spec.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
97 changes: 91 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//-------------------------------
//-------------MAIN--------------
//-------------------------------

using namespace std;
int main(int argc, char** argv){

bool loadedScene = false;
Expand Down Expand Up @@ -37,6 +37,7 @@ int main(int argc, char** argv){
if (init(argc, argv)) {
// GLFW main loop
mainLoop();

}

return 0;
Expand All @@ -46,7 +47,7 @@ void mainLoop() {
while(!glfwWindowShouldClose(window)){
glfwPollEvents();
runCuda();

time_t seconds2 = time (NULL);

if(seconds2-seconds >= 1){
Expand Down Expand Up @@ -80,21 +81,23 @@ void runCuda(){
// Map OpenGL buffer object for writing from CUDA on a single GPU
// No data is moved (Win & Linux). When mapped to CUDA, OpenGL should not use this buffer
dptr=NULL;

glm::mat4 rotation = glm::rotate(glm::mat4(1.0f), 20.0f-0.5f*frame, glm::vec3(0.0f, 1.0f, 0.0f));
//rotation = glm::mat4(1.0f);
vbo = mesh->getVBO();
vbosize = mesh->getVBOsize();

float newcbo[] = {0.0, 1.0, 0.0,
float newcbo[] = {0.8, 0.8, 0.8,
0.0, 0.0, 1.0,
1.0, 0.0, 0.0};
cbo = newcbo;
cbosize = 9;

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), rotation, frame, vbo, vbosize, cbo, cbosize, ibo, ibosize, nbo, nbosize,eye, center);
cudaGLUnmapBufferObject(pbo);

vbo = NULL;
Expand All @@ -104,6 +107,85 @@ void runCuda(){
frame++;
fpstracker++;

}
//--------------------------------
//--------interactive camera------
//--------------------------------


void MouseClickCallback(GLFWwindow *window, int button, int action, int mods)
{
if(action == GLFW_PRESS && button == GLFW_MOUSE_BUTTON_1)
{
glfwGetCursorPos(window,&prevX,&prevY);
isLeftButton = true;
}

if(action == GLFW_PRESS && button == GLFW_MOUSE_BUTTON_2)
{
glfwGetCursorPos(window,&prevX,&prevY);
isRightButton = true;
}

if(action == GLFW_PRESS && button == GLFW_MOUSE_BUTTON_3)
{
glfwGetCursorPos(window,&prevX,&prevY);
isMidButton = true;
}

if(action == GLFW_RELEASE && button == GLFW_MOUSE_BUTTON_1)
isLeftButton = false;

if(action == GLFW_RELEASE && button == GLFW_MOUSE_BUTTON_2)
isRightButton = false;

if(action == GLFW_RELEASE && button == GLFW_MOUSE_BUTTON_3)
isMidButton = false;
}

void CursorEnterCallback(GLFWwindow *window,int entered)
{
if(entered == GL_TRUE)
isInside = true;
else
isInside = false;
}
void CursorCallback(GLFWwindow *window, double x,double y) {
x = max(0.0, x);
x = min(x, (double)width);
y = max(0.0, y);
y = min(y, (double)height);
int offsetX = x - prevX;
int offsetY = y - prevY;
prevX = x;
prevY = y;

glm::vec4 teye;
glm::mat4 rotation;
glm::vec3 axis;
glm::vec3 step;

if(isLeftButton && isInside){
teye = glm::vec4(eye - center, 1);
axis = glm::normalize(glm::cross(glm::vec3(0,1,0), eye-center));
rotation = glm::rotate(rotation, (float)(-360.0f/width*offsetX), glm::vec3(0.0f, 1.0f, 0.0f)) * glm::rotate(rotation,(float)(-360.0f/width*offsetY), glm::vec3(axis.x, axis.y, axis.z));
teye = rotation * teye;
eye = glm::vec3(teye);
eye = eye + center;
}
else if(isMidButton && isInside){ //need revise
eye += glm::vec3(-0.002, 0, 0) * (float)offsetX;
eye += glm::vec3(0, 0.002, 0) * (float)offsetY;
center += glm::vec3(-0.002, 0, 0) * (float)offsetX;
center += glm::vec3(0, 0.002, 0) * (float)offsetY;
}
else if(isRightButton && isInside){ //need revise
if (glm::distance(center, eye) > 0.01 || (offsetX < 0 && glm::distance(center, eye) < 20)) {
step = 0.01f * glm::normalize(center - eye);
eye += step * (float)offsetX;
}
}

}

//-------------------------------
Expand All @@ -126,6 +208,9 @@ bool init(int argc, char* argv[]) {
}
glfwMakeContextCurrent(window);
glfwSetKeyCallback(window, keyCallback);
glfwSetMouseButtonCallback(window,MouseClickCallback);
glfwSetCursorEnterCallback(window,CursorEnterCallback);
glfwSetCursorPosCallback(window,CursorCallback);

// Set up GL context
glewExperimental = GL_TRUE;
Expand Down
16 changes: 12 additions & 4 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <GL/glew.h>
#include <GLFW/glfw3.h>

#include <GL/glut.h>
#include <cuda_runtime.h>
#include <cuda_gl_interop.h>
#include <fstream>
Expand Down Expand Up @@ -47,6 +47,8 @@ float* vbo;
int vbosize;
float* cbo;
int cbosize;
float* nbo;
int nbosize;
int* ibo;
int ibosize;

Expand All @@ -55,7 +57,8 @@ int ibosize;
//-------------------------------

int width = 800; int height = 800;

glm::vec3 eye(0, 0.25, 2);
glm::vec3 center(0, 0.25, 0);
//-------------------------------
//-------------MAIN--------------
//-------------------------------
Expand All @@ -71,8 +74,13 @@ void runCuda();
#ifdef __APPLE__
void display();
#else
void display();

void keyboard(unsigned char key, int x, int y);
void mousePress(int button, int state, int x, int y);
void mouseMove(int x, int y);
int buttonPressed;
double prevX, prevY;
bool isLeftButton = false, isMidButton = false, isRightButton = false, isInside = false;
#endif

//-------------------------------
Expand All @@ -92,7 +100,7 @@ GLuint initShader();
void cleanupCuda();
void deletePBO(GLuint* pbo);
void deleteTexture(GLuint* tex);

void shut_down(int return_code);
//------------------------------
//-------GLFW CALLBACKS---------
//------------------------------
Expand Down
Loading