-
Notifications
You must be signed in to change notification settings - Fork 0
/
cartographer.lua
598 lines (454 loc) · 24 KB
/
cartographer.lua
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
local vector = require "vectors"
local lujgl = require "lujgl"
local ffi = require "ffi"
local gl, glu = lujgl.gl, lujgl.glu
local key, mouse, px, py, pz, rx, ry, rz, xrang, yrang=
{}, {}, -31,-43,-14, 38, 80, 90, 242, 32
mouse.x=0
mouse.y=0
mouse.xold=0
pickoffst={0,0}
objX=ffi.new("double[1]");
objY=ffi.new("double[1]");
objZ=ffi.new("double[1]");
-- swy: redirect the debug prints to the actual 3D screen into a simulated kill log
printbufpos=1; movetxt=0; new_unprinted_lines=0
printbufmax=20; printbuf={}; orig_print=print
function print(line, ...) local arg={...}
orig_print(line, ...) -- swy: call the original function so that it still prints to the console
printbufpos = (printbufpos+1) % printbufmax -- swy: advance the ring buffer position, with wraparound
for k,v in ipairs(arg) do -- swy: if there is more than one argument, append the extra variables
line=line.. " "..tostring(v) -- (could be a number/bool that needs conversion) to the line
end
if new_unprinted_lines < printbufmax/3 then -- swy: this is used to scroll down a notch for every line, don't allow
new_unprinted_lines=new_unprinted_lines+1 -- scrolling too many of them at once or all of them will move below the screen
end
printbuf[printbufpos]=line -- swy: paste it into the current ring buffer position for printing
end
--@ Load cooler dependencies
require "winapi"
require "mab-registry"
reg=mab.registry:query()
cartographer={}; dofile("cartographer.conf.ini") --new easy peasy config file
require "mab-msys"
msys=mab.msys:getmsysfolder()
mod=mab.msys:getmodulefolder()
print(string.format("Msys folder at <%s>",msys))
print(string.format("Module folder at <%s>",mod))
--@ init and stuff
lujgl.initialize("cartographer", 800, 600)
handle=winapi:GetHandle("","GLFW27")
--@ load our font
require "soil"
require "mab-font"
function check(f)
if not io.open(f,"r") then return false else io.close() return f end
end
mab.font:load(check(mod.."\\Data\\FONT_DATA.XML") or mod.."\\..\\..\\Data\\FONT_DATA.XML",
check(mod.."\\textures\\FONT.dds") or mod.."\\..\\..\\textures\\FONT.dds")
-- mab.font:load("R:\\Juegos\\swconquest\\modules\\swconquest\\Module Data\\FONT_DATA.XML",
-- "R:\\Juegos\\swconquest\\modules\\swconquest\\Textures\\FONT_SWC.dds")
--@ load our map
require "mab-map"
mab.map:load(mod)--"R:\\Juegos\\swconquest\\modules\\swconquest")
--@ load our locations
require "mab-parties"
mab.parties:load(msys.."\\module_parties.py")--"R:\\Juegos\\swconquest\\modules\\swconquest-msys\\module_parties.py")
mab.parties:groundalign()
--@ opengl directives
gl.glShadeModel(gl.GL_SMOOTH)
gl.glEnable(gl.GL_AUTO_NORMAL)
gl.glEnable(gl.GL_LINE_SMOOTH)
gl.glEnable(gl.GL_POINT_SMOOTH)
gl.glEnable(gl.GL_CULL_FACE)
gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST)
gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT,gl.GL_NICEST)
gl.glMatrixMode(gl.GL_MODELVIEW)
glu.gluLookAt(0,0,-5,
0,0,0,
0,1,1)
gl.glEnable(gl.GL_DEPTH_TEST)
gl.glDepthFunc(gl.GL_LESS)
gl.glEnable(gl.GL_COLOR_MATERIAL)
gl.glEnable(gl.GL_LIGHTING)
gl.glEnable(gl.GL_LIGHT0)
--@ we like callbacks
lujgl.setIdleCallback(function()
--manage non-blocking input
sin,cos,rad,abs=math.sin,math.cos,math.rad,math.abs
--x3 speed multiplier when CTRL is pressed together with the arrow keys
--there's an additional boost when the camera is high over the terrain
local multiplier = (key[289] and 3 or 1) * (abs(py)/20); if multiplier==0 then multiplier=1 end
--rebuild the direction vector from the /yaw/ angle (in degrees) using trigonometry
if key["w"] or key[283] then pz=pz+cos(rad(xrang)) * multiplier
px=px-sin(rad(xrang)) * multiplier end
if key["s"] or key[284] then pz=pz-cos(rad(xrang)) * multiplier
px=px+sin(rad(xrang)) * multiplier end
if key["a"] or key[285] then pz=pz+cos(rad(xrang-90)) * multiplier
px=px-sin(rad(xrang-90)) * multiplier end --reversed
if key["d"] or key[286] then pz=pz-cos(rad(xrang-90)) * multiplier
px=px+sin(rad(xrang-90)) * multiplier end --reversed
if mab.parties[picked] then
--rotate mode
if key['r'] then
mab.parties[picked].isbeenmod=true
if not mab.parties[picked].oldpos then --save position for good measure
mab.parties[picked].oldpos = mab.parties[picked].pos
end
if not mab.parties[picked].oldrot then --save rotation for good measure
mab.parties[picked].oldrot = mab.parties[picked].rot
end
mab.parties[picked].rot = mab.parties[picked].rot + (mouse.xold-mouse.x)/2
if mab.parties[picked].rot > 360 then mab.parties[picked].rot=0
elseif mab.parties[picked].rot < 0 then mab.parties[picked].rot=360 end --clamp between 0<>360 deg
--drag mode
elseif key['g'] then
mab.parties[picked].isbeenmod=true
if not mab.parties[picked].oldpos then --save it for good measure
mab.parties[picked].oldpos = mab.parties[picked].pos
end
--fill the new value so it will be drawn in the next frame
mab.parties[picked].pos=vector.new(objX[0],objZ[0],objY[0])
end
end
if mouse.lclick then xrang=xrang+(mouse.xold-mouse.x)/2; rx=1
yrang=yrang+(mouse.yold-mouse.y)/2; ry=1; end
if yrang<-90 then yrang=-90 end
mouse.xold=mouse.x
mouse.yold=mouse.y
if yrang > 360 then yrang=0
elseif yrang < 0 then yrang=360 end --clamp between 0<>360 deg
if xrang > 360 then xrang=0
elseif xrang < 0 then xrang=360 end --clamp between 0<>360 deg
end)
lujgl.setRenderCallback(function()
--let's fix aspect ratio
gl.glViewport(0, 0, lujgl.width, lujgl.height)
gl.glMatrixMode(gl.GL_PROJECTION)
gl.glLoadIdentity()
glu.gluPerspective(60,lujgl.width / lujgl.height, 0.01, 4000)
gl.glMatrixMode(gl.GL_MODELVIEW)
gl.glLoadIdentity()
--/pitch/ rotation -> /yaw/ rotation -> translation
gl.glRotatef(yrang,ry, 0, 0)
gl.glRotatef(xrang, 0,rx, 0)
gl.glTranslatef(px,py,pz)
lujgl.glLight(gl.GL_LIGHT0, gl.GL_AMBIENT, 0.1, 0.12, 0.19)
lujgl.glLight(gl.GL_LIGHT0, gl.GL_POSITION, 10, 1, 1, 0)
--light gray and clean the screen
gl.glClearColor(.18,.18,.22,1)-- probably this looks better
gl.glClear(bit.bor(gl.GL_COLOR_BUFFER_BIT, gl.GL_DEPTH_BUFFER_BIT))
--Subtle fog
gl.glFogi(gl.GL_FOG_MODE, gl.GL_LINEAR)
gl.glFogfv(gl.GL_FOG_COLOR, ffi.new("const float[4]", {.36*2,.3*2,.32*2,.6}))
gl.glFogf(gl.GL_FOG_DENSITY, 0.35)
gl.glHint(gl.GL_FOG_HINT, gl.GL_DONT_CARE)
gl.glFogf(gl.GL_FOG_START, 100)
gl.glFogf(gl.GL_FOG_END, 1000)
gl.glEnable(gl.GL_FOG)
--draw the map
gl.glDisable(gl.GL_BLEND)
gl.glEnable(gl.GL_LIGHT0)
if not mapmesh or not gl.glIsList(mapmesh) then
print"(i)no cache available, rebuilding displaylist"; local start=os.clock()
mab.map:softnormal()
mapmesh=gl.glGenLists(1)
gl.glNewList(mapmesh, gl.GL_COMPILE)
gl.glBegin(gl.GL_TRIANGLES)
for i=1,#mab.map.fcs do
x=tonumber(mab.map.fcs[i][11])
gl.glColor3f(unpack(mab.map.terrain[x] or {1,0,1}))
for j=1,3 do
local nm=faceted and mab.map.fcn[i]
or mab.map.vtn[mab.map.fcs[i][j]]
gl.glNormal3d(nm.x,nm.y,nm.z)
local vt=mab.map.vtx[mab.map.fcs[i][j]]
gl.glVertex3d(vt.x,vt.y,vt.z)
end
end
gl.glEnd()
gl.glEndList()
print("generated displaylist "..(os.clock()-start).."s")
--mab.map=nil --garbage collector, do your work!
else
gl.glCallList(mapmesh)
end
--@2D unprojection
local winX=ffi.new("float[1]", mouse.x -pickoffst[1]);
local winY=ffi.new("float[1]",(lujgl.height-mouse.y)-pickoffst[2]);
local winZ=ffi.new("float[1]",1);
gl.glReadPixels( winX[0], winY[0], 1,1, gl.GL_DEPTH_COMPONENT, gl.GL_FLOAT, winZ );
local modelview=ffi.new("double[16]",1);
gl.glGetDoublev( gl.GL_MODELVIEW_MATRIX, modelview );
local projection=ffi.new("double[16]",1);
gl.glGetDoublev( gl.GL_PROJECTION_MATRIX, projection );
local viewport=ffi.new("int[4]",1);
gl.glGetIntegerv( gl.GL_VIEWPORT, viewport );
glu.gluUnProject (winX[0], winY[0], winZ[0], modelview, projection, viewport, objX, objY, objZ)
--@draw the markers
gl.glEnable(gl.GL_BLEND)
gl.glDisable(gl.GL_FOG)
for p=1,#mab.parties do
gl.glPolygonMode( gl.GL_FRONT_AND_BACK, gl.GL_LINE )
gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE)--vertex colored solid
gl.glPushMatrix()
gl.glTranslated(mab.parties[p].pos.x, mab.parties[p].pos.z,
mab.parties[p].pos.y)
gl.glRotatef(mab.parties[p].rot, 0, 1, 0)
gl.glColor4d(.8,.8,.8,.8)
gl.glDisable(gl.GL_LIGHTING)
--cross marker and yellow tinting when selected
if picked==p then
gl.glColor4d(.6,.2,0,.7) --subtly orangey
gl.glBegin(gl.GL_LINES)
gl.glVertex3d(0, 1,0) --vertical
gl.glVertex3d(0,-1,0)
gl.glVertex3d( 1,0,0) --x
gl.glVertex3d(-1,0,0)
gl.glVertex3d(0,0, 1.2) --y (pointing to the north a bit)
gl.glVertex3d(0,0,-1)
gl.glEnd()
gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ZERO)--vertex colored solid
gl.glColor4d(1,.1,0,1) --shockingly hot red
gl.glBegin(gl.GL_LINES)
gl.glVertex3d(0,1, 1.2) --y (pointing to the north a bit)
gl.glVertex3d(0,1, 0.0)
gl.glEnd()
gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE)--vertex colored solid
gl.glColor4d(1,.6,0,1) --hot yellow
end
gl.glEnable(gl.GL_LIGHTING)
quad = glu.gluNewQuadric()
glu.gluQuadricOrientation(quad, glu.GLU_OUTSIDE)
glu.gluSphere(
quad,
1,
4,
4
);
gl.glPopMatrix()
local scrX=ffi.new("double[1]",1);
local scrY=ffi.new("double[1]",1);
local scrZ=ffi.new("double[1]",1);
local modelview=ffi.new("double[16]",1);
gl.glGetDoublev( gl.GL_MODELVIEW_MATRIX, modelview );
local projection=ffi.new("double[16]",1);
gl.glGetDoublev( gl.GL_PROJECTION_MATRIX, projection );
local viewport=ffi.new("int[4]",1);
gl.glGetIntegerv( gl.GL_VIEWPORT, viewport );
glu.gluProject(mab.parties[p].pos.x, mab.parties[p].pos.z, mab.parties[p].pos.y, modelview, projection, viewport, scrX, scrY, scrZ);
distance_max = cartographer.conf.labeldist and cartographer.conf.labeldist or 120 -- swy: have a sensible default in case the configuration file is old and doesn't have the new `labeldist` key
distance = (vector.new(-px, -pz, -py) - mab.parties[p].pos):len() -- swy: compute the length between the camera and the current party origin, don't ask me about the weird XZY swizzling and negations from ten years ago,
-- only got them right after adding debug code to see where they matched. :)
if (scrX[0] > -(lujgl.width/2) and scrX[0] < lujgl.width ) and -- swy: cull the party labels when they sit outside of the viewport, first horizontal with some leeway so that the right-aligned text shows up when the origin goes beyond the left side
(scrY[0] > 0 and scrY[0] < lujgl.height) and -- then vertically, easier case that just skips them when the origin goes beyond the top or bottom of the screen, not easily noticed
(scrZ[0] < 1 ) and -- then avoid drawing any labels behind the camera, without this we will draw like a black hole, showing in front what's behind
(distance < distance_max ) then -- use the actual distance from the camera to control how far the label shows up, instead of the unprojection thing.
gl.glPolygonMode( gl.GL_FRONT_AND_BACK, gl.GL_FILL )
gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_SRC_COLOR)--outlines
gl.glColor4d(1,1,1,1)
lujgl.begin2D()
if mab.parties[p].kind==1 then
scal=.66
elseif mab.parties[p].kind==2 then
scal=.33
end
for i=1,2 do
mab.font:print( ( (key[287] or key[288]) and mab.parties[p].id or mab.parties[p].name), --switch between party name and id by pressing the shift keys...
scrX[0],scrY[0],scal)
gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_CONSTANT_ALPHA) -- swy: draw the 3D settlement label a second time additively, to highlight the inner glyph shape
if picked==p then gl.glColor4d(1,.5,0,1) end -- swy: set it to an orangey red if selected
end
lujgl.end2D()
end
-- end
end
--draw 2d
gl.glPolygonMode( gl.GL_FRONT_AND_BACK, gl.GL_FILL )
lujgl.begin2D()
local highlight=.7 and (key['g'] or key['r']) or .3
gl.glColor4d(1,.9,1,highlight)
gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_CONSTANT_ALPHA)--vertex colored solid
mab.font:print(string.format("%d--%d",mouse.x, lujgl.height-mouse.y),
49,lujgl.height/2-110,.6)
mab.font:print(string.format("x:%g y:%g z:%g",-objX[0],objZ[0],objY[0]),
49,lujgl.height/2-60,.7)
if mab.parties[picked] then
mab.font:print(string.format("%s (%g\xBA)", mab.parties[picked].id, mab.parties[picked].rot), -- swy: 0xBA is "º" without using UTF-8 encoding, so that the bitmap font shows it correctly
49,lujgl.height/2-0,.7)
end
gl.glColor4d(.3,1,1,((lujgl.height-(mouse.y-60))/lujgl.height)*2) --cool fadeoff when cursor is close :)
mab.font:print((mab.parties[picked] and
"{G} Drag party "..
"{R} Rotate party | " or "")..
"{F5} Save map.txt "..
"{F6} Reload map.txt "..
"{F7} Import Obj "..
"{F8} Export Obj | "..
"{F9} Save edited parties "..
"{F10} Reload module_parties.py - Hold: "..
"{Shift} Show party IDs "..
"{Ctrl} Move fast | "..
"{Tab} Sharp triangles",
1,10,.3)
-- swy: a real m&b map editor clearly needs its own (animated) kill log
if new_unprinted_lines > 0 then
movetxt = movetxt + (20 * new_unprinted_lines) -- swy: reset it down a notch by a line height size every time a new line arrives
new_unprinted_lines = 0
end
if movetxt > 0 then
movetxt = movetxt - 1 -- swy: slowly animate the lines moving them up until reaching the base position
end
for i=1, printbufmax do -- swy: do the actual printing here
gl.glColor4d(1,.9,.4, (printbufmax-i)/printbufmax) -- swy: the more the lines go up, the fainter they look
mab.font:print(printbuf[(printbufpos + printbufmax - i) % printbufmax], 20, 45 - movetxt + (20 * i), .3) -- print the oldest line first and go down, the newest is the last one
end
lujgl.end2D()
--bugs ahoy?
lujgl.checkError()
end
)
lujgl.setEventCallback(function(ev,...) local arg={...}
--print("Event", ev, ...)
if ev=="key" then -- keyboard presses
local down,k=arg[1],arg[2]
if k=="w" or k==283
or k=="a" or k==285
or k=="s" or k==284
or k=="d" or k==286
or k==287 or k==288
or k==265 or k==264 --f8 & f7
or k==262 or k==263 --f5 & f6
or k==266 or k==267 --f9 & f10
or k==289 --Ctrl
or k=="r" or k=="g" then --R for rotation and G for ground
key[k]=down end
--tab switches between faceted display modes
if k==293 and down then faceted = not faceted; print("faceted is",faceted); mapmesh=nil
elseif k==265 and down then local objpath=winapi:SaveDialog(handle) --f8
if objpath and mapmesh then
print(string.format("saving OBJ to <%s>",objpath))
mab.map:saveobj(objpath)
end
elseif k==264 and down then local objpath=winapi:OpenDialog(handle) --refresh cached map end --f7
if objpath and mapmesh then
print(string.format("loading OBJ from <%s>",objpath))
mab.map:loadobj(objpath,false)
if mapmesh then gl.glDeleteLists(mapmesh,1) end; mapmesh=nil
mab.parties:groundalign()
end
elseif k==262 and down then if mapmesh then mab.map:save(mod.."\\map.txt",true) end --f5
elseif k==263 and down then if mapmesh and winapi:messagebox() then --f6
mab.map:load(mod);
if mapmesh then gl.glDeleteLists(mapmesh,1) end; mapmesh=nil
end--refresh cached map end
elseif k==266 and down then mab.parties:save(msys.."\\module_parties.py") --f9
elseif k==267 and down then mab.parties:load(msys.."\\module_parties.py") --f10
mab.parties:groundalign()
end
elseif ev=="motion" then -- mouse movement
mouse.x=arg[1]
mouse.y=arg[2]
elseif ev=="mouse" then -- mouse clicks
local k,down,x,y=arg[1],arg[2],arg[3],arg[4]
if k==1 and down then
local winX=ffi.new("float[1]",mouse.x);
local winY=ffi.new("float[1]",lujgl.height-mouse.y);
local pickId=ffi.new("GLubyte[4]",1);
--@draw the color coded marker
gl.glClearColor(0,0,0,0)
gl.glClear(bit.bor(gl.GL_COLOR_BUFFER_BIT, gl.GL_DEPTH_BUFFER_BIT))
gl.glDisable(gl.GL_AUTO_NORMAL)
gl.glDisable(gl.GL_LIGHTING)
gl.glDisable(gl.GL_LIGHT0)
gl.glDisable(gl.GL_BLEND)
gl.glDisable(gl.GL_FOG)
for p=1,#mab.parties do
gl.glPushMatrix()
gl.glTranslated(mab.parties[p].pos.x,
mab.parties[p].pos.z,
mab.parties[p].pos.y)
gl.glRotatef(mab.parties[p].rot, 0, 1, 0)
local bit=require "bit";
--encode the party id as follows
--(p & 0xff000000 >> 24,
-- p & 0xff0000 >> 16,
-- p & 0xff00 >> 8,
-- p & 0xff)
--p= p*7000000
gl.glColor4ub(bit.rshift(bit.band(p,0xff000000),8*3),
bit.rshift(bit.band(p,0x00ff0000),8*2),
bit.rshift(bit.band(p,0x0000ff00),8),
bit.band(p,0x000000ff));
quad = glu.gluNewQuadric()
glu.gluSphere(
quad,
1,
4,
4
);
gl.glPopMatrix()
end
gl.glReadPixels( winX[0], winY[0], 1,1, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, pickId );
--print(pickId[0],pickId[1],pickId[2],pickId[3])
pickId_dec=bit.bor(bit.lshift(pickId[0],8*3),
bit.lshift(pickId[1],8*2),
bit.lshift(pickId[2],8),
pickId[3]);
--print(pickId_dec)
pickId=pickId_dec
gl.glEnable(gl.GL_LIGHTING)
gl.glEnable(gl.GL_FOG)
gl.glVertex2s(1,1); -- /gDEBugger GL/ backbuffer breakpoint, if you're wondering :)
if mab.parties[pickId] then
tty=mab.parties[pickId].name
picked=pickId
mouse.rclick=true
--@ Avoid bumpy picks
local scrX=ffi.new("double[1]");
local scrY=ffi.new("double[1]")
local scrZ=ffi.new("double[1]");
local modelview=ffi.new("double[16]");
gl.glGetDoublev( gl.GL_MODELVIEW_MATRIX, modelview );
local projection=ffi.new("double[16]");
gl.glGetDoublev( gl.GL_PROJECTION_MATRIX, projection );
local viewport=ffi.new("int[4]");
gl.glGetIntegerv( gl.GL_VIEWPORT, viewport );
glu.gluProject(mab.parties[picked].pos.x,
mab.parties[picked].pos.z,
mab.parties[picked].pos.y, modelview, projection, viewport, scrX, scrY, scrZ);
pickoffst={
mouse.x -scrX[0],
(lujgl.height-mouse.y)-scrY[0]
}
--lujgl.glfw.glfwSwapBuffers()
else
tty="unknown"
picked=0
end
print("dragging "..tty)
elseif k==1 and picked ~= 0 then
print("dropped "..(tty or "bug"))
mouse.rclick=false
pickoffst={0,0}
end
if k==0 then mouse.lclick=down end
if k==2 then mouse.mclick=down end
mouse.x=x
mouse.y=y
elseif ev=="wheel" then -- wheel movement
mouse.wheel_locl=arg[1]
mouse.wheel_absl=arg[2]
if mouse.wheel_absl then --mab scroll like effect
py=py+mouse.wheel_locl * math.max(abs(py)/30, 0.1) * (key[289] and 3 or 1) -- swy: make zoom-in-out scroll movement x3 faster when Ctrl is held, also, scale up the scroll wheel effect as we get far higher and higher over the map; reduce medical bills. with the max(.01) we ensure that we never get stuck at zero
--rx=rx+mouse.wheel_locl
--rang=mouse.wheel_absl
end
elseif ev=="close" then --closing down
gl.glDeleteTextures(1,ffi.new("const unsigned int[1]",fontdds)) -- get rid of the bitmap font and unload the
if mapmesh then gl.glDeleteLists(mapmesh,1) end -- map mesh. that fixes those ugly GPU memory leaks
end
end
)
--@ start the loop already
lujgl.mainLoop()