问题五十六:怎么用ray tracing画参数方程表示的曲面(3)—— b-spline surface

接“问题五十四”,已经简单学习了bezier曲线曲面,知道了双三次bezier曲面的矩阵表示形式,同时也以此画出了曲面图形。

这一章节主要以对比bezier曲线曲面和b-spline曲线曲面的方式来简单学习b-spline曲线曲面。

 



56.1 b-spline曲线








56.2 b-spline曲面










56.3 b-spline的C++代码实现

 

----------------------------------------------parametric_surface.h ------------------------------------------

parametric_surface.h

 

#ifndef PARAMETRIC_SURFACE_H
#define PARAMETRIC_SURFACE_H

#include <hitable.h>
#include "material.h"
#include "log.h"

#define TYPE 3
/*
TYPE=1: sphere;
TYPE=2: horn;
TYPE=3: bezier3;
*/
#define CURVE 1
/*
CURVE=1: bezier
CURVE=2: b-spline
*/

class parametric_surface : public hitable
{
    public:
        parametric_surface() {}
#if ((TYPE == 1) || (TYPE ==2))
        parametric_surface(vec3 cen, float a, float b, float c, float hy, material *m, float r, float t, float n) : center(cen), intercept_x(a), intercept_y(b), intercept_z(c), height_half_y(hy), ma(m), rho(r), theta(t), num(n) {}
#endif // TYPE
#if TYPE == 3
        parametric_surface(material *m, float r, float t, float n, vec3 *cp) : ma(m), rho(r), theta(t), num(n) {
/*相比bicubic Bezier surface,bicubic b-spline surface只需要改动如下黄底部分代码*/
            vec3 ctrl_points[4][4];
            for (int i=0; i<16; i++) {
                ctrl_points[(i/4)][(i%4)] = cp[i];
            }
#if CURVE == 1//bezier
            float matrix_t[4][4] = {
  
  { 1,  0,  0, 0},
                                    {-3,  3,  0, 0},
                                    { 3, -6,  3, 0},
                                    {-1,  3, -3, 1}};
            float matrix[4][4] = {
  
  {1, -3,  3, -1},
              
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值