File: view.C

package info (click to toggle)
battleball 2.0-13
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,016 kB
  • ctags: 3,097
  • sloc: cpp: 15,310; makefile: 48; csh: 34
file content (51 lines) | stat: -rw-r--r-- 1,336 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) 1997 Philip A. Hardin (pahardin@cs.utexas.edu)
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License v2 or later.


#include "view.h"


/*=========================================================================*/
view& view::Copy(const view& v) {
  maxPts= numPts=		v.numPts;
  modelToView=			v.modelToView;
  shape=			v.shape;

  if (maxPts >0) {
    pts= new pt3d[maxPts];
    forii(numPts) pts[i]=v.pts[i];
  }

  return *this;
}


/*-------------------------------------------------------------------------*/
// In:  mtv= new modelToView transformation matrix
void view::Update(xregion3d *newShape, const tmtrx& newMtv) {

  // if the shape has changed and the new shape has more pts than
  // the old one, allocate an adequately large array of pts
  if (newShape != shape) {
    numPts= newShape->pts.Num();
    if (numPts >maxPts) {
      if (maxPts >0) delete [] pts;
      maxPts= numPts;
      pts= new pt3d[maxPts];
    }
  }
  
  if (newShape != shape || !modelToView.RotationSame(newMtv)) {
    newShape->TransformTo(newMtv,pts);
  }
  else {
    pt3d delta= newMtv.Cart() - modelToView.Cart();
    if (delta != pt3d(0,0,0)) {
      forii(newShape->pts.Num())
	pts[i] += delta;
    }
  }
  modelToView= newMtv;
  shape= newShape;
}