线条样式颜色 以及平滑

#include <windows.h>
#include <tchar.h>
#include <math.h>
#include "CELLMath.hpp"
#include "OpenGLWindow.h"
#include <vector>

using namespace CELL;

class   SamplerSplineEditor :public OpenGLWindow
{
public:
	std::vector<float3> _array;
	std::vector<float3> _keys;
	tspline<float> _spline;

	bool _isButtonDown;
	size_t _selectIndex;
	POINT _mouseOld;

	SamplerSplineEditor()
	{
		_isButtonDown = false;
		_selectIndex = -1;

		_spline.addPoint(float3(10,10,0));
		_spline.addPoint(float3(20,100,0));
		_spline.addPoint(float3(100,80,0));
		_spline.addPoint(float3(200,100,0));
		_spline.addPoint(float3(300,10,0));
		_spline.addPoint(float3(400,150,0));

		for(float t=0;t<1.0f;t+=0.01f)
		{
			float3 pos = _spline.interpolate(t);
			_array.push_back(pos);

		}
		for(int i=0;i<_spline.getNumPoints();++i)
		{
			_keys.push_back(_spline.getPoint(i));

		}

	}

    virtual void    render()
    {
		#define M_PI (3.14159265358979323846)
        //! 指定以下的操作针对投影矩阵
        glMatrixMode(GL_PROJECTION);
        //! 将投影举证清空成单位矩阵
        glLoadIdentity();
        glOrtho(0,_width,_height,0,-100,100);

		glColor3f(1,0,0);
		glLineWidth(2);
		glEnable(GL_LINE_SMOOTH);
		glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);

		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

        glEnableClientState(GL_VERTEX_ARRAY);
		glVertexPointer(3,GL_FLOAT,sizeof(float3),&_array[0]);
		glDrawArrays(GL_LINE_STRIP,0,_array.size()); 


		glEnable(GL_POINT_SMOOTH);
		glHint(GL_POINT_SMOOTH_HINT,GL_NICEST);
		glPointSize(8);
		glVertexPointer(3,GL_FLOAT,sizeof(float3),&_keys[0]);
		glDrawArrays(GL_POINTS,0,_keys.size());

    }

	virtual LRESULT events(HWND hWnd,UINT msgId, WPARAM wParam, LPARAM lParam)
    {
        switch(msgId)
        {
        case WM_CLOSE:
        case WM_DESTROY:
            {
                PostQuitMessage(0);
            }
            break;
        case  WM_LBUTTONDOWN:
            {
                _isButtonDown   =   true;
                _selectIndex    =   -1;

                POINT   pt  =  {LOWORD(lParam),HIWORD(lParam)};

                _mouseOld   =   pt;

                for (size_t i = 0 ;i< _keys.size() ; ++ i)
                {
                    RECT    rt;
                    rt.left =   _keys[i].x - 4;
                    rt.right =   _keys[i].x + 4;
                    rt.top =   _keys[i].y - 4;
                    rt.bottom =   _keys[i].y + 4;

                    if (PtInRect(&rt,pt))
                    {
                        _selectIndex    =   i;
                        break;
                    }
                }
            }
            break;
        case WM_LBUTTONUP:
            {
                _isButtonDown   =   false;
                _selectIndex    =   -1;
            }
            break;
        case WM_MOUSEMOVE:
            {
                if (_isButtonDown && _selectIndex != -1)
                {
                    POINT   pt  =   {LOWORD(lParam),HIWORD(lParam)};

                    POINT   off =   {   pt.x - _mouseOld.x,pt.y - _mouseOld.y};

                    _mouseOld   =   pt;

                    _keys[_selectIndex].x   +=  off.x;
                    _keys[_selectIndex].y   +=  off.y;

                    _spline.getPoint(_selectIndex).x    +=  off.x;
                    _spline.getPoint(_selectIndex).y    +=  off.y;

                    _spline.recalcTangents();

                    _array.clear();

                    for (float t = 0 ; t < 1.0f; t += 0.01f)
                    {
                        float3  pos =   _spline.interpolate(t);
                        _array.push_back(pos);
                    }

                }
            }
            break;
        default:
            return DefWindowProc(hWnd, msgId, wParam, lParam);
        }
        return  0;
    }
};

int __stdcall WinMain( 
                      HINSTANCE hInstance, 
                      HINSTANCE hPrevInstance, 
                      LPSTR lpCmdLine, 
                      int nShowCmd
                      )
{
   
    SamplerSplineEditor    instance;
    instance.main(800,600);


    return  0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值