home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Learn 3D Graphics Programming on the PC
/
Learn_3D_Graphics_Programming_on_the_PC_Ferraro.iso
/
rwwin
/
editmat.c_
/
editmat.bin
Wrap
Text File
|
1995-11-14
|
30KB
|
900 lines
/**********************************************************************
*
* File : editmat.c
*
* Abstract : RenderWare paint demo. Material editor module
*
**********************************************************************
*
* This file is a product of Criterion Software Ltd.
*
* This file is provided as is with no warranties of any kind and is
* provided without any obligation on Criterion Software Ltd. or
* Canon Inc. to assist in its use or modification.
*
* Criterion Software Ltd. will not, under any
* circumstances, be liable for any lost revenue or other damages arising
* from the use of this file.
*
* Copyright (c) 1995 Criterion Software Ltd.
* All Rights Reserved.
*
* RenderWare is a trademark of Canon Inc.
*
************************************************************************/
#ifdef __WINDOWS_386__
#define INCLUDE_SHELLAPI_H
#define OEMRESOURCE
#include <windows.h>
#else /* __WINDOWS_386__ */
#include <windows.h>
#include <shellapi.h>
#endif /* __WINDOWS_386__ */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <dos.h>
#include <rwlib.h>
#include "meditres.h"
#include "editmat.h"
#define CAMERA_BACK CREAL(-13.0)
#define SPACING CREAL(2.5)
#define ERROR_DIALOG_TITLE "RenderWare Material Editor Error"
typedef struct
{
RwReal Amb, Diff, Spec;
RwRGBColor Col;
RwTexture *Tex;
int Geom, Light;
RwTextureModes TextureModes;
UINT ChangesMessage;
HWND User; /* this window gets sent the above message (if not null) */
int Flags; /* currently unused - send 0 */
unsigned short int Changes;
RwReal Opacity;
}
MAT_DATA;
static MAT_DATA CurMat;
static HWND MatHnd;
static RwCamera *pCamera, *pComboCam;
static RwScene *pScene, *pComboScene;
static RwClump *pClump, *pBackClump;
static RwClump *pComboClump;
static RwMaterial *Material;
static int CurrentTexture;
static long Current = -1, Checksum;
LRESULT CALLBACK PosDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
static LONG CreateMsg(HWND hWnd);
static void ScrollMsg(HWND hDlg, short ScrollCode, short Pos, HWND ScrollBar);
static void ScrollTextures(HWND hDlg, short ScrollCode, short Pos, HWND ScrollBar);
static void UpdateClump(HWND hWnd, int Send);
static void AddToTextureList(RwTexture * pTex, RwRGBColor * col);
static void UpdatePolygon(RwPolygon3d * Poly);
static void SetScrollBar(int IdScroll, int IdValue, RwReal Value);
static void RebuildTextureScene(void);
static void DlgCommandMsg(HWND hWnd, WPARAM wParam, LPARAM lParam);
static void UpdateTextureBlob(void);
void
SetupControls(void)
{
int Id;
CurMat.Changes = (unsigned short int) -1;
if (Material != NULL)
{
CurMat.Amb = RwGetMaterialAmbient(Material);
CurMat.Diff = RwGetMaterialDiffuse(Material);
CurMat.Spec = RwGetMaterialSpecular(Material);
RwGetMaterialColor(Material, &CurMat.Col);
CurMat.Geom = RwGetMaterialGeometrySampling(Material);
CurMat.Light = RwGetMaterialLightSampling(Material);
CurMat.Opacity = RwGetMaterialOpacity(Material);
CurMat.Tex = RwGetMaterialTexture(Material);
CurMat.TextureModes = RwGetMaterialTextureModes(Material);
}
switch (CurMat.Geom)
{
case rwPOINTCLOUD:
Id = MAT_POINTCLOUD;
break;
case rwWIREFRAME:
Id = MAT_WIREFRAME;
break;
default:
case rwSOLID:
Id = MAT_SOLID;
break;
}
CheckRadioButton(MatHnd, MAT_POINTCLOUD, MAT_SOLID, Id);
switch (CurMat.Light)
{
case rwFACET:
Id = MAT_FLATSHADE;
break;
default:
case rwVERTEX:
Id = MAT_SMOOTHSHADE;
break;
}
SendMessage(GetDlgItem(MatHnd, MAT_LIT), BM_SETCHECK, (int) (CurMat.TextureModes & rwLIT), 0L);
CheckRadioButton(MatHnd, MAT_FLATSHADE, MAT_SMOOTHSHADE, Id);
SetScrollBar(MAT_AMBIENTSCROLL, MAT_AMBIENTVALUE, CurMat.Amb);
SetScrollBar(MAT_DIFFUSESCROLL, MAT_DIFFUSEVALUE, CurMat.Diff);
SetScrollBar(MAT_SPECUALRSCROLL, MAT_SPECULARVALUE, CurMat.Spec);
SetScrollBar(MAT_OPACITYSCROLL, MAT_OPACITYVALUE, CurMat.Opacity);
SetScrollBar(MAT_REDSCROLL, MAT_REDVALUE, CurMat.Col.r);
SetScrollBar(MAT_GREENSCROLL, MAT_GREENVALUE, CurMat.Col.g);
SetScrollBar(MAT_BLUESCROLL, MAT_BLUEVALUE, CurMat.Col.b);
RebuildTextureScene();
UpdateClump(MatHnd, FALSE);
ShowWindow(MatHnd, SW_SHOW);
}
HWND FAR PASCAL
MaterialEditor(RwMaterial *UseMaterial, HINSTANCE Instance, HWND hOwner, HWND User, UINT Message)
{
HMENU hMenu;
Material = UseMaterial;
CurMat.User = User;
CurMat.ChangesMessage = Message;
if (MatHnd == NULL)
{
MatHnd = CreateDialog(Instance, "DIALOG_1", hOwner, (DLGPROC) MakeProcInstance((FARPROC) PosDlgProc, Instance));
if (MatHnd == NULL)
{
MessageBox(hOwner, "Internal Operating System Error",
ERROR_DIALOG_TITLE, MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL);
return NULL;
}
hMenu = GetSystemMenu(MatHnd, FALSE);
DeleteMenu(hMenu, 4, MF_BYPOSITION);
DeleteMenu(hMenu, 2, MF_BYPOSITION);
}
else
{
if (pCamera == NULL)
{
/* We should check for error's here */
CreateMsg(MatHnd);
}
SetupControls();
}
return (HWND) MatHnd;
}
static void
SetScrollBar(int IdScroll, int IdValue, RwReal Value)
{
char Buf[10];
SetScrollRange(GetDlgItem(MatHnd, IdScroll), SB_CTL, 0, 100, FALSE);
SetScrollPos(GetDlgItem(MatHnd, IdScroll), SB_CTL, (int) REAL2INT(RMul(RAdd(Value, CREAL(0.001)), CREAL(100.0))), TRUE);
sprintf(Buf, "%d.%2.2d", REAL2INT(Value), REAL2INT(RMul(Value, CREAL(100.0))) % 100);
SetWindowText(GetDlgItem(MatHnd, IdValue), Buf);
}
LRESULT CALLBACK
PosDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
DRAWITEMSTRUCT far *pDis;
COLORREF Colour;
static HBRUSH RedBrush, GreenBrush, BlueBrush;
HBRUSH Brush;
HDC hDC;
PAINTSTRUCT ps;
HDROP Drop;
char Path[_MAX_PATH];
int i;
switch (msg)
{
case WM_DROPFILES:
Drop = (HDROP) wParam;
for (i = DragQueryFile(Drop, (UINT) - 1, Path, _MAX_PATH) - 1; i >= 0; --i)
{
DragQueryFile(Drop, (UINT) i, Path, _MAX_PATH);
RwGetNamedTexture(Path);
RebuildTextureScene();
}
DragFinish(Drop);
break;
case WM_PAINT:
if (IsIconic(hWnd))
{
hDC = BeginPaint(hWnd, &ps);
RwVCMoveCamera(pCamera, CREAL(2.85), CREAL(-2.85), CREAL(-14.0));
RwInvalidateCameraViewport(pCamera);
RwBeginCameraUpdate(pCamera, (void *)(DWORD)hWnd);
RwClearCameraViewport(pCamera);
RwRenderScene(pScene);
RwEndCameraUpdate(pCamera);
RwShowCameraImage(pCamera, (void *)(DWORD)hDC);
RwVCMoveCamera(pCamera, CREAL(-2.85), CREAL(2.85), CREAL(14.0));
EndPaint(hWnd, &ps);
}
break;
case WM_INITDIALOG:
MatHnd = hWnd;
RedBrush = CreateSolidBrush(RGB(255, 0, 0));
GreenBrush = CreateSolidBrush(RGB(0, 255, 0));
BlueBrush = CreateSolidBrush(RGB(0, 0, 255));
DragAcceptFiles(hWnd, TRUE);
if (CreateMsg(hWnd) == -1)
return 0;
SetupControls();
return MAT_TEXTURESCROLL;
case WM_ACTIVATE: /* keep texture list up to date in case app has loaded more */
if (wParam != WA_INACTIVE)
{
RebuildTextureScene();
return 0;
}
return 1;
case WM_DRAWITEM:
#ifdef __WINDOWS_386__
pDis = (DRAWITEMSTRUCT FAR *) MK_FP32((void *) lParam);
#else /* __WINDOWS_386__ */
pDis = (DRAWITEMSTRUCT FAR *) lParam;
#endif /* __WINDOWS_386__ */
if ((pDis->itemAction == ODA_DRAWENTIRE) && (wParam == MAT_BUTTON))
{
RwForAllPolygonsInClump(pClump, (RwPolygon3dFuncVoid) UpdatePolygon);
UpdateTextureBlob();
CurMat.Changes = 0;
RwInvalidateCameraViewport(pCamera);
RwBeginCameraUpdate(pCamera, (void *)(DWORD)hWnd);
RwClearCameraViewport(pCamera);
RwRenderScene(pScene);
RwEndCameraUpdate(pCamera);
RwShowCameraImage(pCamera, (void *)(DWORD)pDis->hDC);
return 1;
}
if ((pDis->itemAction == ODA_DRAWENTIRE) && (wParam == MAT_TEXTUREBUTTON))
{
RwInvalidateCameraViewport(pComboCam);
RwBeginCameraUpdate(pComboCam, (void *)(DWORD)hWnd);
RwClearCameraViewport(pComboCam);
RwRenderScene(pComboScene);
RwEndCameraUpdate(pComboCam);
RwShowCameraImage(pComboCam, (void *)(DWORD)pDis->hDC);
return 1;
}
break;
case WM_COMMAND:
DlgCommandMsg(hWnd, wParam, lParam);
return 0;
case WM_HSCROLL:
{
short ScrollCode;
short Pos;
HWND ScrollBar;
#ifdef WIN32
ScrollCode = (short) LOWORD(wParam);
Pos = (short) HIWORD(wParam);
ScrollBar = (HWND) lParam;
#else
ScrollCode = (short) wParam;
Pos = (short) LOWORD(lParam);
ScrollBar = (HWND) HIWORD(lParam);
#endif
if (GetDlgCtrlID(ScrollBar) != MAT_TEXTURESCROLL)
ScrollMsg(hWnd, ScrollCode, Pos, ScrollBar);
else
ScrollTextures(hWnd, ScrollCode, Pos, ScrollBar);
return 0;
}
case WM_DESTROY:
DeleteObject(RedBrush);
DeleteObject(GreenBrush);
DeleteObject(BlueBrush);
case WM_CLOSE:
if (pCamera != NULL)
{
ShowWindow(MatHnd, SW_HIDE);
RwDestroyCamera(pCamera);
RwDestroyCamera(pComboCam);
pCamera = pComboCam = NULL;
RwDestroyScene(pScene);
RwDestroyScene(pComboScene);
pScene = pComboScene = NULL;
pClump = pComboClump = NULL;
Current = -1;
CurrentTexture = 0;
}
SendMessage(CurMat.User, CurMat.ChangesMessage, 0, (LPARAM) NULL);
break;
#ifdef WIN32
case WM_CTLCOLORSCROLLBAR:
Brush = NULL;
switch (GetDlgCtrlID((HWND) lParam))
{
#else
case WM_CTLCOLOR:
Brush = NULL;
switch (GetDlgCtrlID(LOWORD(lParam)))
{
#endif
case MAT_REDSCROLL:
case MAT_REDVALUE:
Colour = RGB(REAL2INT(RMul(CurMat.Col.r, CREAL(255.0))), 0, 0);
Brush = RedBrush;
break;
case MAT_GREENSCROLL:
case MAT_GREENVALUE:
Colour = RGB(0, REAL2INT(RMul(CurMat.Col.g, CREAL(255.0))), 0);
Brush = GreenBrush;
break;
case MAT_BLUESCROLL:
case MAT_BLUEVALUE:
Colour = RGB(0, 0, REAL2INT(RMul(CurMat.Col.b, CREAL(255.0))));
Brush = BlueBrush;
break;
case MAT_REDTEXT:
Colour = RGB(255, 0, 0);
Brush = RedBrush;
break;
case MAT_GREENTEXT:
Colour = RGB(0, 255, 0);
Brush = GreenBrush;
break;
case MAT_BLUETEXT:
Colour = RGB(0, 0, 255);
Brush = BlueBrush;
break;
}
if (Brush != NULL)
{
SetBkColor((HDC) wParam, GetSysColor(COLOR_WINDOW));
SetTextColor((HDC) wParam, Colour);
return Brush;
}
break;
}
return 0;
}
void
SetBackClump(RwPolygon3d * Poly)
{
static RwRGBColor Col;
RwSetPolygonColorStruct(Poly, &Col);
RwSetPolygonGeometrySampling(Poly, rwSOLID);
RwSetPolygonLightSampling(Poly, rwFACET);
RwSetPolygonAmbient(Poly, CREAL(0.1));
RwSetPolygonDiffuse(Poly, CREAL(0.3));
RwSetPolygonSpecular(Poly, CREAL(0.6));
RwSetPolygonOpacity(Poly, CREAL(1.0));
RwSetPolygonTexture(Poly, NULL);
}
static LONG
CreateMsg(HWND hWnd)
{
HDC hDC;
DWORD DialogUnits;
DialogUnits = GetDialogBaseUnits();
RwModelBegin();
RwClumpBegin();
RwTransformBegin();
RwRotateCTM(CREAL(1.0), CREAL(0.0), CREAL(0.0), CREAL(90.0));
RwHemisphere(CREAL(0.6), 6);
RwTransformEnd();
if (RwClumpEnd(&pClump) == NULL)
{
MessageBox(hWnd, "Error creating the RenderWare clump",
ERROR_DIALOG_TITLE, MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL);
return -1L;
}
RwModelEnd();
RwSetClumpHints(pClump, 0L);
RwModelBegin();
RwClumpBegin();
RwTransformBegin();
RwRotateCTM(CREAL(1.0), CREAL(1.0), CREAL(0.0), CREAL(45.0));
RwSphere(CREAL(0.3), 0);
RwTransformEnd();
if (RwClumpEnd(&pBackClump) == NULL)
{
MessageBox(hWnd, "Error creating the RenderWare clump",
ERROR_DIALOG_TITLE, MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL);
return -1L;
}
RwModelEnd();
RwSetClumpHints(pBackClump, rwCONTAINER);
hDC = GetDC(MatHnd);
pCamera = RwCreateCamera(256, 256, NULL);
ReleaseDC(MatHnd, hDC);
if (pCamera == NULL)
{
if (RwGetError() == E_RW_NOMEM)
{
MessageBox(hWnd, "Insufficient memory to create the RenderWare camera",
ERROR_DIALOG_TITLE, MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL);
}
else
{
MessageBox(hWnd, "Error creating the RenderWare camera",
ERROR_DIALOG_TITLE, MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL);
}
return -1L;
}
RwSetCameraViewwindow(pCamera, CREAL(0.2), CREAL(0.2));
RwSetCameraViewport(pCamera, 0, 0, (90 * LOWORD(DialogUnits)) / 4, (90 * HIWORD(DialogUnits)) / 8);
RwRevolveCamera(pCamera, CREAL(180.0));
RwBeginCameraUpdate(pCamera, (void *)(DWORD)hWnd);
RwSetCameraBackColor(pCamera, CREAL(0.5), CREAL(0.5), CREAL(0.5));
RwClearCameraViewport(pCamera);
RwEndCameraUpdate(pCamera);
pScene = RwCreateScene();
RwSphericalTexturizeClump(pClump);
RwAddLightToScene(pScene, RwCreateLight(rwPOINT, CREAL(-1.0), CREAL(-1.0), CREAL(1.0), CREAL(1.0)));
RwVCMoveCamera(pCamera, CREAL(0.0), CREAL(0.0), CREAL(-4.0));
RwAddClumpToScene(pScene, pClump);
RwAddClumpToScene(pScene, pBackClump);
RwForAllPolygonsInClump(pBackClump, (RwPolygon3dFuncVoid) SetBackClump);
hDC = GetDC(MatHnd);
pComboCam = RwCreateCamera(max((144 * LOWORD(DialogUnits)) / 4, 256), 256, NULL);
ReleaseDC(MatHnd, hDC);
if (pComboCam == NULL)
{
if (RwGetError() == E_RW_NOMEM)
{
MessageBox(hWnd, "Insufficient memory to create the RenderWare camera",
ERROR_DIALOG_TITLE, MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL);
}
else
{
MessageBox(hWnd, "Error creating the RenderWare camera",
ERROR_DIALOG_TITLE, MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL);
}
return -1L;
}
RwSetCameraViewport(pComboCam, 0, 0, (144 * LOWORD(DialogUnits)) / 4, (32 * HIWORD(DialogUnits)) / 8);
RwBeginCameraUpdate(pComboCam, (void *)(DWORD)hWnd);
RwSetCameraBackColor(pComboCam, CREAL(0.5), CREAL(0.5), CREAL(0.5));
RwSetCameraViewwindow(pComboCam, CREAL(0.4), RDiv(RDiv(CREAL(32.0), CREAL(72.0)), CREAL(5.0)));
RwClearCameraViewport(pComboCam);
RwEndCameraUpdate(pComboCam);
RwVCMoveCamera(pComboCam, CREAL(0.2), CREAL(0.0), CAMERA_BACK);
ShowWindow(MatHnd, SW_SHOW);
return 1;
}
static void
DlgCommandMsg(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
POINT Where;
RECT Rect;
RwPickRecord Pick;
if (HIWORD(lParam) == BN_CLICKED)
{
if (wParam == MAT_TEXTUREBUTTON)
{
GetCursorPos(&Where);
GetWindowRect(GetDlgItem(hWnd, MAT_TEXTUREBUTTON), &Rect);
RwPickScene(pComboScene, Where.x - Rect.left, Where.y - Rect.top, pComboCam, &Pick);
if (Pick.type == rwPICKCLUMP)
{
CurMat.Changes |= MAT_TEXTURE_CHANGED;
CurMat.Tex = RwGetPolygonTexture(Pick.object.clump.polygon);
UpdateClump(MatHnd, TRUE);
}
return;
}
if (!IsDlgButtonChecked(hWnd, wParam) && (wParam != MAT_LIT))
return;
switch (wParam)
{
case MAT_POINTCLOUD:
CurMat.Geom = rwPOINTCLOUD;
CurMat.Changes |= MAT_GEOM_CHANGED;
break;
case MAT_WIREFRAME:
CurMat.Geom = rwWIREFRAME;
CurMat.Changes |= MAT_GEOM_CHANGED;
break;
case MAT_SOLID:
CurMat.Geom = rwSOLID;
CurMat.Changes |= MAT_GEOM_CHANGED;
break;
case MAT_LIT:
if (SendMessage(GetDlgItem(MatHnd, MAT_LIT), BM_GETCHECK, 0, 0L) != 0)
CurMat.TextureModes |= rwLIT;
else
CurMat.TextureModes &= ~rwLIT;
CurMat.Changes |= MAT_TEXMODE_CHANGED;
break;
case MAT_FLATSHADE:
CurMat.Light = rwFACET;
CurMat.Changes |= MAT_LIGHT_CHANGED;
break;
default:
case MAT_SMOOTHSHADE:
CurMat.Light = rwVERTEX;
CurMat.Changes |= MAT_LIGHT_CHANGED;
break;
}
UpdateClump(hWnd, TRUE);
}
}
static void
ScrollTextures(HWND hDlg, short ScrollCode, short Pos, HWND ScrollBar)
{
int oldPos, newPos;
HWND hScroll = GetDlgItem(hDlg, MAT_TEXTURESCROLL);
oldPos = GetScrollPos(hScroll, SB_CTL);
newPos = oldPos;
switch (ScrollCode)
{
case SB_TOP:
newPos = 0;
break;
case SB_BOTTOM:
newPos = (int) RwGetNumNamedTextures() + 1;
break;
case SB_LINEDOWN:
newPos++;
break;
case SB_PAGEDOWN:
newPos += 4;
break;
case SB_LINEUP:
newPos--;
break;
case SB_PAGEUP:
newPos -= 4;
break;
case SB_THUMBPOSITION:
case SB_THUMBTRACK:
newPos = Pos;
break;
default:
return;
}
newPos = max(newPos, 0);
newPos = min(newPos, (int) RwGetNumNamedTextures() - 3);
if (newPos != oldPos)
{
RwVCMoveCamera(pComboCam, -RMul(INT2REAL(oldPos - newPos), SPACING), CREAL(0.0), CREAL(0.0));
InvalidateRect(GetDlgItem(hDlg, MAT_TEXTUREBUTTON), NULL, FALSE);
SetScrollPos(hScroll, SB_CTL, newPos, TRUE);
CurrentTexture = newPos;
}
}
static void
ScrollMsg(HWND hDlg, short ScrollCode, short Pos, HWND ScrollBar)
{
int oldPos, newPos, Page;
HWND hScroll, hValue;
RwReal Value, Factor;
char sText[80];
RwReal *Final;
switch (GetDlgCtrlID(ScrollBar))
{
case MAT_AMBIENTSCROLL:
hScroll = GetDlgItem(hDlg, MAT_AMBIENTSCROLL);
hValue = GetDlgItem(hDlg, MAT_AMBIENTVALUE);
Factor = CREAL(100);
Page = 10;
Final = &CurMat.Amb;
CurMat.Changes |= MAT_AMBIENT_CHANGED;
break;
case MAT_DIFFUSESCROLL:
hScroll = GetDlgItem(hDlg, MAT_DIFFUSESCROLL);
hValue = GetDlgItem(hDlg, MAT_DIFFUSEVALUE);
Factor = CREAL(100);
Page = 10;
Final = &CurMat.Diff;
CurMat.Changes |= MAT_DIFFUSE_CHANGED;
break;
case MAT_SPECUALRSCROLL:
hScroll = GetDlgItem(hDlg, MAT_SPECUALRSCROLL);
hValue = GetDlgItem(hDlg, MAT_SPECULARVALUE);
Factor = CREAL(100);
Page = 10;
Final = &CurMat.Spec;
CurMat.Changes |= MAT_SPECULAR_CHANGED;
break;
case MAT_OPACITYSCROLL:
hScroll = GetDlgItem(hDlg, MAT_OPACITYSCROLL);
hValue = GetDlgItem(hDlg, MAT_OPACITYVALUE);
Factor = CREAL(100);
Page = 10;
Final = &CurMat.Opacity;
CurMat.Changes |= MAT_OPACITY_CHANGED;
break;
case MAT_REDSCROLL:
hScroll = GetDlgItem(hDlg, MAT_REDSCROLL);
hValue = GetDlgItem(hDlg, MAT_REDVALUE);
Factor = CREAL(100);
Page = 10;
Final = &CurMat.Col.r;
CurMat.Changes |= MAT_COLOR_CHANGED;
break;
case MAT_GREENSCROLL:
hScroll = GetDlgItem(hDlg, MAT_GREENSCROLL);
hValue = GetDlgItem(hDlg, MAT_GREENVALUE);
Factor = CREAL(100);
Page = 10;
Final = &CurMat.Col.g;
CurMat.Changes |= MAT_COLOR_CHANGED;
break;
case MAT_BLUESCROLL:
hScroll = GetDlgItem(hDlg, MAT_BLUESCROLL);
hValue = GetDlgItem(hDlg, MAT_BLUEVALUE);
Factor = CREAL(100);
Page = 10;
Final = &CurMat.Col.b;
CurMat.Changes |= MAT_COLOR_CHANGED;
break;
default:
return;
}
SetScrollRange(hScroll, SB_CTL, 0, (int) REAL2INT(Factor), FALSE);
SetScrollPos(hScroll, SB_CTL, (int) REAL2INT(RMul(RAdd(*Final, CREAL(0.001)), Factor)), TRUE);
oldPos = GetScrollPos(hScroll, SB_CTL);
newPos = oldPos;
switch (ScrollCode)
{
case SB_TOP:
newPos = 0;
break;
case SB_BOTTOM:
newPos = (int) REAL2INT(Factor);
break;
case SB_LINEDOWN:
newPos += 5;
break;
case SB_PAGEDOWN:
newPos += Page;
break;
case SB_LINEUP:
newPos -= 5;
break;
case SB_PAGEUP:
newPos -= Page;
break;
case SB_THUMBPOSITION:
case SB_THUMBTRACK:
newPos = Pos;
break;
default:
return;
}
newPos = max(newPos, 0);
newPos = min(newPos, (int) REAL2INT(Factor));
if (newPos != oldPos)
{
Value = RDiv(INT2REAL(newPos), Factor);
SetScrollPos(hScroll, SB_CTL, newPos, TRUE);
sprintf(sText, "%d.%2.2d", REAL2INT(Value), REAL2INT(RMul(RSub(Value, INT2REAL(REAL2INT(Value))), CREAL(100))));
*Final = Value;
SetWindowText(hValue, sText);
UpdateClump(hDlg, TRUE);
}
}
static void
UpdatePolygon(RwPolygon3d * Poly)
{
if (CurMat.Changes & MAT_COLOR_CHANGED)
RwSetPolygonColorStruct(Poly, &CurMat.Col);
if (CurMat.Changes & MAT_GEOM_CHANGED)
RwSetPolygonGeometrySampling(Poly, CurMat.Geom);
if (CurMat.Changes & MAT_LIGHT_CHANGED)
RwSetPolygonLightSampling(Poly, CurMat.Light);
if (CurMat.Changes & MAT_AMBIENT_CHANGED)
RwSetPolygonAmbient(Poly, CurMat.Amb);
if (CurMat.Changes & MAT_DIFFUSE_CHANGED)
RwSetPolygonDiffuse(Poly, CurMat.Diff);
if (CurMat.Changes & MAT_SPECULAR_CHANGED)
RwSetPolygonSpecular(Poly, CurMat.Spec);
if (CurMat.Changes & MAT_OPACITY_CHANGED)
RwSetPolygonOpacity(Poly, CurMat.Opacity);
if (CurMat.Changes & MAT_TEXTURE_CHANGED)
RwSetPolygonTexture(Poly, CurMat.Tex);
if (CurMat.Changes & MAT_TEXMODE_CHANGED)
RwSetPolygonTextureModes(Poly, CurMat.TextureModes);
}
static void
UpdateClump(HWND hWnd, int Send)
{
InvalidateRect(GetDlgItem(hWnd, MAT_BUTTON), NULL, FALSE);
if (CurrentTexture == 0)
InvalidateRect(GetDlgItem(hWnd, MAT_TEXTUREBUTTON), NULL, FALSE);
if (Send && (CurMat.User != NULL))
{
if (Material != NULL)
{
RwSetMaterialAmbient(Material, CurMat.Amb);
RwSetMaterialDiffuse(Material, CurMat.Diff);
RwSetMaterialSpecular(Material, CurMat.Spec);
RwSetMaterialColorStruct(Material, &CurMat.Col);
RwSetMaterialLightSampling(Material, CurMat.Light);
RwSetMaterialGeometrySampling(Material, CurMat.Geom);
RwSetMaterialOpacity(Material, CurMat.Opacity);
RwSetMaterialTexture(Material, CurMat.Tex);
RwSetMaterialTextureModes(Material, CurMat.TextureModes);
}
SendMessage(CurMat.User, CurMat.ChangesMessage, CurMat.Changes, (LPARAM) Material);
}
}
static void
AddToTextureList(RwTexture * pTex, RwRGBColor * Col)
{
RwClump *pNewClump;
static RwReal x;
RwUV uv;
if (Col != NULL) /* i.e first one */
{
x = CREAL(-3.5);
RwModelBegin();
RwClumpBegin();
RwVertexExt(CREAL(-1.0), CREAL(-1.0), CREAL(0.0), NULL, NULL);
RwVertexExt(CREAL(1.0), CREAL(-1.0), CREAL(0.0), NULL, NULL);
RwVertexExt(CREAL(1.0), CREAL(1.0), CREAL(0.0), NULL, NULL);
RwVertexExt(CREAL(-1.0), CREAL(1.0), CREAL(0.0), NULL, NULL);
RwQuad(1, 2, 3, 4);
RwClumpEnd(&pNewClump);
pComboClump = pNewClump;
RwModelEnd();
RwForAllPolygonsInClumpReal(pNewClump, RwSetPolygonAmbient, CREAL(0.7));
UpdateTextureBlob();
}
else
{
RwModelBegin();
RwClumpBegin();
uv.u = CREAL(0.0);
uv.v = CREAL(1.0);
RwVertexExt(CREAL(-1.0), CREAL(-1.0), CREAL(0.0), &uv, NULL);
uv.u = CREAL(1.0);
uv.v = CREAL(1.0);
RwVertexExt(CREAL(1.0), CREAL(-1.0), CREAL(0.0), &uv, NULL);
uv.u = CREAL(1.0);
uv.v = CREAL(0.0);
RwVertexExt(CREAL(1.0), CREAL(1.0), CREAL(0.0), &uv, NULL);
uv.u = CREAL(0.0);
uv.v = CREAL(0.0);
RwVertexExt(CREAL(-1.0), CREAL(1.0), CREAL(0.0), &uv, NULL);
RwQuad(1, 2, 3, 4);
RwClumpEnd(&pNewClump);
RwModelEnd();
RwForAllPolygonsInClumpPointer(pNewClump, (RwPolygon3dFuncPointer) RwSetPolygonTexture, pTex);
RwForAllPolygonsInClumpInt(pNewClump, (RwPolygon3dFuncInt) RwAddTextureModeToPolygon, rwLIT);
RwForAllPolygonsInClumpReal(pNewClump, (RwPolygon3dFuncReal) RwSetPolygonAmbient, CREAL(0.5));
RwForAllPolygonsInClumpReal(pNewClump, (RwPolygon3dFuncReal) RwSetPolygonDiffuse, CREAL(0.2));
}
RwPushScratchMatrix();
RwTranslateMatrix(RwScratchMatrix(), x, CREAL(0.0), CREAL(0.0), rwREPLACE);
RwTransformClump(pNewClump, RwScratchMatrix(), rwPOSTCONCAT);
RwPopScratchMatrix();
x = RAdd(SPACING, x);
RwAddClumpToScene(pComboScene, pNewClump);
}
static void
UpdateTextureBlob(void)
{
RwForAllPolygonsInClumpPointer(pComboClump, (RwPolygon3dFuncPointer) RwSetPolygonColorStruct, &CurMat.Col);
}
static void
AddChecksum(RwTexture * pTex)
{
Checksum += (long) pTex;
}
static void
RebuildTextureScene(void)
{
int NumTex, OldPos;
Checksum = 0;
RwForAllNamedTextures((RwTextureFuncVoid) AddChecksum);
if ((Checksum != Current) && (pClump != NULL))
{
Current = Checksum;
NumTex = (int) RwGetNumNamedTextures();
if (pComboScene != NULL)
RwDestroyScene(pComboScene);
pComboScene = RwCreateScene();
RwAddLightToScene(pComboScene, RwCreateLight(rwPOINT, CREAL(2.0), CREAL(2.0), CREAL(3.0), CREAL(1.0)));
AddToTextureList(NULL, &CurMat.Col);
RwForAllNamedTexturesPointer((RwTextureFuncPointer) AddToTextureList, NULL);
if (NumTex >= 4)
{
SetScrollRange(GetDlgItem(MatHnd, MAT_TEXTURESCROLL), SB_CTL, 0, NumTex - 3, FALSE);
EnableWindow(GetDlgItem(MatHnd, MAT_TEXTURESCROLL), TRUE);
}
else
{
EnableWindow(GetDlgItem(MatHnd, MAT_TEXTURESCROLL), FALSE);
}
OldPos = CurrentTexture;
CurrentTexture = min(CurrentTexture, NumTex);
SetScrollPos(GetDlgItem(MatHnd, MAT_TEXTURESCROLL), SB_CTL, CurrentTexture, TRUE);
RwVCMoveCamera(pComboCam, -RMul(INT2REAL(CurrentTexture - OldPos), SPACING), CREAL(0.0), CREAL(0.0));
InvalidateRect(GetDlgItem(MatHnd, MAT_TEXTUREBUTTON), NULL, FALSE);
}
}