Skip to content

Instantly share code, notes, and snippets.

View gszauer's full-sized avatar
💻
Living life 16.6 ms at a time

Gabor Szauer gszauer

💻
Living life 16.6 ms at a time
View GitHub Profile
using UnityEngine;
using System.Collections;
public class TangentDemo : MonoBehaviour {
////////////////////////////////////////////////////////////////////////////////////////////
// In order to ortho-normalize a vector set,
// subtract up the projection of tangent onto the normal and / or binormal from the tangent
////////////////////////////////////////////////////////////////////////////////////////////
void Start () {
#define WIN32_LEAN_AND_MEAN
#define WIN32_EXTRA_LEAN
#include <windows.h>
HWND g_hWnd;
HINSTANCE g_hInstance;
static const int g_nWindowWidth = 600;
static const int g_nWindowHeight = 400;
// Used to double buffer the window
#define WIN32_LEAN_AND_MEAN
#define WIN32_EXTRA_LEAN
#include <windows.h>
HWND hwnd;
HINSTANCE hinstance;
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) {
// Building a 3d game engine in c++ by brian hook
// Constructor
void Triangle(vertex a, vertex b, vertex c, color) {
// Local cache variables
int x1 = a.x;
int x2 = b.x;
int x3 = c.x;
int y1 = a.y;
#define WIN32_LEAN_AND_MEAN
#define WIN32_EXTRA_LEAN
#include <windows.h>
#include <stdio.h>
#include "rasterizer.h"
extern HDC hdcMemory;
extern int g_nWindowWidth;
extern int g_nWindowHeight;
/* $Author: cs442 $ $Revision: 1.1 $ $Date: 2001/11/19 20:08:09 $ */
/*
* File: bmp.c
* Purpose: Provide MS Windows BMP file I/O. Initially designed to only
* read 24-bit BMp files.
* Author: Wayne O. Cochran (cochran@vancouver.wsu.edu) with
* code heavily lifted from the appendix of
* Computer Graphics Using Open GL, Second Edition
* by F.S. Hill, Jr
Everything you ever wanted to know about alpha blending and more.
When doing alpha channels, few algorithms put in the extra effort for maximum flexibility. This is because there is always a battle between speed, memory and complexity. As we shall see, there are many different ways of doing alpha blending.
By far, the most common form of alpha channel is where you have a semi-transparent image that you want to apply over a static background. The semi-transparent image will contain red, green and blue channels as well as an alpha channel that specifies how transparent each pixel is. Each channel contains a series of values that range from 0 to 255 for 32bit images.
What this means is that an alpha channel of 255 would mean full intensity and an alpha value of 0 would mean that the background would show completely through. Any other value would be some percentage of the image and the inverse percentage of the background. For example, if an alpha channel is at 30%, then you'll see 70% of the background showi
The simplest method of projecting a 3D point onto a 3D screen assumes that we are in the camera coordinate system; that is all points are specified in relation to the viewer, who is assumed to be at (0, 0, 0). Assuming that the coordinates of the center of the display are at (0, 0), +X is right and +y is up:
screen_x = vector.x / vector.z;
screen_y = vector.y / vector.z;
In the vga (0, 0) is top left and +Y is going down; Lets account for the skewed center and inverted y:
screen_x = vector.x / vector.z + HALF_SCREEN_WIDTH;
screen_y = -1.0 * vector.y / vector.z + HALF_SCREEN_HEIGHT;
While correct, the above code will greatly exaggerate the effects of of perspective. To somewhat offset this a fixed multiplier should be applied:
screen_x = vector.x * perspective_compensate / vector.z + HALF_SCREEN_WIDTH
#define WIN32_LEAN_AND_MEAN
#define WIN32_EXTRA_LEAN
#include <windows.h>
#include <cmath>
#include <gl/gl.h>
// #pragma comment(lib, "opengl32.lib")
// #pragma comment( linker, "/subsystem:windows" )
#define WINDOW_WIDTH 800
From: http://www.koonsolo.com/news/dewitters-gameloop/
deWiTTERS Game Loop
July 13th, 2009Koen WittersLeave a commentGo to comments
The game loop is the heartbeat of every game, no game can run without it. But unfortunately for every new game programmer, there aren’t any good articles on the internet who provide the proper information on this topic. But fear not, because you have just stumbled upon the one and only article that gives the game loop the attention it deserves. Thanks to my job as a game programmer, I come into contact with a lot of code for small mobile games. And it always amazes me how many game loop implementations are out there. You might wonder yourself how a simple thing like that can be written in different ways. Well, it can, and I will discuss the pros and cons of the most popular implementations, and give you the (in my opinion) best solution of implementing a game loop. (Thanks to Kao Cardoso Félix this article is also available in Brazilian Portuguese)
The Game Loop
Every game cons