📄 bezr8.c
字号:
/*************************************************************************/
/* */
/* Copyright (c) 1997 - 1999 Accelerated Technology, Inc. */
/* */
/* PROPRIETARY RIGHTS of Accelerated Technology are involved in the */
/* subject matter of this material. All manufacturing, reproduction, */
/* use, and sales rights pertaining to this subject matter are governed */
/* by the license agreement. The recipient of this software implicitly */
/* accepts the terms of the license. */
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* FILE NAME VERSION */
/* */
/* BEZR8.c 1.9 */
/* */
/* COMPONENT */
/* */
/* All */
/* */
/* DESCRIPTION */
/* */
/* This file contains the mwBezDDA function. */
/* */
/* AUTHOR */
/* */
/* Robert G. Burrill, Accelerated Technology, Inc. */
/* */
/* DATA STRUCTURES */
/* */
/* None */
/* */
/* FUNCTIONS */
/* */
/* None */
/* */
/* DEPENDENCIES */
/* */
/* None */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* BobB 5/8/98 Corrected for zero depth */
/* */
/*************************************************************************/
#include "meta_wnd.h"
#include "metconst.h" /* MetaWINDOW Constant & Stucture Definitions */
#include "metports.h" /* MetaWINDOW Port & Bitmap Definitions */
#include "grafdata.h"
#include "metmacs3.h"
/* Function mwBezDDA calculates the de'Casteljau construction points by
recursively subdividing the Bezier curve by its control points.
NOTE: Calculates the de'Casteljau construction points so the Bezier
can be subdivided into 2 parts (left, then right) by recursive calls
to this routine. Recursion is broken off when depth, decremented once
for each recursion level, becomes 0. This is the finest level of
subdivision; the right-most point on the small subdivided Bezier is
also a point on the original Bezier, so we load it into global array
BezPts[] (thru ptrBezPts which points into the array). */
void mwBezDDA(long p0X, long p0Y, long p1X, long p1Y, long p2X, long p2Y,
long p3X, long p3Y, int depth)
{
long q0X;
long q0Y;
long q1X;
long q1Y;
long q2X;
long q2Y;
long r0X;
long r0Y;
long r1X;
long r1Y;
long s0X;
long s0Y;
/* depth == 0 means we are at the finest subdivision level: store the
point into global array and return, breaking off recursion. */
if (depth == 0)
{
ptrBEZPTS->X = (short)(p3X >> 16);
ptrBEZPTS->Y = (short)(p3Y >> 16);
/* BobB 5/8/98 - corrected the following line
*ptrBEZPTS++; */
ptrBEZPTS++;
return;
}
/* Calculate de Casteljau construction points as averages of
previous points (ie., midway points). */
/* q's are midway between 4 incoming control and handle points. */
q0X = (p0X + p1X) >> 1;
q0Y = (p0Y + p1Y) >> 1;
q1X = (p1X + p2X) >> 1;
q1Y = (p1Y + p2Y) >> 1;
q2X = (p2X + p3X) >> 1;
q2Y = (p2Y + p3Y) >> 1;
/* r's are midway between 3 q's. */
r0X = (q0X + q1X) >> 1;
r0Y = (q0Y + q1Y) >> 1;
r1X = (q1X + q2X) >> 1;
r1Y = (q1Y + q2Y) >> 1;
/* s0 is midway between 2 r's and is in middle of original Bez. */
s0X = (r0X + r1X) >> 1;
s0Y = (r0Y + r1Y) >> 1;
/* Decrement depth; subdivide incoming Bez into 2 parts: left, then right. */
mwBezDDA(p0X, p0Y, q0X, q0Y, r0X, r0Y, s0X, s0Y, --depth);
mwBezDDA(s0X, s0Y, r1X, r1Y, q2X, q2Y, p3X, p3Y, depth);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -