File: ring.d

package info (click to toggle)
projectl 1.001.dfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,720 kB
  • ctags: 5
  • sloc: xml: 57; makefile: 32
file content (112 lines) | stat: -rw-r--r-- 3,024 bytes parent folder | download | duplicates (3)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
module util.ring;
private import opengl;
private import std.math; 
private import util.parts;
private import util.vector;
private import util.matrix;
private import br.gamemanager;

public interface Caller{
	public void reportRing(Ring ring);
	public bool exists();
}
public class Ring:Parts{
	private:
	static const int DIVISION = 16;
	static double[] si;
	static double[] co;
	Caller caller;
	string _name;
	int span;
	real sint ,cost;
	public this(Caller caller ,Vector3 pos ,string name ,int span ,double R ,double G,double B,double alpha ,real deg = 90.0){
		if(caller is null || !caller.exists){
			vanish();
			return;
		}
		if(si.length == 0){
			si.length = DIVISION;
			for(int i=0;i<DIVISION;i++){
				si[i] = sin(PI *2.0 * cast(double)i / DIVISION);
			}
		}
		if(co.length == 0){
			co.length = DIVISION;
			for(int i=0;i<DIVISION;i++){
				co[i] = cos(PI *2.0 * cast(double)i / DIVISION);
			}
		}
		this.pos = pos;
		/*
		foreach(ref Vector3 lpos;locuspos){
			lpos = cast(Vector3)pos.clone();
		}
		*/
		this.caller = caller;
		this._name = name;
		this.span = span;
		this.R=R;
		this.G=G;
		this.B=B;
		this.alpha=alpha;
		
		deg = 0.0;
		sint = sin(deg * PI / 180.0);
		cost = cos(deg * PI / 180.0);
		
		
		ringManager.add(this);
	}
	public override void move(){
		super.move();
		if(caller !is null && caller.exists){
			if(span <= cnt)report();
		}else vanish();
		/*
		if(pos.y < screen.GAME_DOWN || screen.GAME_UP < pos.y ||
			screen.GAME_RIGHT  < pos.x || pos.x < screen.GAME_LEFT )vanish();
		*/
	}
	public void report(){
		if(caller !is null && caller.exists == true){
			caller.reportRing(this);
		}
		vanish();
	}
	public override void draw(){
//		super.draw();
		glTranslatef(pos.x ,pos.y ,pos.z);
		if(caller is null)return;
		glEnable(GL_BLEND);
		double radius1=fmax(0.0,cast(double)(span - cnt + 9) * 3);
		double radius0=fmax(0.0,cast(double)(span - cnt - 0)  * 3);
		for(int j=0;j<DIVISION-1;j++){
			glBegin(GL_POLYGON);
//			glColor3f(0 ,0 ,0);
			glColor4f(R,G,B,0.0);
			glVertex3f(radius1*co[j]*cost,radius1*si[j]*cost ,radius1*sint);
			glVertex3f(radius1*co[j+1]*cost,radius1*si[j+1]*cost ,radius1*sint);
//			glColor3f(R * alpha,G * alpha ,B * alpha);
			glColor4f(R,G,B,alpha);
			glVertex3f(radius0*co[j+1]*cost,radius0*si[j+1]*cost ,radius0*sint);
			glVertex3f(radius0*co[j]*cost,radius0*si[j]*cost ,radius0*sint);
			
			glEnd();
		}
		glBegin(GL_POLYGON);
//		glColor3f(0 ,0 ,0);
		glColor4f(R,G,B,0);
		glVertex3f(radius1*co[0]*cost,radius1*si[0]*cost ,radius1*sint);
		glVertex3f(radius1*co[DIVISION-1]*cost,radius1*si[DIVISION-1]*cost ,radius1*sint);
//		glColor3f(R * alpha,G * alpha ,B * alpha);
		glColor4f(R,G,B,alpha);
		glVertex3f(radius0*co[DIVISION-1]*cost,radius0*si[DIVISION-1]*cost ,radius0*sint);
		glVertex3f(radius0*co[0]*cost,radius0*si[0]*cost ,radius0*sint);
		glEnd();
		glDisable(GL_BLEND);

	}
	public string name(){
		return _name;
	}
}