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

View module revisions #6

Merged
merged 4 commits into from
Sep 15, 2014
Merged
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
24 changes: 19 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ clean-osx:

clean: clean-android clean-ios clean-osx

CORE_SRC_FILES= \
core/tangram.cpp \
core/util/*.cpp \
core/viewModule/*.cpp

OSX_FRAMEWORKS= \
-framework Cocoa \
-framework OpenGL \
-framework IOKit \
-framework CoreVideo
OSX_INCLUDES= \
-Icore \
-Icore/include
OSX_SRC_FILES= \
osx/src/main.cpp \
osx/src/platform_osx.cpp

android/libs/armeabi/libtangram.so: android/jni/jniExports.cpp android/jni/platform_android.cpp core/tangram.cpp core/tangram.h android/jni/Android.mk android/jni/Application.mk
ndk-build -C android/jni

Expand All @@ -33,10 +50,7 @@ android: android/bin/TangramAndroid-Debug.apk
ios:
xcodebuild -workspace ios/TangramiOS.xcworkspace -scheme TangramiOS -destination 'platform=iOS Simulator,name=iPhone Retina (3.5-inch)'

osx/lib/libtangram.so: core/tangram.cpp core/tangram.h
clang++ -o osx/lib/libtangram.so core/tangram.cpp core/util/shaderProgram.cpp core/util/error.cpp osx/src/platform_osx.cpp -Icore -DPLATFORM_OSX -lglfw3 -framework OpenGL -std=c++11 -shared

osx/bin/TangramOSX: osx/lib/libtangram.so
clang++ -o osx/bin/TangramOSX osx/src/main.cpp osx/lib/libtangram.so -Icore -DPLATFORM_OSX -lglfw3 -framework Cocoa -framework IOKit -framework OpenGL -framework CoreVideo -std=c++11 -g
osx/bin/TangramOSX: $(OSX_SRC_FILES)
clang++ -o osx/bin/TangramOSX $(CORE_SRC_FILES) $(OSX_SRC_FILES) $(OSX_INCLUDES) $(OSX_FRAMEWORKS) -DPLATFORM_OSX -lglfw3 -std=c++11 -g

osx: osx/bin/TangramOSX
4 changes: 4 additions & 0 deletions core/tangram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const GLfloat vertices[] = {

ShaderProgram simpleShader;
GLuint vbo;
ViewModule view;
float t;

const std::string vertShaderSrc =
Expand Down Expand Up @@ -43,12 +44,15 @@ void initializeOpenGL()
t = 0;

logMsg("%s\n", "initialize");

}

void resizeViewport(int newWidth, int newHeight)
{
glViewport(0, 0, newWidth, newHeight);

view.setAspect(newWidth, newHeight);

logMsg("%s\n", "resizeViewport");
}

Expand Down
1 change: 1 addition & 0 deletions core/tangram.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "platform.h"
#include "util/shaderProgram.h"
#include "viewModule/viewModule.h"

void initializeOpenGL();
void resizeViewport(int newWidth, int newHeight);
Expand Down
25 changes: 15 additions & 10 deletions core/viewModule/viewModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ void ViewModule::setAspect(float _width, float _height) {

m_aspect = _width / _height;
setZoom(m_zoom);
m_dirty = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for line #13 (can not comment there).. there is no need to set m_dirty to true there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, it's just there for clarity.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coolness :D.


}

void ViewModule::setPosition(float _x, float _y) {

translate(_x - m_pos.x, _y - m_pos.y);
m_dirty = true;

}

Expand All @@ -42,23 +44,25 @@ void ViewModule::translate(float _dx, float _dy) {
glm::translate(m_view, glm::vec3(_dx, _dy, 0.0));
m_pos.x += _dx;
m_pos.y += _dy;
m_dirty = true;

}

void ViewModule::setZoom(int _z) {

m_zoom = _z;
float tileSize = 2 * PI * EARTH_RADIUS_M / pow(2, m_zoom);
float tileSize = 2 * PI * EARTH_RADIUS_M * pow(2, -m_zoom);
m_height = 3 * tileSize; // Set viewport size to ~3 tiles vertically
m_width = m_height * m_aspect; // Size viewport width to match aspect ratio
m_proj = glm::ortho(-m_width/2.0, m_width/2.0, -m_height/2.0, m_height/2.0);
m_proj = glm::ortho(-m_width * 0.5, m_width * 0.5, -m_height * 0.5, m_height * 0.5);
m_dirty = true;

}

glm::mat2 ViewModule::getBoundsRect() {

float hw = m_width/2.0;
float hh = m_height/2.0;
float hw = m_width * 0.5;
float hh = m_height * 0.5;
return glm::mat2(m_pos.x - hw, m_pos.y - hh, m_pos.x + hw, m_pos.y + hh);

}
Expand All @@ -71,15 +75,16 @@ const std::vector<glm::ivec3>& ViewModule::getVisibleTiles() {

m_visibleTiles.clear();

float tileSize = 2 * PI * EARTH_RADIUS_M / pow(2, m_zoom);
float tileSize = 2 * PI * EARTH_RADIUS_M * pow(2, -m_zoom);
float invTileSize = 1.0 / tileSize;

float vpLeftEdge = m_pos.x - m_width/2;
float vpLeftEdge = m_pos.x - m_width * 0.5;
float vpRightEdge = vpLeftEdge + m_width;
float vpBottomEdge = m_pos.y - m_height/2;
float vpBottomEdge = m_pos.y - m_height * 0.5;
float vpTopEdge = vpBottomEdge + m_height;

int tileX = (int) vpLeftEdge / tileSize;
int tileY = (int) vpBottomEdge / tileSize;
int tileX = (int) vpLeftEdge * invTileSize;
int tileY = (int) vpBottomEdge * invTileSize;

float x = tileX * tileSize;
float y = tileY * tileSize;
Expand All @@ -94,7 +99,7 @@ const std::vector<glm::ivec3>& ViewModule::getVisibleTiles() {

}

tileY = (int) vpBottomEdge / tileSize;
tileY = (int) vpBottomEdge * invTileSize;
y = tileY * tileSize;

tileX++;
Expand Down
7 changes: 7 additions & 0 deletions osx/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

#include "../../core/tangram.h"

void window_size_callback(GLFWwindow* window, int width, int height)
{
resizeViewport(width, height);
}

int main(void)
{
GLFWwindow* window;
Expand All @@ -26,6 +31,8 @@ int main(void)
initializeOpenGL();
resizeViewport(width, height);

glfwSetWindowSizeCallback(window, window_size_callback);

/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
Expand Down