Skip to content

Instantly share code, notes, and snippets.

View nadult's full-sized avatar
😎

Krzysztof Jakubowski nadult

😎
View GitHub Profile
@nadult
nadult / cuda_simulation.cu
Created November 3, 2013 11:33
Molecular dynamics on GPU
#include <stdio.h>
#include <assert.h>
#include "config.h"
#include <thrust/sort.h>
#include <thrust/tuple.h>
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/iterator/zip_iterator.h>
#define GL_GLEXT_PROTOTYPES 1
@nadult
nadult / parser.hs
Created November 3, 2013 11:38
C-like language parser in Haskell.
module Parser(parseProgram) where
import Text.Parsec.Expr
import Text.ParserCombinators.Parsec
import Text.ParserCombinators.Parsec.Error
import qualified Text.ParserCombinators.Parsec.Token as P
import Text.ParserCombinators.Parsec.Language
import Control.Monad
import Tokens
@nadult
nadult / point_sampler_dxt.cpp
Last active February 9, 2020 09:37
Point sampler class for textures in DXT1 format. It was used in my realtime ray-tracer project. It's using SSE through custom SIMD vector classes.
#include "sampling/point_sampler_dxt.h"
namespace sampling {
PointSamplerDXT::PointSamplerDXT(const gfxlib::Texture &t) :tex(t) {
if(tex.Width() & (tex.Width() - 1) || tex.Height() & (tex.Height() - 1))
THROW("Texture width & height must be a power of 2");
if(tex.GetFormat().GetIdent()!=gfxlib::TI_DXT1)
THROW("DXT sampler requires DXT1 texture");
@nadult
nadult / !texture_cache.hpp
Last active March 2, 2020 18:58
Class responsible for caching multiple small textures into few big ones. It allows to reduce number of glBindTexture calls and greatly improving performance on some cheaper hardware (integrated GPUs).
/* Copyright (C) 2013 Krzysztof Jakubowski <nadult@fastmail.fm>
This file is part of FreeFT.
FreeFT is free software; you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
FreeFT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@nadult
nadult / navi_map.cpp
Created November 3, 2013 11:57
3D navigational heightmap from FreeFT. It allows to quickly find shortest (in most cases) paths between both static & dynamic objects. A* algorithm is utilized.
/* Copyright (C) 2013 Krzysztof Jakubowski <nadult@fastmail.fm>
This file is part of FreeFT.
FreeFT is free software; you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
FreeFT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@nadult
nadult / sse_f32x4.hpp
Created November 3, 2013 11:59
SSE float wrapper class. Written in 2009.
#ifndef VECLIB_SSE_F32_H
#define VECLIB_SSE_F32_H
#include "sse/base.h"
class f32x4b;
class f32x4bn;
class f32x4
class MTRand {
public:
typedef unsigned int u32;
MTRand(u32 s=5489) :p(0) {
for(int i=0;i<n;i++) state[i]=0;
seed(s);
}
void seed(u32 s) {
state[0] = s & 0xFFFFFFFFUL;
@nadult
nadult / hex_voxelizer.cpp
Last active February 9, 2020 09:38
Voxelizer based on hexagonal grid using rational arithmetic.
// This code turns 3D mesh into hexagonal-based voxel grid
// Most features should be preserved (algorithm is similar to Dual Contouring)
// Computations are performed on rational arithmetic to make it 100% robust
#include "vis/voxel_map.h"
#include "fwk_profile.h"
#include "geom/plane_graph.h"
#include "geom/plane_graph_builder.h"
#include "geom/visualizer.h"
@nadult
nadult / constrained_delaunay_triangulation.cpp
Last active March 28, 2019 18:48
Constrained delaunay triangulation
#include "geom/delaunay.h"
#include "geom/segment_grid.h"
#include "geom/voronoi.h"
#include "small_vector.h"
#include <fwk/math/direction.h>
#include <numeric>
#include "instantiator.h"
#include "investigate.h"
@nadult
nadult / !csg.h
Last active February 9, 2020 10:37
CSG based on exact integer arithmetic
#pragma once
#include "gen_base.h"
#include "geom/immutable_graph.h"
#include "geom_base.h"
namespace geom {
// TODO: flagi (neutral jest niezależne od intersection & subtraction, addition niepotrzebne)
DEFINE_ENUM(CSGEdgeType, addition, intersection, subtraction, neutral);