Salut,

J'ai un léger problème dans la valeur retournée lors du picking, elle est bien du style 0.9[..] mais lors-ce que je veux placer un objet, avec sa valeur 2d-z il se place toujours plus près que prévu, donc à chaque frame il se rapproche ( l'objet ) et ça devient inutilisable.

Voici un exemple de l'exécutable:


Rien ne vaut un test, alors voici l'exécutable ( linux ): test.7z

Le code du picking est celui-ci: Picking.cpp

Utilisation:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
 
LDEmain()
{
    LDEwinit = 800;
    LDEhinit = 600;
    LDEinit();
 
    LDEcamera cam;
    cam.init();
    cam.pos.x = 0;
    cam.pos.y = 0;
    cam.pos.z = 0;
    cam.rot.y = -32;
    cam.rot.x = 30;
	cam.dist = 10;
 
	c.active = 1; // activate LDE console
 
	double gridcolor[] = {0,1,0};
 
	LDEpicking picking;
 
	vec3f mover = {2,1,-3};
 
	vec2i text = {0,0};
 
    LDEloop()
    {
        /// 3D stuff goes here ///////////////////////////
        LDE3dmode(45,0.1,500);
 
        // camera
	      if ( LDElalt && LDEmb1 )
	        {
	            cam.rot.y += (float)LDEcfx/10;
	            cam.rot.x += (float)LDEcfy/10;
	        }
	      if ( LDElalt && LDEmb3 ) cam.dist += (float)LDEcfy*(cam.dist/50);
	      if ( LDElalt && LDEmb2 )
	        {
	            cam.side = (float)LDEcfx/100;
	            cam.up = -(float)LDEcfy/100;
	        } else cam.side = 0, cam.up = 0;
		if ( LDEf ) cam.pos.x = 0, cam.pos.y = 0, cam.pos.z = 0;
        cam.setup();
        //
 
		LDEgetm();
 
		glLineWidth(5);
 
		picking.pos.x = LDEcx;
		picking.pos.y = LDEcy;
 
		if ( LDEa )
		{
			c.write( "Cursor on "+LDEnts( picking.coi )+" @ "+LDEnts( picking.z ) , 0,1,0 );
 
			picking.start(45,0.1,500);
 
			glPushMatrix();
			glTranslatef(mover.x,mover.y,mover.z);
 
			glPushName(1);
			glBegin(GL_LINES);
				glVertex3d(0.2,0,0);
				glVertex3d(1,0,0);
			glEnd();
			glPopName();
 
			glPushName(2);
			glBegin(GL_LINES);
				glVertex3d(0,0.2,0);
				glVertex3d(0,1,0);
			glEnd();
			glPopName();
 
			glPushName(3);
			glBegin(GL_LINES);
				glVertex3d(0,0,0.2);
				glVertex3d(0,0,1);
			glEnd();
			glPopName();
 
			glPushName(0);
			glBegin(GL_POINTS);
				glVertex3d(0,0,0);
			glEnd();
			glPopName();
 
			glPopMatrix();
 
			picking.end();
		}
 
		glDisable(GL_LIGHTING);
 
		glPushMatrix();
		glTranslatef(mover.x,mover.y,mover.z);
 
		glBegin(GL_LINES);
			glColor3d(1,0,0);
			glVertex3d(0.2,0,0);
			glVertex3d(1,0,0);
		glEnd();
 
		glBegin(GL_LINES);
			glColor3d(0,1,0);
			glVertex3d(0,0.2,0);
			glVertex3d(0,1,0);
		glEnd();
 
		glBegin(GL_LINES);
			glColor3d(0,0,1);
			glVertex3d(0,0,0.2);
			glVertex3d(0,0,1);
		glEnd();
 
		glColor3d(1,1,1);
		glBegin(GL_POINTS);
			glVertex3d(0,0,0);
		glEnd();
 
		glPopMatrix();
 
        LDEgrid(5,1,gridcolor,gridcolor);
 
		// 2D >> 3D
		if ( LDEz ) LDE2dto3d( picking.pos, mover, picking.z );
 
        /// 2D stuff goes here ///////////////////////////
        LDE2dmode();
 
		LDEtext(0,0,LDEnts( LDEfps ) );
 
		LDE3dto2d(mover,text);
		LDEtext(text.x,text.y, "mover" );
 
        LDErefresh(0);
        if ( LDEf9 | LDEesc ) LDEstop = 1;
    }
}
Et le code de 2D vers 3D il est tout simple ici:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
void LDE2dto3d(vec2i pos2d, vec3f &pos3d, double z2d )
 
{
 
    double x3d, y3d, z3d,
 
    	   x2d = pos2d.x,
 
           y2d = LDEhinit-pos2d.y;
 
    gluUnProject( x2d, y2d, z2d, LDEmatrix_m, LDEmatrix_p, LDEviewport, &x3d, &y3d, &z3d);
 
    pos3d.x = x3d;
 
    pos3d.y = y3d;
 
    pos3d.z = z3d;
 
 
}
Merci par avance si vous avez une astuce