/********************************************************************/ /* Copyright (c) 2017 System fugen G.K. and Yuzi Mizuno */ /* All rights reserved. */ /********************************************************************/ #include "MGCLStdAfx.h" #include "mg/Straight.h" #include "mgGL/PlaneImage.h" #include "mgGL/VBO.h" #include "mgGL/Texture.h" #include "mgGL/GLSLProgram.h" // //Define MGPlaneImage Class. ///MGPlaneImage defines square image plane. ///This is displayed using texture mapping. ///The plane's root point is the (left, bottom) point of the image(m_image). ///m_uderiv and m_vderiv of the plane are always defined as unit_vectors. ///The pixel sizes are also defined as m_pixelSizeWidth and m_pixelSizeHeight. ///This implies width and hight can be different size. //////////////////Constructor////////////////// MGPlaneImage::MGPlaneImage( const MGVector& uderiv,///0.); if(m_pixelSizeHeight<=0.) m_pixelSizeHeight=m_pixelSizeWidth; m_rightTexCoord=1.;//m_rightTexCoord=double(image_width())/m_pixelSizeWidth; m_topTexCoord=1.;//m_topTexCoord=double(image_height())/m_pixelSizeHeight; } ///Assignment MGPlaneImage& MGPlaneImage::operator=(const MGPlaneImage& gel2){ MGPlane::operator=(gel2); m_image=gel2.m_image; m_pixelSizeWidth=gel2.m_pixelSizeWidth; m_pixelSizeHeight=gel2.m_pixelSizeHeight; m_rightTexCoord=gel2.m_rightTexCoord; m_topTexCoord=gel2.m_topTexCoord; return *this; } ////////Member Function//////// ///Obtain ceter coordinate of the geometry. MGPosition MGPlaneImage::center()const{ double uc=param_e_u()*.5; double vc=param_e_v()*.5; return eval(uc,vc); } ///Generate a newed clone object. MGPlaneImage* MGPlaneImage::clone()const{ MGPlaneImage* pimg=new MGPlaneImage; pimg->MGPlane::operator=(*this); std::unique_ptr image2(m_image.clone()); pimg->m_image=*image2; pimg->m_pixelSizeWidth=m_pixelSizeWidth; pimg->m_pixelSizeHeight=m_pixelSizeHeight; pimg->m_rightTexCoord=m_rightTexCoord; pimg->m_topTexCoord=m_topTexCoord; return pimg; } ///Draw 3D curve in world coordinates. void MGPlaneImage::shade( mgVBO& vbo, const MGDrawParam& para, mgVBO::ELEMENT_TARGET target )const{ if(!m_texture.getTextureID()){ m_texture.set_image(m_image ,true//mutable texture ,false//Not PointSprite ,GL_CLAMP,GL_NEAREST ); } // MGPlaneImageはLightの影響を受けない mgLightModeSwitcher switcher(vbo, mgGLSL::NoShading); vbo.Begin(GL_TRIANGLE_STRIP,target); MGPosition LT=left_top();//left top point vbo.TexCoord2d(0.,m_topTexCoord);vbo.Vertex3dv(LT.data()); const MGPosition& LB=root_point();//Left bottom point. vbo.TexCoord2d(0.,0.); vbo.Vertex3dv(LB.data()); MGPosition RT=right_top();//right top point vbo.TexCoord2d(m_rightTexCoord,m_topTexCoord);vbo.Vertex3dv(RT.data()); MGPosition RB=right_bottom();//right bottom point. vbo.TexCoord2d(m_rightTexCoord,0.);vbo.Vertex3dv(RB.data()); vbo.setTexture(&m_texture); vbo.setDrawType(mgGLSL::Texture); vbo.End(); } ///Evaluate left_bottom point. MGPosition MGPlaneImage::left_bottom()const{ return root_point(); } ///Evaluate right_bottom point. MGPosition MGPlaneImage::right_bottom()const{ return eval(param_e_u(),0.); } ///Evaluate right_top point. MGPosition MGPlaneImage::right_top()const{ return eval(param_e_u(),param_e_v()); } ///Evaluate left_top point. MGPosition MGPlaneImage::left_top()const{ return eval(0.,param_e_v()); } ///Return parameter range of the plane(Infinite box). MGBox MGPlaneImage::param_range() const{ return MGSurface::param_range(); } ///Compute parameter curve. ///Returned is newed area pointer, and must be freed by delete. MGCurve* MGPlaneImage::parameter_curve( int is_u /// MGPlaneImage::skeleton(int density)const{ return MGFSurface::skeleton(density); } //Get total image size in world coordnate for width. double MGPlaneImage::totalWidth()const{ double w=m_pixelSizeWidth*double(image_width()); return w; } //Get total image size in world coordnate for height. double MGPlaneImage::totalHeight()const{ double h=m_pixelSizeHeight*double(image_height()); return h; } ///Read all member data. void MGPlaneImage::ReadMembers(MGIfstream& buf){ } ///Write all member data void MGPlaneImage::WriteMembers(MGOfstream& buf)const{ } /// Output function. std::ostream& MGPlaneImage::out(std::ostream& strm) const{ strm<<"MGPlaneImage::"<expand(eval(0.,ve)); bx->expand(eval(ue,0.)); return bx; }