Pages

Wednesday, December 06, 2006

The small grey children, who stand by your bed and watch you while you're sleeping.

Sometimes we need pointers to pointers. Today was one of those days, it's used to pass back information. If you want to pass back info and just pass in a normal pointer, then a copy is made and the pointer outside of the function is never changed.

This is my *arghh* how does it work code.


#include "stdafx.h"
#include

using namespace std;

int b = 3;

void func(int ** i){
*i = &b;
}

int _tmain(int argc, _TCHAR* argv[])
{
int * p;
func(&p);
std::cout << (*p) << std::endl;
char a;
cin >> a;
return 0;
}


My second sweet snippet is cheap cheap openGL matrices.

This takes in an openGL matrix array, like you'd get from glLoadMatrix, then applies to a vector or vertex.


void TransformVector(float * m, Vector3d &v, Vector3d &d)
{
d.x = (m[0] * v.x) + (m[4] * v.y) + (m[8] * v.z) + m[12];
d.y = (m[1] * v.x) + (m[5] * v.y) + (m[9] * v.z) + m[13];
d.z = (m[2] * v.x) + (m[6] * v.y) + (m[10] * v.z) + m[14];
}

3 comments:

  1. i would like you write about alpha blending c# managed with sprites =]

    ReplyDelete
  2. There's some basic blending stuff under 2:2 movement. But at the moment I'm not going to be writing anything more - sorry!

    I have some time free after Christmas so I might expand / rewrite parts of the tutorials then.

    ReplyDelete
  3. okay thanks, uh nice page very usefull!

    ReplyDelete

All comments are moderated unless the post is very recent.
It may take a little time for your comment to be pushed to the blog.
Anything spammy is deleted.