Browse Source

Added quick vertex modification.

angel 7 years ago
parent
commit
3dd7b80af8
6 changed files with 40 additions and 7 deletions
  1. 5 2
      CMakeLists.txt
  2. 10 0
      include/Matrix.h
  3. 2 0
      include/engine.h
  4. 18 1
      src/engine.cpp
  5. 4 4
      src/rasterizer.cpp
  6. 1 0
      src/renderManager.cpp

+ 5 - 2
CMakeLists.txt

@@ -3,15 +3,18 @@ project(softwareRenderer)
 
 
 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/modules")
-#set(SDL2_PATH "C:\\vs_dev_lib\\SDL2-2.0.8")
+set(SDL2_PATH "C:\\vs_dev_lib\\SDL2-2.0.8")
 find_package(SDL2 REQUIRED)
 include_directories(${SDL2_INCLUDE_DIR} include)
 
 file(GLOB source_files "*.h" "*.cpp" "src/*.cpp" "include/*.h")
+
 add_executable(softwareRenderer ${source_files})
+#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
+#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
+#set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg")
 target_link_libraries(softwareRenderer ${SDL2_LIBRARY})
 
-
 if(WIN32)
     add_custom_command(TARGET softwareRenderer POST_BUILD COMMAND
     ${CMAKE_COMMAND} -E copy_if_different

+ 10 - 0
include/Matrix.h

@@ -0,0 +1,10 @@
+#ifndef MATRIX_H
+#define MATRIX_H
+
+#include <math.h>
+
+class Matrix{
+
+};
+
+#endif

+ 2 - 0
include/engine.h

@@ -22,6 +22,8 @@ class Engine{
 
         void loadModels();
 
+        void moveModels();
+
     private:
         WindowManager FEWindowManager;
         RenderManager FERenderManager;

+ 18 - 1
src/engine.cpp

@@ -1,5 +1,6 @@
 #include "engine.h"
 #include <string>
+#include <math.h>
 
 Engine::Engine(){
 
@@ -53,7 +54,7 @@ void Engine::mainLoop(){
         done = FEInputManager.processInput();
 
         //Update entities here in the future
-        //TO DO
+        moveModels();
 
         //Perform all render calculations and update screen
         FERenderManager.render(sceneModels);
@@ -72,4 +73,20 @@ void Engine::loadModels(){
     //sceneModels->describeMesh();
 }
 
+void Engine::moveModels(){
+    float theta  = 0.01;
+    float cosine = std::cos(theta);
+    float sine    = std::sin(theta);
 
+    Mesh * modelMesh = sceneModels->getMesh();
+    int size = modelMesh->numVertices;
+    std::vector<Vector3> * vertices = &modelMesh->vertices;
+
+    for (int i = 0;i < size; ++i){
+        float xOld = (*vertices)[i].x;
+        float zOld = (*vertices)[i].z;
+        (*vertices)[i].x = xOld*cosine + zOld*sine;
+        (*vertices)[i].z = -xOld*sine   + zOld*cosine;
+    }
+
+}

+ 4 - 4
src/rasterizer.cpp

@@ -86,17 +86,17 @@ void Rasterizer::drawLine(Vector3 vertex1, Vector3 vertex2, Uint32 color){
                 y += (y2 > y1  ? 1 : -1);
                 error2 -= dx*2;
             }
-            // if( (x >= 0 ) && (yf >= 0) && (x < mCanvas->mWidth) && (yf < mCanvas->mHeight) ){
-                
-                
-            // }
+
         }
         
 }
 
 void Rasterizer::setPixelColor(Uint32 color, int x, int y){
     int arrayCoordinates = convertCoordinates(x,y);
+    if( ((x >= 0 ) && (y >= 0)) && ((x < mCanvas->mWidth ) && (y < mCanvas->mHeight))  ){   
     mCanvas->mBuffer[arrayCoordinates] = color;
+    }
+    
 }
 
 int Rasterizer::convertCoordinates(int x, int y){

+ 1 - 0
src/renderManager.cpp

@@ -93,5 +93,6 @@ void RenderManager::updateScreen(){
 void RenderManager::clearScreen(){
     SDL_SetRenderDrawColor(mainRenderer, 0x00, 0x00, 0x00, 0xFF);
     SDL_RenderClear(mainRenderer);
+    memset(mainCanvas->mBuffer,0, mainCanvas->mPitch*mainCanvas->mHeight);
 }