Skip to content

Commit

Permalink
Fixed line rendering, added license
Browse files Browse the repository at this point in the history
  • Loading branch information
john-chapman committed Jan 9, 2017
1 parent 42f11e3 commit 47455cc
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 125 deletions.
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2016-2017 John Chapman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
2 changes: 1 addition & 1 deletion im3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,5 +430,5 @@ Context::~Context()
float Context::pixelsToWorldSize(const Vec3& _position, float _pixels)
{
float d = Length(_position - m_appData.m_viewOrigin);
return m_appData.m_tanHalfFov * 2.0f * d * (_pixels / m_appData.m_displaySize.y);
return m_appData.m_tanHalfFov * 2.0f * d * (_pixels / m_appData.m_viewportSize.y);
}
2 changes: 1 addition & 1 deletion im3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ struct AppData
Vec3 m_cursorRayOrigin; // World space cursor ray origin.
Vec3 m_cursorRayDirection; // World space cursor ray direction.
Vec3 m_viewOrigin; // World space render origin (camera position).
Vec2 m_displaySize; // Viewport size (pixels).
Vec2 m_viewportSize; // Viewport size (pixels).
float m_tanHalfFov; // tan(fov/2); fov = vertical field of view of the current projection.
float m_deltaTime; // Time since previous frame (seconds).
void* m_userData; // App-specific data (useful for passing app context to drawPrimitives).
Expand Down
28 changes: 8 additions & 20 deletions tests/Windows/OpenGL/TestApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ static void Im3d_Draw(Im3d::DrawPrimitiveType _primType, const Im3d::VertexData*

glAssert(glUseProgram(sh));
glAssert(glUniformMatrix4fv(glGetUniformLocation(sh, "uViewProjMatrix"), 1, false, (const GLfloat*)s_testApp->m_camViewProj));
glAssert(glUniform2f(glGetUniformLocation(sh, "uViewport"), (float)s_testApp->getWidth(), (float)s_testApp->getHeight()));
glAssert(glDrawArrays(prim, 0, (GLsizei)_count));

glAssert(glDisable(GL_PROGRAM_POINT_SIZE));
Expand Down Expand Up @@ -646,7 +647,7 @@ bool TestApp::init(int _width, int _height, const char* _title)

shutdown();

// force the current working directoy to the exe location
// force the current working directory to the exe location
TCHAR buf[MAX_PATH] = {};
DWORD buflen;
IM3D_PLATFORM_VERIFY(buflen = GetModuleFileName(0, buf, MAX_PATH));
Expand Down Expand Up @@ -716,13 +717,13 @@ bool TestApp::update()
m_camPos = m_camPos - m_camWorld.getCol(2) * (m_deltaTime * kCamSpeed);
}
if (GetAsyncKeyState(0x41) & 0x8000) { // A (left)
m_camPos = m_camPos + m_camWorld.getCol(0) * (m_deltaTime * kCamSpeed);
m_camPos = m_camPos - m_camWorld.getCol(0) * (m_deltaTime * kCamSpeed);
}
if (GetAsyncKeyState(0x53) & 0x8000) { // S (backward)
m_camPos = m_camPos + m_camWorld.getCol(2) * (m_deltaTime * kCamSpeed);
}
if (GetAsyncKeyState(0x44) & 0x8000) { // D (right)
m_camPos = m_camPos - m_camWorld.getCol(0) * (m_deltaTime * kCamSpeed);
m_camPos = m_camPos + m_camWorld.getCol(0) * (m_deltaTime * kCamSpeed);
}
if (GetAsyncKeyState(0x51) & 0x8000) { // Q (down)
m_camPos = m_camPos - m_camWorld.getCol(1)* (m_deltaTime * kCamSpeed);
Expand All @@ -732,10 +733,10 @@ bool TestApp::update()
}

if (GetAsyncKeyState(VK_ADD) & 0x8000) { // + (rotate right)
m_camDir = Rotate(Mat4(1.0f), Vec3(0.0f, 1.0f, 0.0f), m_deltaTime) * m_camDir;
m_camDir = Rotate(Mat4(1.0f), Vec3(0.0f, 1.0f, 0.0f), -m_deltaTime) * m_camDir;
}
if (GetAsyncKeyState(VK_SUBTRACT) & 0x8000) { // - (rotate left)
m_camDir = Rotate(Mat4(1.0f), Vec3(0.0f, 1.0f, 0.0f), -m_deltaTime) * m_camDir;
m_camDir = Rotate(Mat4(1.0f), Vec3(0.0f, 1.0f, 0.0f), m_deltaTime) * m_camDir;
}


Expand All @@ -756,11 +757,11 @@ bool TestApp::update()
0.0f, 0.0f, -1.0f, 0.0f
);
m_camWorld = LookAt(m_camPos, m_camPos - m_camDir);
m_camView = InvertOrtho(m_camWorld);
m_camView = Inverse(m_camWorld);
m_camViewProj = m_camProj * m_camView;
AppData& ad = GetAppData();
ad.m_deltaTime = m_deltaTime;
ad.m_displaySize = Vec2((float)m_width, (float)m_height);
ad.m_viewportSize = Vec2((float)m_width, (float)m_height);
ad.m_viewOrigin = m_camPos;
ad.m_tanHalfFov = tanf(fovRads * 0.5f);
Im3d::NewFrame();
Expand All @@ -783,19 +784,6 @@ bool TestApp::update()
ImGui::Text("Delta t: %.2f", m_deltaTime);
ImGui::Text("Cam pos: %.2f,%.2f,%.2f", m_camPos.x, m_camPos.y, m_camPos.z);
ImGui::Text("Cam dir: %.2f,%.2f,%.2f", m_camDir.x, m_camDir.y, m_camDir.z);
const Mat4& vm = m_camView;
ImGui::Text("View:\n"
"%+.2f, %+.2f, %+.2f, %+.2f\n"
"%+.2f, %+.2f, %+.2f, %+.2f\n"
"%+.2f, %+.2f, %+.2f, %+.2f\n"
"%+.2f, %+.2f, %+.2f, %+.2f",
vm[ 0], vm[ 4], vm[ 8], vm[12],
vm[ 1], vm[ 5], vm[ 9], vm[13],
vm[ 2], vm[ 6], vm[10], vm[14],
vm[ 3], vm[ 7], vm[11], vm[15]
);



return msg.message != WM_QUIT;
}
Expand Down
103 changes: 0 additions & 103 deletions tests/bin/im3d.glsl

This file was deleted.

9 changes: 9 additions & 0 deletions tests/im3d_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ int main(int, char**)
Im3d::Vertex( 0.0f, 1.0f, -5.0f, Color_Red);
Im3d::Vertex( 1.0f, -1.0f, -5.0f, Color_Blue);
Im3d::End();

Im3d::SetSize(12.0f);
Im3d::SetColor(Color_Magenta);
Im3d::BeginLineLoop();
Im3d::Vertex(-1.0f, -1.0f, -5.0f);
Im3d::Vertex( 0.0f, 1.0f, -5.0f);
Im3d::Vertex( 1.0f, -1.0f, -5.0f);
Im3d::End();

Im3d::PopDrawState();

app.draw();
Expand Down

0 comments on commit 47455cc

Please sign in to comment.