multiple interpolation-types! \o/

This commit is contained in:
Erik Faye-Lund 2008-02-16 15:58:06 +00:00
parent e04c3aa08c
commit 2b1a79cc9c
9 changed files with 142 additions and 61 deletions

View File

@ -2,9 +2,9 @@
<VisualStudioProject <VisualStudioProject
ProjectType="Visual C++" ProjectType="Visual C++"
Version="8,00" Version="8,00"
Name="editor" Name="sync_editor"
ProjectGUID="{76B44BC8-8BB4-4B6E-B2FA-7738C9E7F80B}" ProjectGUID="{76B44BC8-8BB4-4B6E-B2FA-7738C9E7F80B}"
RootNamespace="synctracker2" RootNamespace="sync_editor"
Keyword="Win32Proj" Keyword="Win32Proj"
> >
<Platforms> <Platforms>
@ -229,6 +229,10 @@
RelativePath="..\sync\track.h" RelativePath="..\sync\track.h"
> >
</File> </File>
<File
RelativePath=".\trackview.h"
>
</File>
</Filter> </Filter>
<Filter <Filter
Name="Resource Files" Name="Resource Files"

View File

@ -21,7 +21,7 @@ public:
send(clientSocket, (char*)&track, sizeof(int), 0); send(clientSocket, (char*)&track, sizeof(int), 0);
send(clientSocket, (char*)&row, sizeof(int), 0); send(clientSocket, (char*)&row, sizeof(int), 0);
send(clientSocket, (char*)&key.value, sizeof(float), 0); send(clientSocket, (char*)&key.value, sizeof(float), 0);
// send(clientSocket, (char*)&key.lerp, 1, 0); send(clientSocket, (char*)&key.interpolationType, 1, 0);
} }
void sendDeleteKeyCommand(int track, int row) void sendDeleteKeyCommand(int track, int row)

View File

@ -4,7 +4,6 @@
#include <afxres.h> #include <afxres.h>
#include "resource.h" #include "resource.h"
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
#include <commctrl.h> #include <commctrl.h>
@ -26,10 +25,6 @@ static LRESULT CALLBACK setRowsDialogProc(HWND hDlg, UINT message, WPARAM wParam
{ {
switch (message) switch (message)
{ {
/* case WM_CHAR:
printf("char: %d %d\n", wParam, lParam);
break; */
case WM_INITDIALOG: case WM_INITDIALOG:
{ {
int *rows = (int*)lParam; int *rows = (int*)lParam;
@ -169,7 +164,6 @@ static LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA
break; break;
case WM_SETROWS: case WM_SETROWS:
printf("rows: %d\n", int(lParam));
trackView->setRows(int(lParam)); trackView->setRows(int(lParam));
break; break;
@ -183,7 +177,7 @@ static LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA
case ID_FILE_SAVE: case ID_FILE_SAVE:
case ID_FILE_SAVE_AS: case ID_FILE_SAVE_AS:
case ID_FILE_OPEN: case ID_FILE_OPEN:
MessageBox(trackViewWin, "Not implemented", NULL, MB_OK | MB_ICONERROR); MessageBox(trackViewWin, _T("Not implemented"), NULL, MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
break; break;
case ID_FILE_EXIT: PostQuitMessage(0); break; case ID_FILE_EXIT: PostQuitMessage(0); break;
@ -198,7 +192,7 @@ static LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA
HINSTANCE hInstance = GetModuleHandle(NULL); HINSTANCE hInstance = GetModuleHandle(NULL);
int rows = trackView->getRows(); int rows = trackView->getRows();
INT_PTR result = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_SETROWS), hwnd, (DLGPROC)setRowsDialogProc, (LPARAM)&rows); INT_PTR result = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_SETROWS), hwnd, (DLGPROC)setRowsDialogProc, (LPARAM)&rows);
if (FAILED(result)) MessageBox(NULL, _T("unable to create dialog box"), NULL, MB_OK); if (FAILED(result)) MessageBox(NULL, _T("unable to create dialog box"), NULL, MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
} }
break; break;
@ -207,7 +201,7 @@ static LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA
HINSTANCE hInstance = GetModuleHandle(NULL); HINSTANCE hInstance = GetModuleHandle(NULL);
int initialBias = 0; int initialBias = 0;
INT_PTR result = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_BIASSELECTION), hwnd, (DLGPROC)biasSelectionDialogProc, (LPARAM)&initialBias); INT_PTR result = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_BIASSELECTION), hwnd, (DLGPROC)biasSelectionDialogProc, (LPARAM)&initialBias);
if (FAILED(result)) MessageBox(NULL, _T("unable to create dialog box"), NULL, MB_OK); if (FAILED(result)) MessageBox(NULL, _T("unable to create dialog box"), NULL, MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
} }
break; break;
} }
@ -270,8 +264,9 @@ int _tmain(int argc, _TCHAR* argv[])
puts("binding..."); puts("binding...");
if (SOCKET_ERROR == bind( serverSocket, (struct sockaddr *)&sin, sizeof(sin))) if (SOCKET_ERROR == bind( serverSocket, (struct sockaddr *)&sin, sizeof(sin)))
{ {
MessageBox(NULL, "Could not start server", NULL, MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
fputs("Coult not start server", stderr); fputs("Coult not start server", stderr);
exit(1); return -1;
} }
puts("listening..."); puts("listening...");
@ -287,45 +282,13 @@ int _tmain(int argc, _TCHAR* argv[])
SyncEditData syncData; SyncEditData syncData;
syncData.clientSocket = INVALID_SOCKET; syncData.clientSocket = INVALID_SOCKET;
#if 0
SyncTrack &camXTrack = syncData.getTrack(_T("cam.x"));
SyncTrack &camXTrack2 = syncData.getTrack(_T("cam.x"));
camXTrack.setKeyFrame(1, 2.0f);
camXTrack.setKeyFrame(4, 3.0f);
printf("%p %p\n", &camXTrack, &camXTrack2);
SyncTrack &camYTrack = syncData.getTrack(_T("cam.y"));
SyncTrack &camZTrack = syncData.getTrack(_T("cam.z"));
/* for (int i = 0; i < 16; ++i)
{
TCHAR temp[256];
_sntprintf_s(temp, 256, _T("gen %02d"), i);
SyncTrack &temp2 = syncData.getTrack(temp);
} */
camXTrack.setKeyFrame(1, 2.0f);
camXTrack.setKeyFrame(4, 3.0f);
camYTrack.setKeyFrame(0, 100.0f);
camYTrack.setKeyFrame(8, 999.0f);
camYTrack.setKeyFrame(16, SyncTrack::KeyFrame(float(1E-5)));
for (int i = 0; i < 5 * 2; ++i)
{
float time = float(i) / 2;
printf("%f %d - %f\n", time, camXTrack.isKeyFrame(i), camXTrack.getValue(time));
}
#endif
ATOM mainClass = registerMainWindowClass(hInstance); ATOM mainClass = registerMainWindowClass(hInstance);
ATOM trackViewClass = registerTrackViewWindowClass(hInstance); ATOM trackViewClass = registerTrackViewWindowClass(hInstance);
if (!mainClass || !trackViewClass) if (!mainClass || !trackViewClass)
{ {
MessageBox(NULL, _T("Window Registration Failed!"), _T("Error!"), MB_ICONEXCLAMATION | MB_OK); MessageBox(NULL, _T("Window Registration Failed!"), _T("Error!"), MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
return 0; return -1;
} }
trackView = new TrackView(); trackView = new TrackView();
@ -344,8 +307,8 @@ int _tmain(int argc, _TCHAR* argv[])
if (NULL == hwnd) if (NULL == hwnd)
{ {
MessageBox(NULL, _T("Window Creation Failed!"), _T("Error!"), MB_ICONEXCLAMATION | MB_OK); MessageBox(NULL, _T("Window Creation Failed!"), _T("Error!"), MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND);
return 0; return -1;
} }
HACCEL accel = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR)); HACCEL accel = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR));

View File

@ -664,6 +664,44 @@ void TrackView::editEnterValue()
else MessageBeep(0); else MessageBeep(0);
} }
void TrackView::editToggleInterpolationType()
{
if (editTrack < int(syncData->getTrackCount()))
{
sync::Track &t = syncData->getTrack(editTrack);
// find key to modify
sync::Track::KeyFrameContainer::const_iterator upper = t.keyFrames.upper_bound(editRow);
// bounds check
if (upper == t.keyFrames.end())
{
MessageBeep(0);
return;
}
sync::Track::KeyFrameContainer::const_iterator lower = lower;
lower--;
// bounds check again
if (lower == t.keyFrames.end())
{
MessageBeep(0);
return;
}
sync::Track::KeyFrame newKey = lower->second;
// modify interpolation type
newKey.interpolationType = sync::Track::KeyFrame::InterpolationType(
(int(newKey.interpolationType) + 1) % sync::Track::KeyFrame::IT_COUNT
);
SyncEditData::Command *cmd = syncData->getSetKeyFrameCommand(editTrack, int(lower->first), newKey);
syncData->exec(cmd);
invalidateRange(editTrack, editTrack, lower->first, upper->first);
}
else MessageBeep(0);
}
void TrackView::editDelete() void TrackView::editDelete()
{ {
int selectLeft = min(selectStartTrack, selectStopTrack); int selectLeft = min(selectStartTrack, selectStopTrack);
@ -863,6 +901,10 @@ LRESULT TrackView::onChar(UINT keyCode, UINT flags)
} }
else MessageBeep(0); else MessageBeep(0);
break; break;
case 'i':
editToggleInterpolationType();
break;
} }
return FALSE; return FALSE;
} }

View File

@ -47,6 +47,7 @@ private:
void editCopy(); void editCopy();
void editCut(); void editCut();
void editPaste(); void editPaste();
void editToggleInterpolationType();
void paintTracks(HDC hdc, RECT rcTracks); void paintTracks(HDC hdc, RECT rcTracks);
void paintTopMargin(HDC hdc, RECT rcTracks); void paintTopMargin(HDC hdc, RECT rcTracks);

View File

@ -79,12 +79,17 @@ bool ClientDevice::update(float row)
{ {
int track, row; int track, row;
float value; float value;
Track::KeyFrame::InterpolationType interp;
recv(serverSocket, (char*)&track, sizeof(int), 0); recv(serverSocket, (char*)&track, sizeof(int), 0);
recv(serverSocket, (char*)&row, sizeof(int), 0); recv(serverSocket, (char*)&row, sizeof(int), 0);
recv(serverSocket, (char*)&value, sizeof(float), 0); recv(serverSocket, (char*)&value, sizeof(float), 0);
recv(serverSocket, (char*)&interp, 1, 0);
assert(interp < Track::KeyFrame::IT_COUNT);
sync::Track &t = syncData.getTrack(track); sync::Track &t = syncData.getTrack(track);
t.setKeyFrame(row, Track::KeyFrame(value)); t.setKeyFrame(row, Track::KeyFrame(value, interp));
} }
break; break;

View File

@ -1,17 +1,62 @@
#define _USE_MATH_DEFINES
#include <cmath>
#include "track.h" #include "track.h"
#include "data.h" #include "data.h"
using namespace sync; using namespace sync;
#include <cmath>
#include <cstddef> #include <cstddef>
/*#ifndef M_PI
#define M_PI
#endif */
static inline float step(Track::KeyFrameContainer::const_iterator lower, Track::KeyFrameContainer::const_iterator upper, float time)
{
return lower->second.value;
}
static inline float lerp(Track::KeyFrameContainer::const_iterator lower, Track::KeyFrameContainer::const_iterator upper, float time)
{
// find local time
float t = (time - lower->first) / (upper->first - lower->first);
// lerp, bitch
float delta = upper->second.value - lower->second.value;
return lower->second.value + delta * t;
}
static inline float cosine(Track::KeyFrameContainer::const_iterator lower, Track::KeyFrameContainer::const_iterator upper, float time)
{
// find local time
float t = (time - lower->first) / (upper->first - lower->first);
t = float((1.0 - cos(t * M_PI)) * 0.5);
// lerp, bitch
float delta = upper->second.value - lower->second.value;
return lower->second.value + delta * t;
}
static inline float ramp(Track::KeyFrameContainer::const_iterator lower, Track::KeyFrameContainer::const_iterator upper, float time)
{
// find local time
float t = (time - lower->first) / (upper->first - lower->first);
t = powf(t, 2.0f);
// lerp, bitch
float delta = upper->second.value - lower->second.value;
return lower->second.value + delta * t;
}
/*float cosine(float time) const;
float ramp(float time) const; */
float Track::getValue(float time) const float Track::getValue(float time) const
{ {
if (keyFrames.size() == 0) return 0.0f; if (keyFrames.size() == 0) return 0.0f;
int currRow = int(floor(time));
// find bounding keyframes // find bounding keyframes
int currRow = int(floor(time));
KeyFrameContainer::const_iterator upper = keyFrames.upper_bound(currRow); KeyFrameContainer::const_iterator upper = keyFrames.upper_bound(currRow);
KeyFrameContainer::const_iterator lower = upper; KeyFrameContainer::const_iterator lower = upper;
lower--; lower--;
@ -20,11 +65,16 @@ float Track::getValue(float time) const
if (lower == keyFrames.end()) return upper->second.value; if (lower == keyFrames.end()) return upper->second.value;
if (upper == keyFrames.end()) return lower->second.value; if (upper == keyFrames.end()) return lower->second.value;
float delta = upper->second.value - lower->second.value; switch (lower->second.interpolationType)
{
// lerp, bitch case Track::KeyFrame::IT_STEP: return step( lower, upper, time);
float d = (time - lower->first) / (upper->first - lower->first); case Track::KeyFrame::IT_LERP: return lerp( lower, upper, time);
return lower->second.value + delta * d; case Track::KeyFrame::IT_COSINE: return cosine(lower, upper, time);
case Track::KeyFrame::IT_RAMP: return ramp( lower, upper, time);
default:
assert(false);
return step(lower, upper, time);
}
} }
bool Track::isKeyFrame(size_t row) const bool Track::isKeyFrame(size_t row) const

View File

@ -10,13 +10,28 @@ namespace sync
public: public:
struct KeyFrame struct KeyFrame
{ {
KeyFrame() : lerp(false) {} enum InterpolationType
KeyFrame(float value) : value(value), lerp(false) {} {
IT_STEP,
IT_LERP,
IT_COSINE,
IT_RAMP,
IT_COUNT // max value
};
KeyFrame() : value(0.0f), interpolationType(IT_STEP) {}
explicit KeyFrame(float value, InterpolationType interpolationType) :
value(value),
interpolationType(interpolationType)
{
}
float value; float value;
bool lerp; InterpolationType interpolationType;
}; };
float getValue(float time) const; float getValue(float time) const;
bool isKeyFrame(size_t row) const; bool isKeyFrame(size_t row) const;
const KeyFrame *getKeyFrame(size_t row) const; const KeyFrame *getKeyFrame(size_t row) const;
size_t getFrameCount() const; size_t getFrameCount() const;

View File

@ -182,6 +182,7 @@
/> />
<Tool <Tool
Name="VCLibrarianTool" Name="VCLibrarianTool"
AdditionalDependencies="ws2_32.lib"
/> />
<Tool <Tool
Name="VCALinkTool" Name="VCALinkTool"