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
|
/*
* Copyright (C) Volition, Inc. 1999. All rights reserved.
*
* All source code herein is the property of Volition, Inc. You may not sell
* or otherwise commercially exploit the source or things you created based on the
* source.
*
*/
#include "stdafx.h"
#include "FRED.h"
#include "Grid.h"
#include "mission/missiongrid.h"
#include "render/3d.h"
#include "object/object.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/**
* @brief Creates (or recreates) a grid from the two given unit vectors
*
* @param forward Vector that points forward
* @param right Vector that points to the right
*/
void GridOrient(vec3d *forward, vec3d *right);
BEGIN_MESSAGE_MAP(CGrid, CDialog)
//{{AFX_MSG_MAP(CGrid)
ON_BN_CLICKED(IDC_GRID_XY_PLANE, OnGridXyPlane)
ON_BN_CLICKED(IDC_GRID_XZ_PLANE, OnGridXzPlane)
ON_BN_CLICKED(IDC_GRID_YZ_PLANE, OnGridYzPlane)
ON_WM_CLOSE()
ON_WM_DESTROY()
ON_WM_KILLFOCUS()
ON_WM_VSCROLL()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL CGrid::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) {
return CDialog::Create(IDD, pParentWnd);
}
BOOL CGrid::Create() {
return CDialog::Create(CGrid::IDD);
}
CGrid::CGrid(CView* pView) {
m_pGView = pView;
}
CGrid::CGrid(CWnd* pParent /*=NULL*/)
: CDialog(CGrid::IDD, pParent) {
//{{AFX_DATA_INIT(CGrid)
m_GridSize = 0;
//}}AFX_DATA_INIT
m_pGView = NULL;
}
void CGrid::DoDataExchange(CDataExchange* pDX) {
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CGrid)
DDX_Text(pDX, IDC_GRID_SIZE, m_GridSize);
DDV_MinMaxUInt(pDX, m_GridSize, 2, 20);
//}}AFX_DATA_MAP
}
void CGrid::OnClose() {
DestroyWindow();
}
void CGrid::OnDestroy() {
UpdateData(TRUE);
CDialog::OnDestroy();
}
void CGrid::OnGridXyPlane() {
vec3d forward, right;
vm_vec_make(&forward, 0.0f, 1.0f, 0.0f);
vm_vec_make(&right, 1.0f, 0.0f, 0.0f);
GridOrient(&forward, &right);
}
void CGrid::OnGridXzPlane() {
vec3d forward, right;
vm_vec_make(&forward, 0.0f, 0.0f, 1.0f);
vm_vec_make(&right, 1.0f, 0.0f, 0.0f);
GridOrient(&forward, &right);
}
void CGrid::OnGridYzPlane() {
vec3d forward, right;
vm_vec_make(&forward, 0.0f, 1.0f, 0.0f);
vm_vec_make(&right, 0.0f, 0.0f, 1.0f);
GridOrient(&forward, &right);
}
BOOL CGrid::OnInitDialog() {
CDialog::OnInitDialog();
CSpinButtonCtrl* pSpin = (CSpinButtonCtrl*) GetDlgItem(IDC_SPIN_GRID_SIZE);
pSpin->SetRange(2, 20);
if ((m_GridSize < 2) || (m_GridSize > 20))
m_GridSize = The_grid->ncols / 5;
pSpin->SetPos(m_GridSize);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CGrid::OnKillFocus(CWnd* pNewWnd) {
CDialog::OnKillFocus(pNewWnd);
DestroyWindow();
}
void CGrid::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) {
CString strValue;
CSpinButtonCtrl* pSpin = (CSpinButtonCtrl*) GetDlgItem(IDC_SPIN_GRID_SIZE);
strValue.Format("%i", pSpin->GetPos());
pSpin->GetBuddy()->SetWindowText(strValue);
The_grid->nrows = pSpin->GetPos() * 5;
The_grid->ncols = The_grid->nrows;
modify_grid(The_grid);
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}
BOOL CGrid::DestroyWindow() {
// TODO: Add your specialized code here and/or call the base class
UpdateData(TRUE);
return CDialog::DestroyWindow();
}
void GridOrient(vec3d *forward, vec3d *right) {
vec3d center;
int nrows, ncols;
float square_size;
if (The_grid != NULL) {
center = The_grid->center;
nrows = The_grid->nrows;
ncols = The_grid->ncols;
square_size = The_grid->square_size;
} else {
vm_vec_make(¢er, 0.0f, 0.0f, 0.0f);
nrows = 20;
ncols = 20;
square_size = 2.0f;
}
The_grid = create_grid(The_grid, forward,
right,
¢er,
nrows, ncols,
square_size);
physics_init(&The_grid->physics);
}
|