Skip to content

Instantly share code, notes, and snippets.

View chunkyguy's full-sized avatar

Sidharth Juyal chunkyguy

View GitHub Profile
#include <stdio.h>
#include <string.h>
char *map =
"xxxxxx000xxxxxx"
"xxxxxx0r0xxxxxx"
"xxxxxx0r0xxxxxx"
"xxxxxx0r0xxxxxx"
"xxxxxx0r0xxxxxx"
"xxxxxx0r0xxxxxx"
@chunkyguy
chunkyguy / line_seg_intersect.c
Created October 11, 2013 18:54
Assume two line segments [p, p+r] and [q, q+s], and test if they intersect.
#define CROSS_Z(a, b) ((a.x*b.y) - (a.y*b.x))
bool LinesIntersect(GLKVector2 p, GLKVector2 p_plus_r, GLKVector2 q, GLKVector2 q_plus_s) {
/* Calculate q - p */
GLKVector2 q_p = {
q.x - p.x,
q.y - p.y
};
/* Calculate r */
@chunkyguy
chunkyguy / DebugHelper.hpp
Created October 3, 2013 08:38
C++11 variadic template to implement the logging system.
//
// DebugHelper.h
// HideousGameEngine
//
// Created by Sid on 06/06/13.
// Copyright (c) 2013 whackylabs. All rights reserved.
//
#ifndef __HideousGameEngine__DebugHelper__
#define __HideousGameEngine__DebugHelper__
@chunkyguy
chunkyguy / gist:6295373
Created August 21, 2013 14:41
Minimum code to set up OpenGL for iOS.
//
// main.m
// OGL_Basic
//
// Created by Sid on 21/08/13.
// Copyright (c) 2013 whackylabs. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
@chunkyguy
chunkyguy / theory.cpp
Created August 14, 2013 21:00
Theory behind C++ I/O.
#include<iostream>
#include<fstream>
using namespace std;
struct test
{
short sss;
char ccc;
int iii;
@chunkyguy
chunkyguy / gist:5986168
Last active July 19, 2018 23:08
std::unique_ptr: Creating unique_ptr to hold array of pointers to something.
// unique_ptr
// Case 1: Array of type
// Case 2: Array of pointer to type
#include <iostream>
#include <memory>
class Bar {
public:
Bar(float b) : bb(b) {
// Thank you std::unique_ptr!
// Compile with
// clang++ unique_ptr.cpp -o unique_ptr -std=c++11 -stdlib=libc++ && ./unique_ptr
/* OUTPUT:
--- START ---
Game
--- MAIN ---
Screen
MainScreen
@chunkyguy
chunkyguy / gist:5908490
Created July 2, 2013 11:15
texture coordinates
<html>
<head>
<title>Texture Coordinates</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript" src="glMatrix-0.9.5.min.js"></script>
<script type="text/javascript" src="webgl-utils.js"></script>
<script id="shader-fs" type="x-shader/x-fragment">
@chunkyguy
chunkyguy / gist:5253727
Created March 27, 2013 12:08
This code demonstrates a way to broadcast messages to many listeners. I'm scrapping this code I worked on for few hours. Why? Because for now I'm going forward with one global event dispatcher. Right now on iDevices it doesn't makes any sense to buffer the events, as the OS already buffers them. Maybe someday I'll return to something similar.
//
// EventLoop.h
// HideousGameEngine
//
// Created by Sid on 27/03/13.
// Copyright (c) 2013 whackylabs. All rights reserved.
//
#ifndef __HideousGameEngine__EventLoop__
#define __HideousGameEngine__EventLoop__
@chunkyguy
chunkyguy / gist:5206358
Created March 20, 2013 17:01
C++ pointer to member function
// Using std::function for callback
#include <iostream>
#include <utility>
class Client;
// Calculator server
class Server{
public:
typedef void (Client::*CB)(int result);