// mandel.cpp : Defines the entry point for the application.
// date of program 2002
#include "stdafx.h"
#include "resource.h"
#include "amd3dx.h"
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int mx = 640, my = 480+100;
BOOL threednow = FALSE;
DWORD t1,t2;
TCHAR buffer[]= "ثلاثي الأبعاد";;
HGLOBAL Hgl;
LPBYTE m;
HBITMAP hbmp;
HDC hdcmem;
HDC hdc;
BOOL now = FALSE;
void draw(HDC hdc,float x0,float y0 ) {
float cx,cy,x1,y1;
int a,b;
int orb,i,j =0;
float xo,yo;
SelectObject(hdcmem,hbmp);
for (b = 0; b<= my-100; b++)
for (a = 0 ; a<=mx ; a++) {
cx = -2.5+4*(float)a/my;
cy = 1.5-4*(float)b/my;
orb = 0; i = 0;
xo = x0, yo = y0;
do {
x1 = xo*xo-yo*yo+cx;
y1 = 2*xo*yo+cy;
xo = x1;
yo = y1;
i++;
}
while ((i < 32) && (x1*x1+y1*y1 < 4.0) && (fabs(x1) < 2.0) && (fabs(y1) < 2.0));
if (i < 32) orb = i;
SetPixel(hdc,a,b,RGB(8*orb,8*orb,0));
}
}
class complex {
public :
float x,y;
complex() { x = 0;y = 0;}
complex(float x0,float y0) { x= x0; y = y0;};
}
;
void draw_3DNOW(HDC hdc,float x0,float y0 ) {
float cx,cy;
int a,b;
int orb,i,j = 0;
int m;
complex c,X;
complex r(-2.5,1.5),t(4,-4),A;
float S;
float M[2],cm[2]={2,2};
float x =4.0;
m = mx;
_asm {
movq mm4,t // mm4 ={4,4}
movq mm5,r // mm5={-2.5,1.3}
}
for (b = 0; b<= my-100; b++)
for (a = 0 ; a<=mx ; a++) {
// cx = -2.5+4*(float)a/mx;
// cy = 1.5-4*(float)b/my;
c =complex(cx,cy);
orb = 0; i = 0;
X = complex(x0,y0);
M[0] = (float) a;M[1] = (float) b;
_asm {
femms
movq mm6,M
movd mm0,m
pi2fd (mm0,mm0)
pfrcp (mm1,mm0)
punpckldq mm0,mm0
pfrcpit1 (mm0,mm1)
pfrcpit2 (mm0,mm1)
pfmul (mm0,mm6)
pfmul (mm0,mm4)
pfadd (mm0,mm5)
movq mm3,mm0 // mm3 = cy | cx
mov eax,0
begin:
movq mm0,X // mm0 -> y|x
movq mm1,mm0 // mm1 -> y|x
pswapd (mm2,mm0) // mm2 -> x|y
pfmul (mm1,mm1) // mm1 -> y*y | x*x
pfmul (mm2,mm0) // mm2 -> x*y | x*y
pfpnacc (mm1,mm2) // mm1 -> 2*x*y | x*x-y*y
pfadd (mm1,mm3) // mm1 -> 2*x*y+cy | x*x-y*y+cx
movq X,mm1 // A( x',y');
cond1:
pfmul (mm1,mm1)
pfacc (mm1,mm1) // module ...
movd S,mm1 // S = x'*x'+y'*y'
}
i++;
while ((i < 32) && (S < 4.0) && (fabs(X.x) < 2.0) && (fabs(X.y) < 2.0));
end:
if (i < 32) orb = i;
SetPixel(hdc,a,b,RGB(8*orb,8*orb,0));
}
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_MANDEL, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_MANDEL);
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage is only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_MANDEL);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+2);
wcex.lpszMenuName = (LPCSTR)IDC_MANDEL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
return RegisterClassEx(&wcex);
}
//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(szWindowClass, szTitle,
WS_CAPTION | WS_OVERLAPPED | WS_MINIMIZEBOX | WS_POPUP | WS_SYSMENU,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
return TRUE;
}
//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
TCHAR szHello[MAX_LOADSTRING];
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
HMENU hmenu;
BITMAP bm;
switch (message)
{ case WM_CREATE:
MoveWindow(hWnd,50,50,mx,my-100,TRUE);
threednow = FALSE;
timeBeginPeriod(1);
hdc = GetDC(hWnd);
//Hgl = GlobalAlloc(GHND,mx*my*3);
//m= (LPVOID ) GlobalLock(Hgl);
m = new BYTE[mx*my*3];
hbmp = CreateBitmap(mx,my,1,2,m);
// SetBitmapBits(hbmp,3*mx*my,m);
//hbmp = CreateCompatibleBitmap(hdc,mx,my);
hdcmem = CreateCompatibleDC(hdc);
SelectObject(hdcmem,hbmp);
GetObject(hbmp,sizeof(bm),&bm);
//m = (LPBYTE) bm.bmBits;
// PlaySound("action3.wav",hInst,SND_LOOP | SND_ASYNC | SND_FILENAME | SND_NOSTOP );
break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_3DNOW:
hmenu =GetMenu(hWnd);
threednow = !threednow;
if (threednow)
CheckMenuItem(hmenu,IDM_3DNOW,MF_CHECKED);
else
CheckMenuItem(hmenu,IDM_3DNOW,MF_UNCHECKED);
break;
case IDM_DRAW:
hdc = GetDC(hWnd);
SetTextColor(hdc,RGB(255,255,0));
SetBkMode(hdc,TRANSPARENT);
PatBlt(hdc,0,0,mx,my,PATCOPY);
t1 = timeGetTime();
if (threednow) draw_3DNOW(hdc,0,0); else draw(hdc,0,0);
t2 = timeGetTime();
// sprintf( buffer,"%d", (t2-t1) );
// if (threednow) strcat(buffer,"ms 3DNow!"); else strcat(buffer,"ms FPU");
TextOut(hdc,0,0, (LPCSTR) buffer, strlen(buffer));
DrawTextEx(hdc,(LPSTR) L"DEMO",5,NULL,DT_CENTER,NULL);
// TextOut(hdc,0,0,(LPCSTR "demo",5);
break;
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
RECT rt;
GetClientRect(hWnd, &rt);
//DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}
Aucun commentaire:
Enregistrer un commentaire