Changeset 270

Show
Ignore:
Timestamp:
11/02/08 15:35:38 (2 months ago)
Author:
mihai.maruseac
Message:

ray picking de la eye coordinate catre punctul selectat si mai departe; am ascuns terenul si modelul si am schimbat perspectiva

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • test/loadmodel.py

    r267 r270  
    5353        render.addLight(light1) 
    5454        #This is an example of terrain rendering 
    55         AddModel.add_model("models/machinegun/3dm-q3machinegun.3ds", [0, 10, 0]) 
     55        #AddModel.add_model("models/machinegun/3dm-q3machinegun.3ds", [0, 10, 10]) 
    5656        terrain = Terrain.Terrain() 
    5757        patch = Terrain.TerrainPatch(x_origin = -64) 
     
    6868        terrain.addPatch(patch)#""" 
    6969        terrain.Enable() 
    70         render.terrain = terrain 
     70        #render.terrain = terrain 
    7171        #model = Test.TTest() 
    7272        #render.testmodel = model 
     
    8787        return "drawer" 
    8888 
    89 render = Render.Render(800, 600, posx = 0, posy = -1.5, posz = -100, far = 10000) 
     89render = Render.Render(800, 600, posx = 0, posy = 0, posz = -100, far = 10000) 
    9090hfk.insert(drawer()) 
    9191hfk.insert(render) 
  • trunk/hfall/Engine/Render.py

    r265 r270  
    212212            glPopMatrix() 
    213213             
    214             self.ogl.activate_model() 
     214            #self.ogl.activate_model() 
    215215            #just to make it work 
    216216 
  • trunk/hfall/Matrix.py

    r255 r270  
    33""" 
    44import math 
     5from pyglet.gl import * 
    56 
    67import Vector 
     
    326327                    c._m[i][j] = s 
    327328            return c 
     329        elif isinstance(other, Vector.Vector4): 
     330            v = Vector.Vector4() 
     331            for i in range(4): 
     332                s = 0 
     333                for j in range(4): 
     334                    s += self._m[i][j] * other[j] 
     335                v[i] = s 
     336            return v 
    328337        else: 
    329338            return Matrix4([self._m[0][0] * other,\ 
     
    533542               '|' + str(self._m[2][0]) + ' ' + str(self._m[2][1]) + ' ' + str(self._m[2][2]) + ' ' + str(self._m[2][3]) + '|\n' +\ 
    534543               '|' + str(self._m[3][0]) + ' ' + str(self._m[3][1]) + ' ' + str(self._m[3][2]) + ' ' + str(self._m[3][3]) + '|' 
     544 
     545    def asDouble(self): 
     546        m = (GLdouble*16)(*[]) 
     547        m[0] = self._m[0][0] 
     548        m[1] = self._m[0][1] 
     549        m[2] = self._m[0][2] 
     550        m[3] = self._m[0][3] 
     551        m[4] = self._m[1][0] 
     552        m[5] = self._m[1][1] 
     553        m[6] = self._m[1][2] 
     554        m[7] = self._m[1][3] 
     555        m[8] = self._m[2][0] 
     556        m[9] = self._m[2][1] 
     557        m[10] = self._m[2][2] 
     558        m[11] = self._m[2][3] 
     559        m[12] = self._m[3][0] 
     560        m[13] = self._m[3][1] 
     561        m[14] = self._m[3][2] 
     562        m[15] = self._m[3][3] 
     563        return m 
  • trunk/hfall/UI/UI.py

    r252 r270  
    2323import Mathbase 
    2424from Console import Console 
     25from glcalls import * 
     26from View import * 
    2527 
    2628""" 
     
    5254                game_get(symbol,modifiers) 
    5355 
    54 def on_mouse_press(x, y, button, modifiers): 
     56def on_mouse_press(X, Y, button, modifiers): 
     57        if button == mouse.LEFT and modifiers & key.LCTRL: 
     58                proj = glGetMatrix(GL_PROJECTION_MATRIX) 
     59                model = glGetMatrix(GL_MODELVIEW_MATRIX) 
     60                print model 
     61                invmodel = model.inverse() 
     62                view = glGetVector4(GL_VIEWPORT) 
     63                z = 0.0 
     64                posX = (GLdouble * 1)() 
     65                posY = (GLdouble * 1)() 
     66                posZ = (GLdouble * 1)() 
     67                gluUnProject(X, Y, 1.0, model.asDouble(), proj.asDouble(),\ 
     68                             view.asDouble(), posX, posY, posZ) 
     69                x = posX[0] 
     70                y = posY[0] 
     71                z = posZ[0] 
     72                gluUnProject(X, Y, 1.0, model.asDouble(), proj.asDouble(),\ 
     73                             view.asDouble(), posX, posY, posZ) 
     74                xx = posX[0] 
     75                yy = posY[0] 
     76                zz = posZ[0] 
     77                gluUnProject(X, Y, 10.0, model.asDouble(), proj.asDouble(),\ 
     78                             view.asDouble(), posX, posY, posZ) 
     79                x10 = posX[0] 
     80                y10 = posY[0] 
     81                z10 = posZ[0] 
     82                gluUnProject(X, Y, 100.0, model.asDouble(), proj.asDouble(),\ 
     83                             view.asDouble(), posX, posY, posZ) 
     84                xxx = posX[0] 
     85                yyy = posY[0] 
     86                zzz = posZ[0] 
     87                #print "0:",x10,y10,z10 
     88                #print "1:",xx,yy,zz 
     89                #print "10:",x,y,z 
     90                #print "100:",xxx,yyy,zzz 
     91                #print "r:",(x10-xx)/(x-xx),(y10-yy)/(y-yy),(z10-zz)/(z-zz) 
     92                #print "rr:",(x10-xxx)/(x-xxx),(y10-yyy)/(y-yyy),(z10-zzz)/(z-zzz) 
     93                #print "" 
     94                V1 = Vector3(xx - x,\ 
     95                             yy - y,\ 
     96                             zz - z) 
     97                #print "V1:",V1 
     98                V2 = Vector3(0-x, 0-y, 0-z) 
     99                #print "V2:",V2 
     100                #print "distance to 0:", V1.crossProduct(V2).length() / V1.length() 
     101                P0 = Vector3(x, y, z) 
     102                n = Vector3(0,1,0) 
     103                #lamda = - P0.dotProduct(n) / V1.dotProduct(n) 
     104                #P = P0 + V1 * lamda 
     105                print P0 
     106                #print P 
     107                print "" 
     108                r_p = Vector4(0,0,0,1) 
     109                r_v = Vector4(x,y,z,0) 
     110                r_p = invmodel * r_p 
     111                r_v = invmodel * r_v 
     112                print r_p, "\n" 
     113                print r_v 
     114                r_v = r_v * (-1000000) 
     115                global_render.line_manager.add(Wires.Line(r_p[0], r_p[1], r_p[2],\ 
     116                                                          r_p[0] + r_v[0],\ 
     117                                                          r_p[1] + r_v[1],\ 
     118                                                          r_p[2] + r_v[2])) 
     119                global_UI.refresh_world_coords(x,y,z) 
     120 
     121 
     122def old_on_mouse_press(x, y, button, modifiers): 
    55123        if button == mouse.LEFT and modifiers & key.LCTRL: 
    56124                mat_proj = (GLdouble * 16)() 
    57125                mat_model = (GLdouble * 16)() 
    58126                mat_view = (GLint* 4)() 
    59                 glGetDoublev(GL_PROJECTION_MATRIX,mat_proj) 
    60                 glGetDoublev(GL_MODELVIEW_MATRIX,mat_model) 
    61                 glGetIntegerv(GL_VIEWPORT,mat_view) 
     127                ##glGetDoublev(GL_PROJECTION_MATRIX,mat_proj) 
     128                ##glGetDoublev(GL_MODELVIEW_MATRIX,mat_model) 
     129                ##glGetIntegerv(GL_VIEWPORT,mat_view) 
     130 
     131                mat_proj = glGetMatrix(GL_PROJECTION_MATRIX) 
     132                 
     133                #print mat_proj[:] 
     134                print mat_model[:] 
     135                print mat_view[:] 
    62136                world_x = (GLdouble * 1)() 
    63137                world_y = (GLdouble * 1)() 
     
    66140                world_y2 = (GLdouble * 1)() 
    67141                world_z2 = (GLdouble * 1)() 
    68                 if gluUnProject(x,y,-5,mat_model,mat_proj,mat_view,\ 
     142                y = mat_view[3] - y; 
     143                if gluUnProject(x,y,0.0,mat_model,mat_proj,mat_view,\ 
    69144                     world_x,world_y,world_z) == GLU_FALSE: 
    70145                        print "Error in UI.on_mouse_press - projection results" + \ 
    71146                              "are not valid" 
    72                 if gluUnProject(x,y,5,mat_model,mat_proj,mat_view,\ 
     147                if gluUnProject(x,y,1.0,mat_model,mat_proj,mat_view,\ 
    73148                     world_x2,world_y2,world_z2) == GLU_FALSE: 
    74149                        print "Error in UI.on_mouse_press - projection results" + \ 
    75150                              "are not valid" 
    76151                # Folosim ecuatiile parametrice ale dreptei in spatiu  
    77                 factor = 100 
     152                factor = 10 
     153                print world_x[0], world_y[0], world_z[0], '<-----' 
    78154                x1 = world_x[0] + factor * (world_x2[0]-world_x[0]) 
    79155                x2 = world_x[0] - factor * (world_x2[0]-world_x[0]) 
     
    82158                z1 = world_z[0] + factor * (world_z2[0]-world_z[0]) 
    83159                z2 = world_z[0] - factor * (world_z2[0]-world_z[0]) 
     160                x = world_x[0] 
     161                y = world_y[0] 
     162                z = world_z[0] 
     163                xx = world_x2[0] 
     164                yy = world_y2[0] 
     165                zz = world_z2[0] 
     166                print x, y, z, xx, yy, zz, '<<---verifica-le' 
    84167                 
    85                 global_render.line_manager.add(Wires.Line(x1,y1,z1,z2,y2,z2)) 
     168                global_render.line_manager.add(Wires.Line(x,y,z,xx,yy,zz)) 
     169                glBegin(GL_LINES) 
     170                glColor3f(1.0, 0.0, 0.0); 
     171                glVertex3f(x+1, y+1, z+1) 
     172                glVertex3f(xx+1, yy+1, zz+1) 
     173                glEnd() 
    86174                global_UI.refresh_world_coords(world_x[0],world_y[0],world_z[0]) 
    87175         
  • trunk/hfall/Vector.py

    r243 r270  
    33""" 
    44import math 
     5from pyglet.gl import * 
    56 
    67class Vector2: 
     
    282283               ' ' + str(self.z) +\ 
    283284               ' ' + str(self.w) + ']' 
     285 
     286    def asDouble(self): 
     287        m = (GLint*4)(*[]) 
     288        m[0] = int(self.x) 
     289        m[1] = int(self.y) 
     290        m[2] = int(self.z) 
     291        m[3] = int(self.w) 
     292        return m