~ubuntu-branches/ubuntu/warty/swig1.3/warty

« back to all changes in this revision

Viewing changes to Examples/guile/matrix/vector.c

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Landschoff
  • Date: 2002-03-29 01:56:07 UTC
  • Revision ID: james.westby@ubuntu.com-20020329015607-c0wt03xu8oy9ioj7
Tags: upstream-1.3.11
ImportĀ upstreamĀ versionĀ 1.3.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* File : vector.c */
 
2
 
 
3
#include <stdlib.h>
 
4
#include <stdio.h>
 
5
#include "vector.h"
 
6
 
 
7
Vector *createv(double x, double y, double z, double w) {
 
8
 
 
9
  Vector *n;
 
10
  n = (Vector *) malloc(sizeof(Vector));
 
11
  n->x = x;
 
12
  n->y = y;
 
13
  n->z = z;
 
14
  n->w = w;
 
15
  return n;
 
16
 
 
17
}
 
18
 
 
19
/* Destroy vector */
 
20
 
 
21
void destroyv(Vector *v) {
 
22
  free(v);
 
23
}
 
24
 
 
25
/* Print a vector */
 
26
 
 
27
void printv(Vector *v) {
 
28
 
 
29
  printf("x = %g, y = %g, z = %g, w = %g\n", v->x, v->y, v->z, v->w);
 
30
 
 
31
}
 
32
 
 
33
/* Do a transformation */
 
34
void transform(double **m, Vector *v, Vector *r) {
 
35
 
 
36
  r->x = m[0][0]*v->x + m[0][1]*v->y + m[0][2]*v->z + m[0][3]*v->w;
 
37
  r->y = m[1][0]*v->x + m[1][1]*v->y + m[1][2]*v->z + m[1][3]*v->w;
 
38
  r->z = m[2][0]*v->x + m[2][1]*v->y + m[2][2]*v->z + m[2][3]*v->w;
 
39
  r->w = m[3][0]*v->x + m[3][1]*v->y + m[3][2]*v->z + m[3][3]*v->w;
 
40
 
 
41
}
 
42
 
 
43
 
 
44