资源简介

这是Cohen-Sutherland直线段的裁剪算法在VC下的实现,连续单击两个点绘制直线段,直线段位于裁剪窗口内的部分显示为黑色,其它部分为灰色。

资源截图

代码片段和文件信息

// Cohen-Sutherland.cpp : 定义应用程序的入口点。
//

#include “stdafx.h“
#include “Cohen-Sutherland.h“

#define MAX_LOADSTRING 100

// 全局变量:
HINSTANCE hInst; // 当前实例
TCHAR sztitle[MAX_LOADSTRING]; // 标题栏文本
TCHAR szWindowClass[MAX_LOADSTRING]; // 主窗口类名

// 此代码模块中包含的函数的前向声明:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE int);
LRESULT CALLBACK WndProc(HWND UINT WPARAM LPARAM);
INT_PTR CALLBACK About(HWND UINT WPARAM LPARAM);

int APIENTRY _tWinMain(HINSTANCE hInstance
                     HINSTANCE hPrevInstance
                     LPTSTR    lpCmdLine
                     int       nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

  // TODO: 在此放置代码。
MSG msg;
HACCEL hAccelTable;

// 初始化全局字符串
LoadString(hInstance IDS_APP_title sztitle MAX_LOADSTRING);
LoadString(hInstance IDC_COHENSUTHERLAND szWindowClass MAX_LOADSTRING);
MyRegisterClass(hInstance);

// 执行应用程序初始化:
if (!InitInstance (hInstance nCmdShow))
{
return FALSE;
}

hAccelTable = LoadAccelerators(hInstance MAKEINTRESOURCE(IDC_COHENSUTHERLAND));

// 主消息循环:
while (GetMessage(&msg NULL 0 0))
{
if (!TranslateAccelerator(msg.hwnd hAccelTable &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return (int) msg.wParam;
}

typedef struct {
unsigned int all;
unsigned left top right bottom;
} OutCode;
void CompOutCode(float x float y RECT *rect OutCode *outCode)
{
outCode->all = 0;
outCode->left = outCode->top = outCode->right = outCode->bottom = 0;
if (x < rect->left)
{
outCode->left = 1;
outCode->all += 1;
}
if (y < rect->top)
{
outCode->top = 1;
outCode->all += 2;
}
if (x > rect->right)
{
outCode->right = 1;
outCode->all += 4;
}
if (y > rect->bottom)
{
outCode->bottom = 1;
outCode->all += 8;
}
}
void CohenSutherlandLineClip(HDC hdc float x0 float y0 float x1 float y1 RECT *rect)
{
bool accept done;
OutCode outCode0 outCode1;

float x y;
accept = false;
done = false;
CompOutCode(x0 y0 rect &outCode0);
CompOutCode(x1 y1 rect &outCode1);
do {
if (outCode0.all == 0 && outCode1.all == 0)
{
accept = true;
done = true;
}
else if ((outCode0.all & outCode1.all) != 0)
{
done = true;
}
else
{
OutCode *outCodeOut;
if (outCode0.all != 0)
outCodeOut = &outCode0;
else
outCodeOut = &outCode1;

if (outCodeOut->left)
{
x = rect->left;
y = y0+(y1-y0)*(rect->left-x0)/(x1-x0);
}
else if (outCodeOut->top)
{
x = x0+(x1-x0)*(rect->top-y0)/(y1-y0);
y = rect->top;
}
else if (outCodeOut->right)
{
x = rect->right;
y = y0+(y1-y0)*(rect->right-x0)/(x1-x0);
}
else if (outCodeOut->bottom)
{
x = x0+(x1-x0)*(rect->bottom-y0)/(y1-y0);
y = rect->bottom;
}

if (outCodeOut == &outCode0)
{
x0 = x

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        915  2017-02-24 13:54  Cohen-Sutherland.sln

     文件       4636  2017-02-24 13:54  Cohen-Sutherland\Cohen-Sutherland.vcxproj

     文件        143  2017-02-24 13:54  Cohen-Sutherland\Cohen-Sutherland.vcxproj.user

     文件       1828  2017-02-24 13:54  Cohen-Sutherland\Cohen-Sutherland.vcxproj.filters

     文件       2432  2017-02-24 13:54  Cohen-Sutherland\ReadMe.txt

     文件        420  2017-02-24 13:54  Cohen-Sutherland\stdafx.h

     文件        236  2017-02-24 13:54  Cohen-Sutherland\targetver.h

     文件        221  2017-02-24 13:54  Cohen-Sutherland\stdafx.cpp

     文件       7282  2017-02-24 15:33  Cohen-Sutherland\Cohen-Sutherland.cpp

     文件        753  2017-02-24 13:54  Cohen-Sutherland\Resource.h

     文件       6678  2017-02-24 13:54  Cohen-Sutherland\Cohen-Sutherland.rc

     文件         39  2017-02-24 13:54  Cohen-Sutherland\Cohen-Sutherland.h

    .......     23558  2009-08-31 02:31  Cohen-Sutherland\small.ico

    .......     23558  2009-08-31 02:31  Cohen-Sutherland\Cohen-Sutherland.ico

     文件       4043  2017-02-24 15:33  Cohen-Sutherland\Debug\Cohen-Sutherland.log

     文件        713  2017-02-24 15:18  Cohen-Sutherland\Debug\Cohen-Sutherland.vcxprojResolveAssemblyReference.cache

     文件         73  2017-02-24 15:33  Cohen-Sutherland\Debug\Cohen-Sutherland.lastbuildstate

     文件          0  2017-02-24 15:18  Cohen-Sutherland\Debug\Cohen-Sutherland.write.1.tlog

     文件     281600  2017-02-24 15:33  Cohen-Sutherland\Debug\vc100.idb

     文件    4456448  2017-02-24 15:18  Cohen-Sutherland\Debug\Cohen-Sutherland.pch

     文件     405504  2017-02-24 15:33  Cohen-Sutherland\Debug\vc100.pdb

     文件     125875  2017-02-24 15:18  Cohen-Sutherland\Debug\stdafx.obj

     文件       9662  2017-02-24 15:33  Cohen-Sutherland\Debug\CL.read.1.tlog

     文件        948  2017-02-24 15:33  Cohen-Sutherland\Debug\CL.write.1.tlog

     文件       1586  2017-02-24 15:33  Cohen-Sutherland\Debug\cl.command.1.tlog

     文件      48336  2017-02-24 15:18  Cohen-Sutherland\Debug\Cohen-Sutherland.res

     文件       3298  2017-02-24 15:18  Cohen-Sutherland\Debug\rc.read.1.tlog

     文件        646  2017-02-24 15:18  Cohen-Sutherland\Debug\rc.write.1.tlog

     文件       1252  2017-02-24 15:18  Cohen-Sutherland\Debug\rc.command.1.tlog

     文件        406  2017-02-24 15:18  Cohen-Sutherland\Debug\Cohen-Sutherland.exe.embed.manifest

............此处省略17个文件信息

评论

共有 条评论