123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312 |
- /*
- ===========================================================================
- Copyright (C) 1997-2006 Id Software, Inc.
- This file is part of Quake 2 Tools source code.
- Quake 2 Tools source code is free software; you can redistribute it
- and/or modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of the License,
- or (at your option) any later version.
- Quake 2 Tools source code is distributed in the hope that it will be
- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with Quake 2 Tools source code; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- ===========================================================================
- */
- #include "texpaint.h"
- triangle_t *faces;
- int numfaces;
- int skinwidth, skinheight;
- int picwidth, picheight;
- int width, height;
- int iwidth, iheight;
- int width2, height2; // padded to ^2
- float tmcoords[10000][3][2];
- byte pic[1024*512];
- unsigned rgb[1024*512];
- float scale;
- float s_scale, t_scale;
- char filename[1024];
- char picfilename[1024];
- /*
- ================
- BoundFaces
- ================
- */
- vec3_t mins, maxs;
- void BoundFaces (void)
- {
- int i,j,k;
- triangle_t *pol;
- float v;
- for (i=0 ; i<3 ; i++)
- {
- mins[i] = 9999;
- maxs[i] = -9999;
- }
- for (i=0 ; i<numfaces ; i++)
- {
- pol = &faces[i];
- for (j=0 ; j<3 ; j++)
- for (k=0 ; k<3 ; k++)
- {
- v = pol->verts[j][k];
- if (v<mins[k])
- mins[k] = v;
- if (v>maxs[k])
- maxs[k] = v;
- }
- }
- for (i=0 ; i<3 ; i++)
- {
- mins[i] = floor(mins[i]);
- maxs[i] = ceil(maxs[i]);
- }
- width = maxs[0] - mins[0];
- height = maxs[2] - mins[2];
- printf ("width: %i height: %i\n",width, height);
- if (!skinwidth)
- { // old way
- scale = 8;
- if (width*scale >= 150)
- scale = 150.0 / width;
- if (height*scale >= 190)
- scale = 190.0 / height;
- s_scale = t_scale = scale;
- iwidth = ceil(width*scale) + 4;
- iheight = ceil(height*scale) + 4;
- }
- else
- { // new way
- s_scale = (skinwidth/2-4)/(float)width;
- t_scale = (skinheight-4)/(float)height;
- iwidth = skinwidth/2;
- iheight = skinheight;
- }
- printf ("scale: %f\n",scale);
- printf ("iwidth: %i iheight: %i\n",iwidth, iheight);
- }
- /*
- ============
- AddFace
- ============
- */
- void AddFace (int facenum, triangle_t *f)
- {
- vec3_t v1, v2, normal;
- int basex, basey;
- int i, j;
- int coords[3][2];
- //
- // determine which side to map the teture to
- //
- VectorSubtract (f->verts[0], f->verts[1], v1);
- VectorSubtract (f->verts[2], f->verts[1], v2);
- CrossProduct (v1, v2, normal);
- if (normal[1] > 0)
- basex = iwidth + 2;
- else
- basex = 2;
- basey = 2;
- for (i=0 ; i<3 ; i++)
- {
- coords[i][0] = Q_rint((f->verts[i][0] - mins[0])*s_scale + basex);
- coords[i][1] = Q_rint( (maxs[2] - f->verts[i][2])*t_scale + basey);
- tmcoords[facenum][i][0] = coords[i][0]/(float)width2;
- tmcoords[facenum][i][1] = coords[i][1]/(float)height2;
- }
- }
- void CalcTmCoords (void)
- {
- int j;
- BoundFaces ();
- for (j=0 ; j<numfaces ; j++)
- AddFace (j, &faces[j]);
- printf ("numfaces: %i\n",numfaces);
- }
- //===============================================================================
- #define MAX_NUM_ARGVS 32
- int argc;
- char *argv[MAX_NUM_ARGVS];
- /*
- ============
- ParseCommandLine
- ============
- */
- void ParseCommandLine (char *lpCmdLine)
- {
- argc = 1;
- argv[0] = "programname";
- while (*lpCmdLine && (argc < MAX_NUM_ARGVS))
- {
- while (*lpCmdLine && ((*lpCmdLine <= 32) || (*lpCmdLine > 126)))
- lpCmdLine++;
- if (*lpCmdLine)
- {
- argv[argc] = lpCmdLine;
- argc++;
- while (*lpCmdLine && ((*lpCmdLine > 32) && (*lpCmdLine <= 126)))
- lpCmdLine++;
- if (*lpCmdLine)
- {
- *lpCmdLine = 0;
- lpCmdLine++;
- }
- }
- }
- }
- /*
- =================
- LoadTriFile
- =================
- */
- void LoadTriFile (char *name)
- {
- strcpy (tri_filename, name);
- SetWindowText (camerawindow, tri_filename);
- LoadTriangleList (tri_filename, &faces, &numfaces);
- InvalidateRect (camerawindow, NULL, false);
- }
- /*
- ==================
- TimerProc
- ==================
- */
- int CALLBACK TimerProc(
- HWND hwnd, // handle of window for timer messages
- UINT uMsg, // WM_TIMER message
- UINT idEvent, // timer identifier
- DWORD dwTime // current system time
- )
- {
- static int counter;
- char name[1024];
- if (!skin_filename[0])
- return 0;
- if (!modified_past_autosave)
- {
- counter = 0;
- return 0;
- }
- counter++;
- if (counter < 3*5)
- return 0; // save every five minutes
- strcpy (name, skin_filename);
- StripExtension (name);
- strcat (name, "_autosave.lbm");
- Skin_SaveFile (name);
- modified_past_autosave = false;
- counter = 0;
- return 0;
- }
- /*
- ==================
- WinMain
- ==================
- */
- int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance
- ,LPSTR lpCmdLine, int nCmdShow)
- {
- MSG msg;
- HACCEL accelerators;
- main_instance = hInstance;
- ParseCommandLine (lpCmdLine);
- screen_width = GetSystemMetrics (SM_CXFULLSCREEN);
- screen_height = GetSystemMetrics (SM_CYFULLSCREEN);
- // hack for broken NT 4.0 dual screen
- if (screen_width > 2*screen_height)
- screen_width /= 2;
- accelerators = LoadAccelerators (hInstance
- , MAKEINTRESOURCE(IDR_ACCELERATOR1));
- if (!accelerators)
- Sys_Error ("LoadAccelerators failed");
- Main_Create (hInstance);
- WCam_Create (hInstance);
- WPal_Create (hInstance);
- WSkin_Create (hInstance);
- if (argc == 2)
- Skin_LoadFile (argv[1]);
- SetTimer ( mainwindow, 1, 1000*20, TimerProc );
- while (1)
- {
- if (!GetMessage (&msg, mainwindow, 0, 0))
- break;
- if (!TranslateAccelerator(mainwindow, accelerators, &msg) )
- {
- TranslateMessage (&msg);
- DispatchMessage (&msg);
- }
- }
- /* return success of application */
- return TRUE;
- }
|