Skip to content

Instantly share code, notes, and snippets.

View chunkyguy's full-sized avatar

Sidharth Juyal chunkyguy

View GitHub Profile
/*
sid@whackylabs.com
Tool to test collision detection using Grapher.app
Create formatted data.
Input: cd.in
0.000000 320.000000 194.204971 -60.418026 244.204971 -10.418026
0.000000 320.000000 194.249619 -60.418026 244.249619 -10.418026
0.000000 320.000000 194.294266 -60.418026 244.294266 -10.418026
@chunkyguy
chunkyguy / gist:5082285
Created March 4, 2013 13:37
Line segment intersection test
// Test for two line segments intersection
// sid@whackylabs.com
// Inspired from:
// theory: http://www.bryceboe.com/2006/10/23/line-segment-intersection-algorithm/
// source: http://www.bryceboe.com/wordpress/wp-content/uploads/2006/10/intersect.py
#include <iostream>
template<typename T>
@chunkyguy
chunkyguy / lpf.cpp
Created November 6, 2012 00:07
largest prime factor - unoptimized
#include <iostream>
#include <cmath>
#include <cstring>
bool debug;
bool isFactor(long double n, long double f){
long double i = 1.0;
long double m = f * i;
while(m <= n){
@chunkyguy
chunkyguy / Exception.cpp
Created October 13, 2012 08:16
Exception Handling C vs C++
/*
What: Exception using throw and jmp/longjmp
Author: Sid
Note: Test run with 3 cases
1: x(10), y(2) : Returns 2
2: x(10), y(0) : Catch exception DIVIDE_EXCP, prints error and quit
3: x(10), y(-2) : Catch exception NEG_EXCP, does nothing
*/
#include <iostream>
@chunkyguy
chunkyguy / SJViewController.m
Created September 15, 2012 05:41
This code is leaking !!
//
// SJViewController.m
// TestSkybox
//
// Created by Sidharth Juyal on 22/06/12.
// Copyright (c) 2012 whackylabs. All rights reserved.
//
#import "SJViewController.h"
@chunkyguy
chunkyguy / obfuscated.c
Created August 23, 2012 03:44
height of stupidity
/*
This piece of shit that I wrote does one simple task: linearly interpolate between 0.0 and 1.0 for the value 'res'.
This is a sample run:
$ ./mix 1
0: 0.500000
$ ./mix 2
0: 0.333333
1: 0.666667
$ ./mix 3
0: 0.250000
@chunkyguy
chunkyguy / Electricity.cpp
Created August 22, 2012 12:13
How to generate electricity
/*
Electricity:
resolution_ = 0; means straight line
pointA_, pointB_; are vec4s
*/
void ElectricCurrent::createVertexData(){
int tfloats = (2+resolution_) * 4; //num_points * num_floats_per_point
GLfloat data[tfloats];
int atIndx = 0;
@chunkyguy
chunkyguy / sfml_2.cpp
Created August 21, 2012 14:26
SFML 2.0 boilerplate
int main (int argc, const char * argv[]){
// Create the main window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
// Load a sprite to display
sf::Texture texture;
if (!texture.loadFromFile(resourcePath() + "cute_image.jpg"))
return EXIT_FAILURE;
sf::Sprite sprite(texture);
@chunkyguy
chunkyguy / iOS_OpenGL_template.c
Created August 16, 2012 20:37
Apple OpenGL template for iOS uses two sets of enums
/*
At create setup stage
*/
glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(0));
glEnableVertexAttribArray(GLKVertexAttribNormal);
glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(12));
/*
At binding stage
if(troop_position == 4){
for(int possible_position = 0; possible_position < 9; possible_position++){
if(_slots[possible_position] == -1){
availPos[troop_number][available_position[troop_number]++] = possible_position;
}
}
}else{
for(int possible_position = 0; possible_position < 3; possible_position++){
if(_slots[_nextPossiblePositions[troop_position][possible_position]] == -1){
availPos[troop_number][available_position[troop_number]++] = _nextPossiblePositions[troop_position][possible_position];