~jtaylor/ubuntu/oneiric/soya/fix-780305

« back to all changes in this revision

Viewing changes to c_src/volume.c

  • Committer: Bazaar Package Importer
  • Author(s): Marc Dequènes (Duck)
  • Date: 2005-01-30 09:55:06 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050130095506-f21p6v6cgaobhn5j
Tags: 0.9.2-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * P3
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or modify
5
 
 * it under the terms of the GNU General Public License as published by
6
 
 * the Free Software Foundation; either version 2 of the License, or
7
 
 * (at your option) any later version.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 * GNU General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU General Public License
15
 
 * along with this program; if not, write to the Free Software
16
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 
 */
18
 
 
19
 
/**********************************************
20
 
 * volume.c
21
 
 * Copyright (C) 2001-2002 Bertrand 'blam' LAMY
22
 
 **********************************************/
23
 
 
24
 
#include "p3_base.h"
25
 
#include "math3d.h"
26
 
#include "frustum.h"
27
 
#include "coordsys.h"
28
 
#include "util.h"
29
 
#include "volume.h"
30
 
 
31
 
extern P3_renderer* renderer;
32
 
 
33
 
 
34
 
/*========*
35
 
 * VOLUME *
36
 
 *========*/
37
 
 
38
 
P3_class P3_class_volume = { 
39
 
  P3_ID_VOLUME,
40
 
  (batch_func)     P3_volume_batch,
41
 
  (render_func)    0,
42
 
  (shadow_func)    P3_volume_shadow,
43
 
  (raypick_func)   P3_volume_raypick,
44
 
  (raypick_b_func) P3_volume_raypick_b,
45
 
};
46
 
 
47
 
 
48
 
P3_volume* P3_volume_new (P3_volume* c) {
49
 
  if (c == NULL) {
50
 
    c = (P3_volume*) malloc (sizeof (P3_volume));
51
 
  }
52
 
  P3_coordsys_initialize ((P3_coordsys*) c);
53
 
  c->raypick_data = -1;
54
 
  c->class = &P3_class_volume;
55
 
  c->shape = NULL;
56
 
  return c;
57
 
}
58
 
 
59
 
void P3_volume_batch (P3_volume* c, P3_instance* csys) {
60
 
  P3_any_object* o;
61
 
  if (c->option & P3_OBJECT_HIDDEN) { return; }
62
 
  /* compute new renderer stuff: enter in this coordsys */
63
 
  P3_multiply_matrix (c->render_matrix, renderer->c_camera->render_matrix, P3_coordsys_get_root_matrix ((P3_coordsys*) c));
64
 
  c->frustum_data = -1;
65
 
  o = c->shape;
66
 
  if(o != NULL && o->class->batch != 0 && !(c->option & P3_OBJECT_HIDDEN)) {
67
 
    o->class->batch (o, (P3_instance*) c);
68
 
  }
69
 
}
70
 
 
71
 
int P3_volume_shadow (P3_volume* v, P3_instance* inst, P3_light* light) {
72
 
  if (v->shape != NULL && v->shape->class->shadow != 0) {
73
 
    return v->shape->class->shadow (v->shape, (P3_instance*) v, light);
74
 
  }
75
 
  return P3_FALSE;
76
 
}
77
 
 
78
 
void P3_volume_raypick (P3_volume* inst, P3_raypick_data* data, P3_raypickable* parent) {
79
 
  if (inst->shape == NULL || inst->shape->class->raypick == 0 || inst->option & P3_OBJECT_NON_SOLID) return;
80
 
  /* transform origin and direction into the volume coordsys */
81
 
  inst->shape->class->raypick (inst->shape, data, (P3_raypickable*) inst);
82
 
}
83
 
 
84
 
int P3_volume_raypick_b (P3_volume* inst, P3_raypick_data* data, P3_raypickable* parent) {
85
 
  if (inst->shape == NULL || inst->shape->class->raypick_b == 0 || inst->option & P3_OBJECT_NON_SOLID) return P3_FALSE;
86
 
  /* transform origin and direction into the volume coordsys */
87
 
  return inst->shape->class->raypick_b (inst->shape, data, (P3_raypickable*) inst);
88
 
}
89
 
 
90
 
void P3_volume_get_data (P3_volume* v, P3_chunk* chunk) {
91
 
  P3_chunk_save (chunk, v->m, 19 * sizeof (GLfloat));
92
 
  P3_chunk_save_int (chunk, v->option);
93
 
}
94
 
 
95
 
void P3_volume_set_data (P3_volume* v, P3_chunk* chunk) {
96
 
  v->class = &P3_class_volume;
97
 
  v->validity = P3_COORDSYS_INVALID;
98
 
  v->raypick_data = -1;
99
 
  P3_chunk_load (chunk, v->m, 19 * sizeof (GLfloat));
100
 
  v->option = P3_chunk_load_int (chunk);
101
 
}
102