Commit 712826ad authored by guillaume's avatar guillaume

control camera

parent d9a22835
......@@ -15,10 +15,10 @@ find_package(raylib 3.0 REQUIRED)
#set(raylib_VERBOSE 1)
add_executable(nw-hello src/main-hello.c)
target_link_libraries(nw-hello raylib)
target_link_libraries(nw-hello raylib m)
add_executable(nw-viewer src/main-viewer.c src/networld.c src/controlpanel.c)
target_link_libraries(nw-viewer raylib)
target_link_libraries(nw-viewer raylib m)
#without cmake package...
#include_directories(${PROJECT_SOURCE_DIR}/raylib/src)
......
......@@ -4,6 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// Constructor / Destructor
Panel * Panel_new()
......@@ -52,13 +53,15 @@ void Panel_draw(Panel * self)
void Panel_drawBasis(Panel * self)
{
Vector2 screen00= {0.f, 0.f};
screen00= Panel_pixelFromPosition(self, &( screen00 ) );
Vector2 screen10= {1.f, 0.f};
screen10= Panel_pixelFromPosition(self, &( screen10 ) );
Vector2 screen01= {0.f, 1.f};
screen01= Panel_pixelFromPosition(self, &( screen01 ) );
DrawCircleV( self->screenCenter, 4, BLUE );
DrawLineV( self->screenCenter, screen10, RED );
DrawLineV( self->screenCenter, screen01, BLUE );
DrawCircleV( screen00, 4, BLUE );
DrawLineV( screen00, screen10, RED );
DrawLineV( screen00, screen01, BLUE );
}
void Panel_drawNode(Panel * self, Node * n)
......@@ -82,3 +85,21 @@ Vector2 Panel_positionFromPixel(Panel * self, Vector2 * p)
Vector2 position= { p->x, p->y };
return position;
}
void Panel_control(Panel * self)
{
Panel_controlCamera(self);
}
void Panel_controlCamera(Panel * self)
{
// KEYBOARD Control:
float step= 3.0f / self->scale;
if (IsKeyDown(KEY_RIGHT)) self->camera.x += step;
if (IsKeyDown(KEY_LEFT)) self->camera.x -= step;
if (IsKeyDown(KEY_UP)) self->camera.y += step;
if (IsKeyDown(KEY_DOWN)) self->camera.y -= step;
self->scale += (GetMouseWheelMove()*1.f);
self->scale = fmaxf( self->scale, 0.001f );
}
\ No newline at end of file
......@@ -28,4 +28,8 @@ void Panel_drawNode(Panel * self, Node * n);
Vector2 Panel_pixelFromPosition(Panel * self, Vector2 * p);
Vector2 Panel_positionFromPixel(Panel * self, Vector2 * p);
// Control
void Panel_control(Panel * self);
void Panel_controlCamera(Panel * self);
#endif //CONTROLPANEL_H
\ No newline at end of file
......@@ -56,6 +56,7 @@ int main(int nbArg, char ** arg)
// Main game loop
while (!game_end && !WindowShouldClose()) // Detect window close button or ESC key
{
Panel_control(panel);
game_update(world);
Panel_draw(panel);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment