コード例 #1
0
ファイル: OSGCTRL.cpp プロジェクト: flyskyosg/osgkeyframer
void COSGCTRL::interpolateKeyFrames(osg::ref_ptr<osg::AnimationPath> ap, float fps)
{
	CRSpline spline;
	//build list of keyframes
	for(int i = 0; i < m_ListCtrl.GetItemCount();i++)
	{
		KeyFrame* key = (KeyFrame*) m_ListCtrl.GetItemData(i);
		osg::Vec3 pos = key->ctrlPoint.getPosition();
		osg::Quat rot = key->ctrlPoint.getRotation();		
		spline.AddSplinePoint(vec3(key->timeStamp,pos.x(),pos.y(),pos.z(),rot.x(),rot.y(),rot.z(),rot.w()));		
	}

	//get frame timedeltas based on 30 fps
	float finaltime = ((KeyFrame*)m_ListCtrl.GetItemData(m_ListCtrl.GetItemCount()-1))->timeStamp;
	float tdelta= 1.0 / fps;

	//build list of interpolated frames
	for(float i = 0.0; i < finaltime ; i += tdelta)
	{
		vec3 interp =spline.GetInterpolatedSplineKeyFrame(i);
		KeyFrame key;
		key.ctrlPoint.setPosition(osg::Vec3(interp.x,interp.y,interp.z));
		key.ctrlPoint.setRotation(osg::Quat(interp.rx,interp.ry,interp.rz,interp.ra));
		ap->insert(i,key.ctrlPoint);
	}

	//add last frame
	vec3 interp =spline.GetInterpolatedSplineKeyFrame(finaltime);
	KeyFrame key;
	key.ctrlPoint.setPosition(osg::Vec3(interp.x,interp.y,interp.z));
	key.ctrlPoint.setRotation(osg::Quat(interp.rx,interp.ry,interp.rz,interp.ra));
	ap->insert(finaltime,key.ctrlPoint);
}
コード例 #2
0
 void appendLineStrip(osg::Vec3Array* src) {
   int size = _array->size();
   _array->insert(_array->end(), src->begin(), src->end());
   _geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP, size, src->size()));
 }