祝贺VC版开张,也祝愿大家能不用再去CSDN,能在此找到答案(送光滑曲线程序)(0分)

  • 主题发起人 主题发起人 吕雪松
  • 开始时间 开始时间

吕雪松

Unregistered / Unconfirmed
GUEST, unregistred user!
送上第一个程序:过控制点的光滑曲线。
#ifndef _SPLINE_H
#define _SPLINE_H
#include "math.h"
#include "stdafx.h"
#define DIV_FACTOR 4.0 //adjust this factor to adjust the curve smoothness
class Curve
{
public:
float Ax,Ay;
float Bx,By;
float Cx,Cy;
int Ndiv;
Curve(float ax,float ay,float bx,float by,float cx,float cy,int ndiv)
{
Ax = ax;
Ay = ay;
Bx = bx;
By = by;
Cx = cx;
Cy = cy;
Ndiv = ndiv;
}
Curve(float ax,float ay,float bx,float by,float cx,float cy)
{
Ax = ax;
Ay = ay;
Bx = bx;
By = by;
Cx = cx;
Cy = cy;
Ndiv = (int)(max(abs((int)Ax),abs((int)Ay))/DIV_FACTOR);
}
Curve()
{
};
void PutCurve(float ax,float ay,float bx,float by,float cx,float cy)
{
Ax = ax;
Ay = ay;
Bx = bx;
By = by;
Cx = cx;
Cy = cy;
Ndiv = (int)(max(abs((int)Ax),abs((int)Ay))/DIV_FACTOR);
}
void draw(HDC hdc,float x,float y)
{
int OrigX,OrigY,NewX,NewY;
float t,f,g,h;
if (Ndiv==0)
Ndiv=1;
OrigX = (int)x;
OrigY= (int)y;
for(int i=1;
i<=Ndiv i++)
{
t = 1.0f / (float)Ndiv * (float)i;
f = t*t*(3.0f-2.0f*t);
g = t*(t-1.0f)*(t-1.0f);
h = t*t*(t-1.0f);
NewX = (int)(x + Ax*f + Bx*g + Cx*h);
NewY = (int)(y + Ay*f + By*g + Cy*h);
MoveToEx(hdc, OrigX, OrigY, NULL);
LineTo(hdc, NewX, NewY);
OrigX = NewX;

OrigY=NewY;
}
}
int GetCount()
{
if (Ndiv==0)
Ndiv=1;
int PointCount = 1;
for(int i=1;
i<=Ndiv i++)
{
PointCount++;
}
return PointCount;
}
void GetCurve(float x,float y, POINT points[], int&amp;
PointCount)
{
int X,Y;
float t,f,g,h;
if (Ndiv==0)
Ndiv=1;
X = (int)x;
Y= (int)y;
points[PointCount].x = X;
points[PointCount].y = Y;
PointCount++;
for(int i=1;
i<=Ndiv i++)
{
t = 1.0f / (float)Ndiv * (float)i;
f = t*t*(3.0f-2.0f*t);
g = t*(t-1.0f)*(t-1.0f);
h = t*t*(t-1.0f);
X = (int)(x + Ax*f + Bx*g + Cx*h);
Y = (int)(y + Ay*f + By*g + Cy*h);
points[PointCount].x = X;
points[PointCount].y = Y;
PointCount++;
}
}

};
class Spline
{
public:
float* Px;
float* Py;
float* Ax;
float* Ay;
float* Bx;
float* By;
float* Cx;
float* Cy;
float* k;
float* Mat[3];
int NP;
// constructor
Spline(POINT pt[], int np)
{
NP = np;
Px = new float[NP];
Py = new float[NP];
Ax = new float[NP];
Ay = new float[NP];
Bx = new float[NP];
By = new float[NP];
Cx = new float[NP];
Cy = new float[NP];
k = new float[NP];
Mat[0] = new float[NP];
Mat[1] = new float[NP];
Mat[2] = new float[NP];
for(int i=0;i<NP i++)
{
Px = (float)pt.x;

Py = (float)pt.y;
}
}
Spline(float px[] , float py[] , int np)
{
NP = np;
Px = new float[NP];
Py = new float[NP];
Ax = new float[NP];
Ay = new float[NP];
Bx = new float[NP];
By = new float[NP];
Cx = new float[NP];
Cy = new float[NP];
k = new float[NP];
Mat[0] = new float[NP];
Mat[1] = new float[NP];
Mat[2] = new float[NP];
for(int i=0;i<NP i++)
{
Px = px;

Py = py;
}
}

~Spline()
{
delete[] Px;
delete[] Py;
delete[] Ax;
delete[] Ay;
delete[] Bx;
delete[] By;
delete[] Cx;
delete[] Cy;
delete[] k;
delete[] Mat[0];
delete[] Mat[1];
delete[] Mat[2];
}
void Generate()
{
float AMag , AMagOld;
// vector A
for(int i= 0 i<=NP-2 i++ )
{
Ax = Px[i+1] - Px;
Ay = Py[i+1] - Py;
}
// k
AMagOld = (float)sqrt(Ax[0]*Ax[0] + Ay[0]*Ay[0]);
for(i=0 i<=NP-3 i++)
{
AMag = (float)sqrt(Ax[i+1]*Ax[i+1] + Ay[i+1]*Ay[i+1]);
k = AMagOld / AMag;
AMagOld = AMag;
}
k[NP-2] = 1.0f;
// Matrix
for(i=1;
i<=NP-2;i++)
{
Mat[0] = 1.0f;
Mat[1] = 2.0f*k[i-1]*(1.0f + k[i-1]);
Mat[2] = k[i-1]*k[i-1]*k;
}
Mat[1][0] = 2.0f;
Mat[2][0] = k[0];
Mat[0][NP-1] = 1.0f;
Mat[1][NP-1] = 2.0f*k[NP-2];
//
for(i=1;
i<=NP-2;i++)
{
Bx = 3.0f*(Ax[i-1] + k[i-1]*k[i-1]*Ax);
By = 3.0f*(Ay[i-1] + k[i-1]*k[i-1]*Ay);
}
Bx[0] = 3.0f*Ax[0];
By[0] = 3.0f*Ay[0];
Bx[NP-1] = 3.0f*Ax[NP-2];
By[NP-1] = 3.0f*Ay[NP-2];
//
MatrixSolve(Bx);
MatrixSolve(By);
for(i=0 i<=NP-2 i++ )
{
Cx = k*Bx[i+1];
Cy = k*By[i+1];
}
}
void MatrixSolve(float B[])
{
float* Work = new float[NP];
float* WorkB = new float[NP];
for(int i=0;i<=NP-1;i++)
{
Work = B / Mat[1];
WorkB = Work;
}
for(int j=0 j<10 j++)
{ /// need convergence judge
Work[0] = (B[0] - Mat[2][0]*WorkB[1])/Mat[1][0];
for(int i=1;
i<NP-1 i++ )
{
Work = (B-Mat[0]*WorkB[i-1]-Mat[2]*WorkB[i+1])
/Mat[1];
}
Work[NP-1] = (B[NP-1] - Mat[0][NP-1]*WorkB[NP-2])/Mat[1][NP-1];
for(i=0 i<=NP-1 i++ )
{
WorkB = Work;
}
}
for(i=0 i<=NP-1 i++ )
{
B = Work;
}
delete[] Work;
delete[] WorkB;
}
void draw(HDC hdc)
{
Curve c;
for(int i=0;
i<NP-1 i++)
{
c.PutCurve(Ax,Ay,Bx,By,Cx,Cy);
c.draw(hdc,Px,Py);
}

}
int GetCurveCount()
{
Curve c;
int count = 0;
for(int i=0;
i<NP-1 i++)
{
c.PutCurve(Ax,Ay,Bx,By,Cx,Cy);
count += c.GetCount();
}
return count;
}
void GetCurve(POINT points[], int&amp;
PointCount)
{
Curve c;
for(int i=0;
i<NP-1 i++)
{
c.PutCurve(Ax,Ay,Bx,By,Cx,Cy);
c.GetCurve(Px,Py, points, PointCount);
}
}
//////////// closed cubic spline ////////////////////
void GenClosed()
{
float AMag , AMagOld , AMag0;
// vector A
for(int i= 0 i<=NP-2 i++ )
{
Ax = Px[i+1] - Px;
Ay = Py[i+1] - Py;
}
Ax[NP-1] = Px[0] - Px[NP-1];
Ay[NP-1] = Py[0] - Py[NP-1];
// k
AMag0 = AMagOld = (float)sqrt(Ax[0]*Ax[0] + Ay[0]*Ay[0]);
for(i=0 i<=NP-2 i++)
{
AMag = (float)sqrt(Ax[i+1]*Ax[i+1] + Ay[i+1]*Ay[i+1]);
k = AMagOld / AMag;
AMagOld = AMag;
}
k[NP-1]=AMagOld/AMag0;

// Matrix
for(i=1;
i<=NP-1;i++)
{
Mat[0] = 1.0f;
Mat[1][1] = 2.0f*k[i-1]*(1.0f + k[i-1]);
Mat[2] = k[i-1]*k[i-1]*k;
}
Mat[0][0] = 1.0f;
Mat[1][0] = 2.0f*k[NP-1]*(1.0f + k[NP-1]);
Mat[2][0] = k[NP-1]*k[NP-1]*k[0];
//
for(i=1;
i<=NP-1;i++)
{
Bx = 3.0f*(Ax[i-1] + k[i-1]*k[i-1]*Ax);
By = 3.0f*(Ay[i-1] + k[i-1]*k[i-1]*Ay);
}
Bx[0] = 3.0f*(Ax[NP-1] + k[NP-1]*k[NP-1]*Ax[0]);
By[0] = 3.0f*(Ay[NP-1] + k[NP-1]*k[NP-1]*Ay[0]);
//
MatrixSolveEX(Bx);
MatrixSolveEX(By);
for(i=0 i<=NP-2 i++ )
{
Cx = k*Bx[i+1];
Cy = k*By[i+1];
}
Cx[NP-1] = k[NP-1]*Bx[0];
Cy[NP-1] = k[NP-1]*By[0];
}
///// tridiagonal matrix + elements of [0][0], [N-1][N-1] ////
void MatrixSolveEX(float B[])
{
float* Work = new float[NP];
float* WorkB = new float[NP];
for(int i=0;i<=NP-1;i++)
{
Work = B / Mat[1];
WorkB = Work;
}
for(int j=0 j<10 j++)
{ // need judge of convergence
Work[0] = (B[0]-Mat[0][0]*WorkB[NP-1]-Mat[2][0]*WorkB[1])
/Mat[1][0];
for(int i=1;
i<NP-1 i++ )
{
Work = (B-Mat[0]*WorkB[i-1]-Mat[2]*WorkB[i+1])
/Mat[1];
}
Work[NP-1] = (B[NP-1]-Mat[0][NP-1]*WorkB[NP-2]-Mat[2][NP-1]*WorkB[0])
/Mat[1][NP-1];
for(i=0 i<=NP-1 i++ )
{
WorkB = Work;
}
}
for(i=0 i<=NP-1 i++ )
{
B = Work;
}
}
void drawClosed(HDC hdc)
{
Curve c;
for(int i=0;
i<NP i++)
{
c.PutCurve(Ax,Ay,Bx,By,Cx,Cy);
c.draw(hdc ,Px,Py);
}
}

};
#endif
 
:> DFW明天更好!
 
祝贺!!
恭喜!!!
吕大侠,版主是谁? 不是您吧??
收藏了!
 
但是客观的说
csdn的vc 版还是很优秀的
 
csdn改版后太慢了
 
有新的版确实不错!不过我对VC不懂!TC还可以
BCB版什么时候开啊?
 
呵呵,楼上:
bcb不是已经有了吗 :)
 
不好意思!没有看到!
 
庆贺,希望DFW的VC版超过vchelp,成为中国的CodeGuru.
贴两篇最近整理的如何用C/VC开发DB2的帖子(虽然和数据库
相关,不过还是在VC版交流比较爽一些,[:D])
1. 利用VC写DB2存储过程的步骤
Building C/C++ stored procedure for DB2 UDB
===========================================
= summaried by sunyu =
= 2002.3.23 =
= bluesmart corp. =
===========================================
Steps:
==================================================
1. Activating the DB2 Project and Tools add-ins
2. Creating the project
3. Setting the DB2 project properties
4. Creating the stored procedure
5. Building the project
6. Packaging the project
7. Deploying the project

How to implement the step 1
==================================================
1. Register the add-ins by entering the following command :
db2vccmd register
or you can use menu : register the visuall c++ add-ins.
2. Customize your Visual C++ development environment to enable the add-ins :
a. Click Tools -> Customize from the Visual C++ menu.
b. Go to the Add-ins and Macro Files tab.
c. Select the check boxes for IBM DB2 Project and Tools add-ins.

How to implement the step 2
==================================================
1. Click File -> New from Visual C++ menu.
2. go to the project tab.
3. Select Win32 Dynamic-Link Library project type.
4. Input project name and location path.
5. To create a plain Win32 DLL, click An empty DLL project.
6. Click Finish.

How to implement the step 3
==================================================
1. Click the Add-ins button "project properties" which on the Visual C++
Toolbar.
2. Go to the Indentity page.
3. Click the [...] push button to fill the Database name.
4. Click OK.

How to implement the step 4
==================================================
To create a database stored procedure, click the New DB2 Object
toolbar button on the project Add-In toolbar.
Selec the Exported Stored Procedure object type, and click OK. The
Exported DB2 Stored procedure wizard opens.
To create the stored procedure:
1. On the Identity page, type stored procedure name(e.g. QEmpSalaryCPP).
2. On the Parameters page, click New. The DB2 Stored Porcedure Parameter
window opens. Add your parameters.
e.g.
Name Mode SQL Type
---------------------------------
FromSalary input do
uble
ToSalary input do
uble
3. On the Options page, type the number of result sets
4. On the Code page, create the required SQL query.
5. On the implementation page, use the default implementation module name.
6. Click finish.

How to implement the step 5
=====================================================
To build the project, click Build->Rebuild All on the Visual C++ menu.

How to implement the step 6
=====================================================
1. Click the package DB2 Project toolbar button of the Project Add-In
toolbar to open the Package DB2 Project window.
2. Select the project binary to include as part of the package. Depending
on whether you built this project in debug or releas mode, use one of
the following files:
debug/demoide_sp.dll
release/demoide_sp.dll
3. Click OK

How to implement the step 7
======================================================
1. Click the Deploy DB2 Project toolbar button of the Project Add-In
toolbar. The Deploy DB2 Project window opens.
2. For the tutorial, use the default project binary deployment options.
3. Click OK.
Notes:
you also can use command line to deploy stored procedure :
db2pkgdp.exe ...
Finally, copy the dll file to DB2 server lib /SQLLIB/bin or system directory.
2.设置DB2 SPB的puresql 存储过程的C/C++编译环境
DB2 UDP v7.2 用SQL编写存储过程的C/C++编译环境设置
(Windows 2000平台)
===========================================
= summaried by sunyu =
= 2002.3.23 =
= bluesmart corp. =
===========================================
1. 安装DB2 UDP v7.2 服务器,开发工具(Application Development Client)
2. 安装C/C++编译器,例如可以安装Microsoft Visual C++
3. 在DB2的Stored Procedure Builder中的Selected -> SQL Stored Procedure Build Options中配置
(以安装Micirosoft Visual C++ 6.0为例):
Compiler Enviroment : d:/Program files/Microsoft Visual Studio/VC98/bin/vcvars32.bat
Compiler Options : cl -Od -W2 /TC -D_X86_=1 -I%DB2PATH%/include SQLROUTINE_FILENAME.c /link -dll -def:SQLROUTINE_FILENAME.def /out:SQLROUTINE_FILENAME.dll %DB2PATH%/lib/db2api.lib
4. 设置完毕

当用户无论在客户端还是在服务器端的Stored Procedure Builder中编译SQL存储过程的时候,在服务器端的/SQLLIB/function/Routine/下就生成了存储过程的所有的存储过程文件.
 
各位兄弟,我刚学VC,,,,
有一个问题,,在VC里如何响应EDIT的KEYDOWN事件???
[:D][:D][:D]
 
好啊,好啊
恭喜恭喜
 
我也大吃一惊,怎么忽然有VC++了??
以前不是很排斥吗??
好事来晚了。估计只有DFW里的VC爱好者会来这里。
我们几个同志更要相互加紧联络了!!但是不要笑我菜啊!
 
那次吵架,嘲笑了wsn几句,从此认识了他。
现在才发觉其实他很关心DFW,下不了决心不来啊,呵呵。
小弟大菜鸟,wsn大哥请多多关照!
Email:nevergrief@sina.com
QQ:76628305
 
可惜我水平太菜,如果再过两年开VC板,我就申请版主。
一个遥远的梦想。
 
支持,我喜欢DFW,但是工作中经常又vc的问题,不得不去csdn,希望以后在这里解决,不再去
csdn
 
刚刚学习VC请各位大侠多多指教!
 
后退
顶部