1 /***************************************************************************
2 * Copyright (C) 2004-2005 by *
3 * Paolo Sacconier <axa1981@tin.it> *
4 * Francesco Tamagni <minchiahead@hacari.org> *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 ***************************************************************************/
21 #include "goal.h"
22
23 namespace gillo {
24
25 const float Goal::areaRadius = ODE_GOAL_DISTANCE;
26
Goal(Context & c)27 Goal::Goal(Context& c)
28 : Entity(c)
29 {
30 type = GOAL;
31 dSpaceID sid = dSimpleSpaceCreate(c.getSid());
32 gid = (dGeomID) sid;
33 Entity::Init();
34
35 /* ssg part */
36 ssgSimpleState * state = c.getState(STA_GOAL);
37 ssgSimpleState * alphastate = c.getState(STA_GOAL_CENTER);
38
39 sgVec3 dim[] = {
40 { ODE_GOAL_DIMX, ODE_GOAL_DIMY, ODE_GOAL_DIMZ },
41 { ODE_GOAL_DIMX, ODE_GOAL_DIMY, ODE_GOAL_DIMZ },
42 { ODE_GOAL_DISTANCE - ODE_GOAL_DIMX, ODE_GOAL_DIMY, ODE_GOAL_DIMY },
43 { ODE_GOAL_DISTANCE - ODE_GOAL_DIMX, ODE_GOAL_DIMY, ODE_GOAL_DIMY },
44 { ODE_GOAL_DISTANCE, 0.1*ODE_GOAL_DIMY, 0.9*(ODE_GOAL_DIMZ - ODE_GOAL_DIMY)},
45 { 2*areaRadius, 2*areaRadius, ODE_GOAL_DIMZ}
46 };
47 sgVec3 pos[] = {
48 { ODE_GOAL_DISTANCE/2, 0, 0 },
49 { -ODE_GOAL_DISTANCE/2, 0, 0 },
50 { 0, 0, -0.9*(ODE_GOAL_DIMZ/2 - ODE_GOAL_DIMY/2)},
51 { 0, 0, 0.9*(ODE_GOAL_DIMZ/2 - ODE_GOAL_DIMY/2)},
52 { 0, 0, 0 }
53 };
54
55 ssgaCube* e_obj;
56 for (int i = 0; i < 5; i++) {
57 e_obj = new ssgaCube () ;
58 e_obj -> setSize ( dim[i] ) ;
59 e_obj -> setCenter ( pos[i] ) ;
60 e_obj -> setKidState ( state ) ;
61 e_obj -> regenerate () ;
62 trans.addKid( e_obj );
63 gids[i] = dCreateBox (sid, dim[i][0], dim[i][1], dim[i][2]);
64 dGeomSetData(gids[i], this);
65 dGeomSetPosition (gids[i], (dReal) pos[i][0], (dReal) pos[i][1], (dReal) pos[i][2]);
66 }
67
68 alphaTrans.addKid( e_obj );
69 trans.removeKid( e_obj );
70
71 e_obj -> setKidState ( alphastate ) ;
72 e_obj -> regenerate () ;
73
74 // area geom
75 gids[5] = dCreateCCylinder (sid, areaRadius, ODE_GOAL_DIMZ);
76 dGeomSetData(gids[5], this);
77 ssgaCylinder* area_obj = new ssgaCylinder();
78 ssgTransform* area_tr = new ssgTransform();
79 area_obj -> setSize ( dim[5] ) ;
80 area_obj -> setCenter ( pos[4] ) ;
81 area_obj -> setKidState ( c.getState(STA_GOAL_AREA) ) ;
82 area_obj -> makeCapped ( 0 );
83 area_obj -> regenerate () ;
84 area_tr -> addKid( area_obj );
85 alphaTrans.addKid( area_tr );
86
87 }
88
89
update(float dt)90 void Goal::update(float dt) {
91 sgMat4 rotm;
92 const sgVec3 axis = { 0, 0, 1 };
93 static float angle = 0;
94
95 angle += 500*dt;
96 sgMakeRotMat4(rotm, angle, axis);
97
98 ((ssgTransform*) alphaTrans.getKid(1))->setTransform(rotm);
99 }
100
101
~Goal()102 Goal::~Goal()
103 {
104 }
105
getPos(sgVec3 out)106 void Goal::getPos(sgVec3 out)
107 {
108 sgZeroVec3(out);
109 }
110
111 };
112