00001
00002 #include "revolt.h"
00003 #include "edfield.h"
00004 #include "main.h"
00005 #include "dx.h"
00006 #include "geom.h"
00007 #include "camera.h"
00008 #include "text.h"
00009 #include "input.h"
00010 #include "level.h"
00011 #include "model.h"
00012
00013
00014
00015 FILE_FIELD *CurrentField = NULL;
00016
00017 static long FileFieldNum;
00018 static FILE_FIELD *FileFields;
00019 static long FileFieldAxis, FileFieldAxisType;
00020 static long FileFieldSide, FileFieldRotType;
00021 static MODEL FileFieldModel[2];
00022 static long Picker, EnterFlag;
00023 static char EnterString[128];
00024
00025
00026
00027 static char *FileFieldTypeNames[] = {
00028 "Linear",
00029 "Orientation",
00030 "Velocity",
00031 "Spherical",
00032 };
00033
00034 static char MaxPicker[] = {
00035 2,
00036 2,
00037 1,
00038 2,
00039 };
00040
00041 static char *FileFieldRotNames[] = {
00042 "Box",
00043 "Dir",
00044 };
00045
00046 static char *FileFieldAxisNames[] = {
00047 "X Y",
00048 "X Z",
00049 "Z Y",
00050 "X",
00051 "Y",
00052 "Z",
00053 };
00054
00055 static char *FileFieldAxisTypeNames[] = {
00056 "Camera",
00057 "World",
00058 };
00059
00060 static unsigned short DrawFieldIndex[] = {
00061 1, 3, 7, 5,
00062 2, 0, 4, 6,
00063 4, 5, 7, 6,
00064 0, 2, 3, 1,
00065 3, 2, 6, 7,
00066 0, 1, 5, 4,
00067 };
00068
00069 static long DrawFieldCol[] = {
00070 0x80ff0000,
00071 0x8000ff00,
00072 0x800000ff,
00073 };
00074
00076
00078
00079 void InitFileFields(void)
00080 {
00081 FileFields = (FILE_FIELD*)malloc(sizeof(FILE_FIELD) * MAX_FILE_FIELDS);
00082 if (!FileFields)
00083 {
00084 Box(NULL, "Can't alloc memory for file fields!", MB_OK);
00085 QuitGame = TRUE;
00086 }
00087 }
00088
00090
00092
00093 void KillFileFields(void)
00094 {
00095 free(FileFields);
00096 }
00097
00099
00101
00102 void LoadFileFields(char *file)
00103 {
00104 long i;
00105 FILE *fp;
00106 FILE_FIELD ff;
00107
00108
00109
00110 fp = fopen(file, "rb");
00111
00112
00113
00114 if (!fp)
00115 {
00116 fp = fopen(file, "wb");
00117 if (!fp) return;
00118 i = 0;
00119 fwrite(&i, sizeof(i), 1, fp);
00120 fclose(fp);
00121 fp = fopen(file, "rb");
00122 if (!fp) return;
00123 }
00124
00125
00126
00127 fread(&FileFieldNum, sizeof(FileFieldNum), 1, fp);
00128
00129 for (i = 0 ; i < FileFieldNum ; i++)
00130 {
00131
00132
00133
00134 fread(&ff, sizeof(ff), 1, fp);
00135
00136 VecMulScalar(&ff.Pos, EditScale);
00137 VecMulScalar((VEC*)ff.Size, EditScale);
00138
00139
00140
00141 FileFields[i] = ff;
00142 }
00143
00144
00145
00146 fclose(fp);
00147 }
00148
00150
00152
00153 void SaveFileFields(char *file)
00154 {
00155 long i;
00156 FILE *fp;
00157 FILE_FIELD ff;
00158 char bak[256];
00159
00160
00161
00162 memcpy(bak, file, strlen(file) - 3);
00163 wsprintf(bak + strlen(file) - 3, "fl-");
00164 remove(bak);
00165 rename(file, bak);
00166
00167
00168
00169 fp = fopen(file, "wb");
00170 if (!fp) return;
00171
00172
00173
00174 fwrite(&FileFieldNum, sizeof(FileFieldNum), 1, fp);
00175
00176
00177
00178 for (i = 0 ; i < FileFieldNum ; i++)
00179 {
00180
00181
00182
00183 ff = FileFields[i];
00184
00185
00186
00187 fwrite(&ff, sizeof(ff), 1, fp);
00188 }
00189
00190
00191
00192 Box("Saved Field File:", file, MB_OK);
00193 fclose(fp);
00194 }
00195
00197
00199
00200 FILE_FIELD *AllocFileField(void)
00201 {
00202
00203
00204
00205 if (FileFieldNum >= MAX_FILE_FIELDS)
00206 return NULL;
00207
00208
00209
00210 return &FileFields[FileFieldNum++];
00211 }
00212
00214
00216
00217 void FreeFileField(FILE_FIELD *field)
00218 {
00219 long idx, i;
00220
00221
00222
00223 idx = (long)(field - FileFields);
00224
00225
00226
00227 for (i = idx ; i < FileFieldNum - 1; i++)
00228 {
00229 FileFields[i] = FileFields[i + 1];
00230 }
00231
00232
00233
00234 FileFieldNum--;
00235 }
00236
00238
00240
00241 void DrawFields(void)
00242 {
00243 long i, j, k, col[4];
00244 float mul;
00245 FILE_FIELD *field;
00246 VEC v[8], vpos[8], pos[4];
00247 MAT mat;
00248 VEC vec;
00249 char buf[128];
00250
00251
00252
00253 WIREFRAME_OFF();
00254
00255
00256
00257 field = FileFields;
00258 for (i = 0 ; i < FileFieldNum ; i++, field++)
00259 {
00260
00261
00262
00263 if (field->Type == FILE_FIELD_TYPE_SPHERICAL)
00264 {
00265 ALPHA_ON();
00266 ALPHA_SRC(D3DBLEND_ONE);
00267 ALPHA_DEST(D3DBLEND_ONE);
00268 ZBUFFER_ON();
00269
00270 CopyMatrix(&IdentityMatrix, &mat);
00271 mul = field->RadStart / FileFieldModel[0].Radius;
00272 for (j = 0 ; j < 9 ; j++) mat.m[j] *= mul;
00273 DrawModel(&FileFieldModel[0], &mat, &field->Pos, MODEL_PLAIN);
00274
00275 CopyMatrix(&IdentityMatrix, &mat);
00276 mul = field->RadEnd / FileFieldModel[1].Radius;
00277 for (j = 0 ; j < 9 ; j++) mat.m[j] *= mul;
00278 DrawModel(&FileFieldModel[1], &mat, &field->Pos, MODEL_PLAIN);
00279
00280 FlushPolyBuckets();
00281 }
00282
00283
00284
00285 else
00286 {
00287
00288
00289
00290 ALPHA_OFF();
00291 ZBUFFER_ON();
00292
00293 vec.v[X] = field->Pos.v[X] + field->Dir.v[X] * 256;
00294 vec.v[Y] = field->Pos.v[Y] + field->Dir.v[Y] * 256;
00295 vec.v[Z] = field->Pos.v[Z] + field->Dir.v[Z] * 256;
00296
00297 DrawLine(&field->Pos, &vec, 0xffffff, 0xffffff);
00298
00299
00300
00301 SetVector(&v[0], -field->Size[X], -field->Size[Y], -field->Size[Z]);
00302 SetVector(&v[1], field->Size[X], -field->Size[Y], -field->Size[Z]);
00303 SetVector(&v[2], -field->Size[X], -field->Size[Y], field->Size[Z]);
00304 SetVector(&v[3], field->Size[X], -field->Size[Y], field->Size[Z]);
00305
00306 SetVector(&v[4], -field->Size[X], field->Size[Y], -field->Size[Z]);
00307 SetVector(&v[5], field->Size[X], field->Size[Y], -field->Size[Z]);
00308 SetVector(&v[6], -field->Size[X], field->Size[Y], field->Size[Z]);
00309 SetVector(&v[7], field->Size[X], field->Size[Y], field->Size[Z]);
00310
00311 for (j = 0 ; j < 8 ; j++)
00312 {
00313 RotTransVector(&field->Matrix, &field->Pos, &v[j], &vpos[j]);
00314 }
00315
00316
00317
00318 SET_TPAGE(-1);
00319 ALPHA_SRC(D3DBLEND_SRCALPHA);
00320 ALPHA_DEST(D3DBLEND_INVSRCALPHA);
00321 ALPHA_ON();
00322 ZBUFFER_ON();
00323
00324 for (j = 0 ; j < 6 ; j++)
00325 {
00326 for (k = 0 ; k < 4 ; k++)
00327 {
00328 pos[k] = vpos[DrawFieldIndex[j * 4 + k]];
00329
00330 if (CurrentField == field && j == FileFieldSide)
00331 col[k] = 0x80ffffff * (FrameCount & 1);
00332 else
00333 col[k] = DrawFieldCol[field->Type % FILE_FIELD_TYPE_MAX];
00334 }
00335
00336 DrawNearClipPolyTEX0(pos, col, 4);
00337 }
00338 }
00339
00340
00341
00342 wsprintf(buf, "%s", FileFieldTypeNames[field->Type]);
00343 RotTransVector(&ViewMatrix, &ViewTrans, &field->Pos, &vec);
00344 vec.v[X] -= 32 * strlen(FileFieldTypeNames[field->Type]);
00345 vec.v[Y] -= 64;
00346 if (vec.v[Z] > RenderSettings.NearClip)
00347 {
00348 ALPHA_OFF();
00349 ZBUFFER_OFF();
00350 DumpText3D(&vec, 64, 128, 0x00ffff, buf);
00351 }
00352
00353
00354
00355 if (CurrentField == field)
00356 {
00357 ALPHA_OFF();
00358 ZBUFFER_OFF();
00359
00360 if (FileFieldAxisType)
00361 CopyMatrix(&IdentityMatrix, &mat);
00362 else
00363 CopyMatrix(&CAM_MainCamera->WMatrix, &mat);
00364
00365 MatMulScalar(&mat, 2.0f);
00366 DrawAxis(&mat, &field->Pos);
00367 }
00368 }
00369
00370
00371
00372 WIREFRAME_ON();
00373 }
00374
00376
00378
00379 void DisplayFieldInfo(FILE_FIELD *field)
00380 {
00381 char buf[256];
00382
00383
00384
00385 wsprintf(buf, "%s", FileFieldTypeNames[field->Type]);
00386 DumpText(450, 0, 8, 16, 0xffff00, buf);
00387
00388
00389
00390 wsprintf(buf, "Axis %s - %s", FileFieldAxisNames[FileFieldAxis], FileFieldAxisTypeNames[FileFieldAxisType]);
00391 DumpText(450, 24, 8, 16, 0xff00ff, buf);
00392
00393
00394
00395 wsprintf(buf, "Rot %s", FileFieldRotNames[FileFieldRotType]);
00396 DumpText(450, 48, 8, 16, 0xff0000, buf);
00397
00398
00399
00400 if (field->Type != FILE_FIELD_TYPE_SPHERICAL)
00401 {
00402 if (EnterFlag && !Picker) wsprintf(buf, "Mag %s_", EnterString);
00403 else wsprintf(buf, "Mag %ld.%04ld", (long)field->Mag, (long)((field->Mag - (float)(long)field->Mag) * 10000));
00404 DumpText(450, 72, 8, 16, 0x00ffff, buf);
00405 }
00406
00407
00408
00409 if (field->Type == FILE_FIELD_TYPE_LINEAR || field->Type == FILE_FIELD_TYPE_ORIENTATION)
00410 {
00411 if (EnterFlag && Picker == 1) wsprintf(buf, "Damping %s_", EnterString);
00412 else wsprintf(buf, "Damping %ld.%04ld", (long)field->Damping, (long)((field->Damping - (float)(long)field->Damping) * 10000));
00413 DumpText(450, 96, 8, 16, 0x00ff00, buf);
00414 }
00415
00416
00417
00418 if (field->Type == FILE_FIELD_TYPE_SPHERICAL)
00419 {
00420 if (EnterFlag && !Picker) wsprintf(buf, "Grad Start %s_", EnterString);
00421 else wsprintf(buf, "Grad Start %ld.%04ld", (long)field->GradStart, (long)((field->GradStart - (float)(long)field->GradStart) * 10000));
00422 DumpText(450, 72, 8, 16, 0x00ffff, buf);
00423 }
00424
00425
00426
00427 if (field->Type == FILE_FIELD_TYPE_SPHERICAL)
00428 {
00429 if (EnterFlag && Picker == 1) wsprintf(buf, "Grad End %s_", EnterString);
00430 else wsprintf(buf, "Grad End %ld.%04ld", (long)field->GradEnd, (long)((field->GradEnd - (float)(long)field->GradEnd) * 10000));
00431 DumpText(450, 96, 8, 16, 0x00ff00, buf);
00432 }
00433
00434
00435
00436 DumpText(426, Picker * 24 + 72, 8, 16, 0xffffff, "->");
00437 }
00438
00440
00442
00443 void EditFields(void)
00444 {
00445 long i, j;
00446 VEC vec, vec2, r, u, l, r2, u2, l2;
00447 float z, sx, sy, rad, add, f;
00448 MAT mat, mat2;
00449 unsigned char c;
00450 FILE_FIELD *nfield, *field;
00451
00452
00453
00454 if (CAM_MainCamera->Type != CAM_EDIT)
00455 {
00456 CurrentField = NULL;
00457 EnterFlag = FALSE;
00458 return;
00459 }
00460
00461
00462
00463 if (EnterFlag)
00464 {
00465 if ((c = GetKeyPress()))
00466 {
00467 if (c == 8)
00468 {
00469 if (strlen(EnterString))
00470 {
00471 EnterString[strlen(EnterString) - 1] = 0;
00472 }
00473 }
00474 else if (c != 13 && c != 27)
00475 {
00476 if (strlen(EnterString) < 127)
00477 {
00478 EnterString[strlen(EnterString) + 1] = 0;
00479 EnterString[strlen(EnterString)] = c;
00480 }
00481 }
00482 if (c == 13)
00483 {
00484 f = (float)atof(EnterString);
00485 switch (Picker)
00486 {
00487 case 0:
00488 if (CurrentField->Type == FILE_FIELD_TYPE_SPHERICAL) CurrentField->GradStart = f;
00489 else CurrentField->Mag = f;
00490 break;
00491
00492 case 1:
00493 if (CurrentField->Type == FILE_FIELD_TYPE_SPHERICAL) CurrentField->GradEnd = f;
00494 else CurrentField->Damping = f;
00495 break;
00496 }
00497
00498 EnterFlag = FALSE;
00499 }
00500 }
00501 return;
00502 }
00503
00504
00505
00506 if (MouseRight)
00507 {
00508 RotMatrixZYX(&mat, (float)-Mouse.lY / 3072, -(float)Mouse.lX / 3072, 0);
00509 MulMatrix(&CAM_MainCamera->WMatrix, &mat, &mat2);
00510 CopyMatrix(&mat2, &CAM_MainCamera->WMatrix);
00511
00512 CAM_MainCamera->WMatrix.m[RY] = 0;
00513 NormalizeVector(&CAM_MainCamera->WMatrix.mv[X]);
00514 CrossProduct(&CAM_MainCamera->WMatrix.mv[Z], &CAM_MainCamera->WMatrix.mv[X], &CAM_MainCamera->WMatrix.mv[Y]);
00515 NormalizeVector(&CAM_MainCamera->WMatrix.mv[Y]);
00516 CrossProduct(&CAM_MainCamera->WMatrix.mv[X], &CAM_MainCamera->WMatrix.mv[Y], &CAM_MainCamera->WMatrix.mv[Z]);
00517 }
00518
00519
00520
00521 if (Keys[DIK_LCONTROL] && Keys[DIK_F4] && !LastKeys[DIK_F4])
00522 {
00523 SaveFileFields(GetLevelFilename("fld", FILENAME_MAKE_BODY | FILENAME_GAME_SETTINGS));
00524 }
00525
00526
00527
00528 if (Keys[DIK_RETURN] && !LastKeys[DIK_RETURN])
00529 {
00530 nfield = NULL;
00531 z = RenderSettings.FarClip;
00532
00533 field = FileFields;
00534 for (i = 0 ; i < FileFieldNum ; i++, field++)
00535 {
00536 for (j = 0 ; j < 2 ; j++)
00537 {
00538 RotTransVector(&ViewMatrix, &ViewTrans, &field->Pos, &vec);
00539
00540 if (vec.v[Z] < RenderSettings.NearClip || vec.v[Z] >= RenderSettings.FarClip) continue;
00541
00542 sx = vec.v[X] * RenderSettings.GeomPers / vec.v[Z] + REAL_SCREEN_XHALF;
00543 sy = vec.v[Y] * RenderSettings.GeomPers / vec.v[Z] + REAL_SCREEN_YHALF;
00544
00545 rad = 128 * RenderSettings.GeomPers / vec.v[Z];
00546
00547 if (MouseXpos > sx - rad && MouseXpos < sx + rad && MouseYpos > sy - rad && MouseYpos < sy + rad)
00548 {
00549 if (vec.v[Z] < z)
00550 {
00551 nfield = field;
00552 z = vec.v[Z];
00553 }
00554 }
00555 }
00556 }
00557 if (nfield)
00558 {
00559 CurrentField = nfield;
00560 return;
00561 }
00562 }
00563
00564
00565
00566 if (Keys[DIK_INSERT] && !LastKeys[DIK_INSERT])
00567 {
00568 if ((field = AllocFileField()))
00569 {
00570 vec.v[X] = 0;
00571 vec.v[Y] = 0;
00572 vec.v[Z] = 512;
00573 RotVector(&CAM_MainCamera->WMatrix, &vec, &vec2);
00574 AddVector(&CAM_MainCamera->WPos, &vec2, &field->Pos);
00575
00576 CopyMatrix(&IdentityMatrix, &field->Matrix);
00577
00578 field->Size[X] = field->Size[Y] = field->Size[Z] = 128;
00579 field->Type = FILE_FIELD_TYPE_LINEAR;
00580
00581 CopyVec(&UpVec, &field->Dir);
00582 field->Mag = 0;
00583 field->Damping = 0;
00584 field->RadStart = 64;
00585 field->RadEnd = 128;
00586 field->GradStart = 0;
00587 field->GradEnd = 0;
00588
00589 CurrentField = field;
00590 }
00591 }
00592
00593
00594
00595 if (!CurrentField) return;
00596
00597
00598
00599 if (Keys[DIK_RETURN] && !LastKeys[DIK_RETURN])
00600 {
00601 CurrentField = NULL;
00602 return;
00603 }
00604
00605
00606
00607 if (Keys[DIK_DELETE] && !LastKeys[DIK_DELETE])
00608 {
00609 FreeFileField(CurrentField);
00610 CurrentField = NULL;
00611 return;
00612 }
00613
00614
00615
00616 if (Keys[DIK_TAB] && !LastKeys[DIK_TAB])
00617 {
00618 if (Keys[DIK_LSHIFT]) FileFieldAxis--;
00619 else FileFieldAxis++;
00620 if (FileFieldAxis == -1) FileFieldAxis = 5;
00621 if (FileFieldAxis == 6) FileFieldAxis = 0;
00622 }
00623
00624
00625
00626 if (Keys[DIK_LALT] && !LastKeys[DIK_LALT])
00627 FileFieldAxisType ^= 1;
00628
00629
00630
00631 if (Keys[DIK_SPACE] && !LastKeys[DIK_SPACE])
00632 FileFieldSide = (FileFieldSide + 1) % 6;
00633
00634
00635
00636 if (Keys[DIK_NUMPADPERIOD] && !LastKeys[DIK_NUMPADPERIOD])
00637 FileFieldRotType ^= 1;
00638
00639
00640
00641 if (Keys[DIK_NUMPADMINUS] && !LastKeys[DIK_NUMPADMINUS] && CurrentField->Type)
00642 CurrentField->Type--;
00643 if (Keys[DIK_NUMPADPLUS] && !LastKeys[DIK_NUMPADPLUS] && CurrentField->Type < FILE_FIELD_TYPE_MAX - 1)
00644 CurrentField->Type++;
00645
00646
00647
00648 if (Keys[DIK_UP] && !LastKeys[DIK_UP] && Picker)
00649 Picker--;
00650
00651 if (Keys[DIK_DOWN] && !LastKeys[DIK_DOWN])
00652 Picker++;
00653
00654 if (Picker > MaxPicker[CurrentField->Type] - 1)
00655 Picker = MaxPicker[CurrentField->Type] - 1;
00656
00657
00658
00659 if (!EnterFlag && Keys[DIK_NUMPADENTER] && !LastKeys[DIK_NUMPADENTER])
00660 {
00661 EnterFlag = TRUE;
00662 EnterString[0] = 0;
00663 }
00664
00665
00666
00667 if (CurrentField->Type == FILE_FIELD_TYPE_SPHERICAL)
00668 {
00669 add = 0;
00670 if (Keys[DIK_NUMPADSTAR])
00671 add = 4 * TimeFactor;
00672 if (Keys[DIK_NUMPADSLASH])
00673 add = -4 * TimeFactor;
00674
00675 if (Keys[DIK_LSHIFT])
00676 {
00677 CurrentField->RadEnd += add;
00678 if (CurrentField->RadEnd > 4096) CurrentField->RadEnd = 4096;
00679 if (CurrentField->RadEnd < CurrentField->RadStart) CurrentField->RadEnd = CurrentField->RadStart;
00680 }
00681 else
00682 {
00683 CurrentField->RadStart += add;
00684 if (CurrentField->RadStart < 32) CurrentField->RadStart = 32;
00685 if (CurrentField->RadStart > CurrentField->RadEnd) CurrentField->RadStart = CurrentField->RadEnd;
00686 }
00687 }
00688
00689
00690
00691 else
00692 {
00693 add = 0;
00694 if (Keys[DIK_NUMPADSTAR])
00695 add = 4 * TimeFactor;
00696 if (Keys[DIK_NUMPADSLASH])
00697 add = -4 * TimeFactor;
00698
00699 if (Keys[DIK_LCONTROL]) add *= 4;
00700
00701 if (add)
00702 {
00703 if (Keys[DIK_LSHIFT])
00704 {
00705 CurrentField->Size[X] += add;
00706 if (CurrentField->Size[X] < 16) CurrentField->Size[X] = 16;
00707 CurrentField->Size[Y] += add;
00708 if (CurrentField->Size[Y] < 16) CurrentField->Size[Y] = 16;
00709 CurrentField->Size[Z] += add;
00710 if (CurrentField->Size[Z] < 16) CurrentField->Size[Z] = 16;
00711 }
00712 else
00713 {
00714 switch (FileFieldSide)
00715 {
00716 case 0:
00717 CurrentField->Size[X] += add;
00718 if (CurrentField->Size[X] < 16) CurrentField->Size[X] = 16;
00719 CurrentField->Pos.v[X] += CurrentField->Matrix.m[RX] * add;
00720 CurrentField->Pos.v[Y] += CurrentField->Matrix.m[RY] * add;
00721 CurrentField->Pos.v[Z] += CurrentField->Matrix.m[RZ] * add;
00722 break;
00723 case 1:
00724 CurrentField->Size[X] += add;
00725 if (CurrentField->Size[X] < 16) CurrentField->Size[X] = 16;
00726 CurrentField->Pos.v[X] -= CurrentField->Matrix.m[RX] * add;
00727 CurrentField->Pos.v[Y] -= CurrentField->Matrix.m[RY] * add;
00728 CurrentField->Pos.v[Z] -= CurrentField->Matrix.m[RZ] * add;
00729 break;
00730 case 2:
00731 CurrentField->Size[Y] += add;
00732 if (CurrentField->Size[Y] < 16) CurrentField->Size[Y] = 16;
00733 CurrentField->Pos.v[X] += CurrentField->Matrix.m[UX] * add;
00734 CurrentField->Pos.v[Y] += CurrentField->Matrix.m[UY] * add;
00735 CurrentField->Pos.v[Z] += CurrentField->Matrix.m[UZ] * add;
00736 break;
00737 case 3:
00738 CurrentField->Size[Y] += add;
00739 if (CurrentField->Size[Y] < 16) CurrentField->Size[Y] = 16;
00740 CurrentField->Pos.v[X] -= CurrentField->Matrix.m[UX] * add;
00741 CurrentField->Pos.v[Y] -= CurrentField->Matrix.m[UY] * add;
00742 CurrentField->Pos.v[Z] -= CurrentField->Matrix.m[UZ] * add;
00743 break;
00744 case 4:
00745 CurrentField->Size[Z] += add;
00746 if (CurrentField->Size[Z] < 16) CurrentField->Size[Z] = 16;
00747 CurrentField->Pos.v[X] += CurrentField->Matrix.m[LX] * add;
00748 CurrentField->Pos.v[Y] += CurrentField->Matrix.m[LY] * add;
00749 CurrentField->Pos.v[Z] += CurrentField->Matrix.m[LZ] * add;
00750 break;
00751 case 5:
00752 CurrentField->Size[Z] += add;
00753 if (CurrentField->Size[Z] < 16) CurrentField->Size[Z] = 16;
00754 CurrentField->Pos.v[X] -= CurrentField->Matrix.m[LX] * add;
00755 CurrentField->Pos.v[Y] -= CurrentField->Matrix.m[LY] * add;
00756 CurrentField->Pos.v[Z] -= CurrentField->Matrix.m[LZ] * add;
00757 break;
00758 }
00759 }
00760 }
00761 }
00762
00763
00764
00765 if (MouseLeft)
00766 {
00767 RotTransVector(&ViewMatrix, &ViewTrans, &CurrentField->Pos, &vec);
00768
00769 switch (FileFieldAxis)
00770 {
00771 case FILE_FIELD_AXIS_XY:
00772 vec.v[X] = MouseXrel * vec.v[Z] / RenderSettings.GeomPers + CameraEditXrel;
00773 vec.v[Y] = MouseYrel * vec.v[Z] / RenderSettings.GeomPers + CameraEditYrel;
00774 vec.v[Z] = CameraEditZrel;
00775 break;
00776 case FILE_FIELD_AXIS_XZ:
00777 vec.v[X] = MouseXrel * vec.v[Z] / RenderSettings.GeomPers + CameraEditXrel;
00778 vec.v[Y] = CameraEditYrel;
00779 vec.v[Z] = -MouseYrel * vec.v[Z] / RenderSettings.GeomPers + CameraEditZrel;
00780 break;
00781 case FILE_FIELD_AXIS_ZY:
00782 vec.v[X] = CameraEditXrel;
00783 vec.v[Y] = MouseYrel * vec.v[Z] / RenderSettings.GeomPers + CameraEditYrel;
00784 vec.v[Z] = MouseXrel * vec.v[Z] / RenderSettings.GeomPers + CameraEditZrel;
00785 break;
00786 case FILE_FIELD_AXIS_X:
00787 vec.v[X] = MouseXrel * vec.v[Z] / RenderSettings.GeomPers + CameraEditXrel;
00788 vec.v[Y] = CameraEditYrel;
00789 vec.v[Z] = CameraEditZrel;
00790 break;
00791 case FILE_FIELD_AXIS_Y:
00792 vec.v[X] = CameraEditXrel;
00793 vec.v[Y] = MouseYrel * vec.v[Z] / RenderSettings.GeomPers + CameraEditYrel;
00794 vec.v[Z] = CameraEditZrel;
00795 break;
00796 case FILE_FIELD_AXIS_Z:
00797 vec.v[X] = CameraEditXrel;
00798 vec.v[Y] = CameraEditYrel;
00799 vec.v[Z] = -MouseYrel * vec.v[Z] / RenderSettings.GeomPers + CameraEditZrel;
00800 break;
00801 }
00802
00803 if (FileFieldAxisType == 1)
00804 {
00805 SetVector(&vec2, vec.v[X], vec.v[Y], vec.v[Z]);
00806 }
00807 else
00808 {
00809 RotVector(&CAM_MainCamera->WMatrix, &vec, &vec2);
00810 }
00811
00812 CurrentField->Pos.v[X] += vec2.v[X];
00813 CurrentField->Pos.v[Y] += vec2.v[Y];
00814 CurrentField->Pos.v[Z] += vec2.v[Z];
00815 }
00816
00817
00818
00819 if (CurrentField->Type != FILE_FIELD_TYPE_SPHERICAL)
00820 {
00821 vec.v[X] = vec.v[Y] = vec.v[Z] = 0;
00822
00823 if (Keys[DIK_NUMPAD7]) vec.v[X] -= 0.005f;
00824 if (Keys[DIK_NUMPAD4]) vec.v[X] += 0.005f;
00825 if (Keys[DIK_NUMPAD8]) vec.v[Y] -= 0.005f;
00826 if (Keys[DIK_NUMPAD5]) vec.v[Y] += 0.005f;
00827 if (Keys[DIK_NUMPAD9]) vec.v[Z] -= 0.005f;
00828 if (Keys[DIK_NUMPAD6]) vec.v[Z] += 0.005f;
00829
00830 if (Keys[DIK_NUMPAD1] && !LastKeys[DIK_NUMPAD1]) vec.v[X] += 0.25f;
00831 if (Keys[DIK_NUMPAD2] && !LastKeys[DIK_NUMPAD2]) vec.v[Y] += 0.25f;
00832 if (Keys[DIK_NUMPAD3] && !LastKeys[DIK_NUMPAD3]) vec.v[Z] += 0.25f;
00833
00834 RotMatrixZYX(&mat, vec.v[X], vec.v[Y], vec.v[Z]);
00835
00836
00837
00838 if (FileFieldRotType)
00839 {
00840 if (Keys[DIK_NUMPAD0]) CopyVec(&UpVec, &CurrentField->Dir);
00841
00842 if (FileFieldAxisType)
00843 {
00844 RotVector(&mat, &CurrentField->Dir, &l);
00845 CopyVec(&l, &CurrentField->Dir);
00846 NormalizeVector(&CurrentField->Dir);
00847 }
00848 else if (vec.v[X] || vec.v[Y] || vec.v[Z])
00849 {
00850 RotVector(&ViewMatrix, &CurrentField->Dir, &l);
00851 RotVector(&mat, &l, &l2);
00852 RotVector(&CAM_MainCamera->WMatrix, &l2, &CurrentField->Dir);
00853 NormalizeVector(&CurrentField->Dir);
00854 }
00855 }
00856
00857
00858
00859 else
00860 {
00861 if (Keys[DIK_NUMPAD0]) CopyMatrix(&IdentityMatrix, &CurrentField->Matrix);
00862
00863 if (FileFieldAxisType)
00864 {
00865 MulMatrix(&mat, &CurrentField->Matrix, &mat2);
00866 CopyMatrix(&mat2, &CurrentField->Matrix);
00867 NormalizeMatrix(&CurrentField->Matrix);
00868 }
00869 else if (vec.v[X] || vec.v[Y] || vec.v[Z])
00870 {
00871 RotVector(&ViewMatrix, &CurrentField->Matrix.mv[X], &r);
00872 RotVector(&ViewMatrix, &CurrentField->Matrix.mv[Y], &u);
00873 RotVector(&ViewMatrix, &CurrentField->Matrix.mv[Z], &l);
00874
00875 RotVector(&mat, &r, &r2);
00876 RotVector(&mat, &u, &u2);
00877 RotVector(&mat, &l, &l2);
00878
00879 RotVector(&CAM_MainCamera->WMatrix, &r2, &CurrentField->Matrix.mv[X]);
00880 RotVector(&CAM_MainCamera->WMatrix, &u2, &CurrentField->Matrix.mv[Y]);
00881 RotVector(&CAM_MainCamera->WMatrix, &l2, &CurrentField->Matrix.mv[Z]);
00882
00883 NormalizeMatrix(&CurrentField->Matrix);
00884 }
00885 }
00886 }
00887 }
00888
00890
00892
00893 void LoadFileFieldModels(void)
00894 {
00895 LoadModel("edit\\field1.m", &FileFieldModel[0], -1, 1, LOADMODEL_FORCE_TPAGE, 100);
00896 LoadModel("edit\\field2.m", &FileFieldModel[1], -1, 1, LOADMODEL_FORCE_TPAGE, 100);
00897 }
00898
00900
00902
00903 void FreeFileFieldModels(void)
00904 {
00905 FreeModel(&FileFieldModel[0], 1);
00906 FreeModel(&FileFieldModel[1], 1);
00907 }