欧美三级国产三级日韩三级_亚洲熟妇丰满大屁股熟妇_欧美亚洲成人一区二区三区_国产精品久久久久久模特

Bullet3之優(yōu)化PhysicsDraw3D - 新聞資訊 - 云南小程序開發(fā)|云南軟件開發(fā)|云南網(wǎng)站建設-昆明葵宇信息科技有限公司

159-8711-8523

云南網(wǎng)建設/小程序開發(fā)/軟件開發(fā)

知識

不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價值,我們在追求其視覺表現(xiàn)的同時,更側(cè)重于功能的便捷,營銷的便利,運營的高效,讓網(wǎng)站成為營銷工具,讓軟件能切實提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序為后期升級提供便捷的支持!

您當前位置>首頁 » 新聞資訊 » 技術(shù)分享 >

Bullet3之優(yōu)化PhysicsDraw3D

發(fā)表時間:2020-10-19

發(fā)布人:葵宇科技

瀏覽次數(shù):74


static PhysicsDraw3D* createWithLayer(Node* layer);
為了測試bullet物體的大年夜小,促寫完的PhysicsDraw3D的效力低的要命,這也是為什么cocos2dx棄用了DrawPrimitives,而去應用DrawNode
DrawPrimitives每次繪制都去調(diào)用glDrawElements,假如每幀繪制10000條線段,那么就要調(diào)用10000次glDrawElements,可奏效力之低。
而DrawNode采取的是批處理的方法,當drawLine的時刻不是急速繪制,而是將線段的信息添加到數(shù)組里,當draw時同一調(diào)用gl的繪制函數(shù)
10000/1可不是一個小數(shù)量啊。
下圖應用DrawPrimitives辦法
[img]http://img.blog.csdn.net/20150106195017671?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3R4ZGVjcw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center    [img]http://img.blog.csdn.net/20150106194800454?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3R4ZGVjcw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
參加40個Sphere幀率就掉落到40,70的幀率更是慘不忍睹
void clearDraw();
修改PhysicsDraw3D
燒毀時也要將_drawNode大年夜Parent中移除
下圖應用DrawNode辦法
3. 保存drawPoint, drawPoints, drawLine,其他的繪制函數(shù)不要
[img]http://img.blog.csdn.net/20150106195102312?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3R4ZGVjcw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center    [img]http://img.blog.csdn.net/20150106194934328?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3R4ZGVjcw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
為懂得決這個問題就要參照DrawNode實現(xiàn)一個簡單的DrawNode3D
不管三七二十一,將DrawNode的頭文件代碼copy,刪去一些不須要的,
1.修改V2F_C4B_T2F 為 V3F_C4B_T2F
2.修改Vec2為Vec3,要繪制3D
#ifndef __DRAW_NODE_3D_H__
#define __DRAW_NODE_3D_H__

#include "cocos2d.h"
USING_NS_CC;

class DrawNode3D : public Node
{
public:
	static DrawNode3D* create();

	void drawPoint(const Vec3& point, const float pointSize, const Color4F &color);

	void drawPoints(const Vec3 *position, unsigned int numberOfPoints, const Color4F &color);

	void drawLine(const Vec3 &origin, const Vec3 &destination, const Color4F &color);
	// Overrides
	virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;

    void clear();

    const BlendFunc& getBlendFunc() const;

    void setBlendFunc(const BlendFunc &blendFunc);

    void onDraw(const Mat4 &transform, uint32_t flags);
    void onDrawGLLine(const Mat4 &transform, uint32_t flags);
    void onDrawGLPoint(const Mat4 &transform, uint32_t flags);

CC_CONSTRUCTOR_ACCESS:
	DrawNode3D();
	virtual ~DrawNode3D();
	virtual bool init();

protected:
	void ensureCapacity(int count);
	void ensureCapacityGLPoint(int count);
	void ensureCapacityGLLine(int count);

	GLuint      _vao;
	GLuint      _vbo;
	GLuint      _vaoGLPoint;
	GLuint      _vboGLPoint;
	GLuint      _vaoGLLine;
	GLuint      _vboGLLine;

	int         _bufferCapacity;
	GLsizei     _bufferCount;
	V3F_C4B_T2F *_buffer;

	int         _bufferCapacityGLPoint;
	GLsizei     _bufferCountGLPoint;
	V3F_C4B_T2F *_bufferGLPoint;
	Color4F     _pointColor;
	int         _pointSize;

	int         _bufferCapacityGLLine;
	GLsizei     _bufferCountGLLine;
	V3F_C4B_T2F *_bufferGLLine;

	BlendFunc   _blendFunc;
	CustomCommand _customCommand;
	CustomCommand _customCommandGLPoint;
	CustomCommand _customCommandGLLine;

	bool        _dirty;
	bool        _dirtyGLPoint;
	bool        _dirtyGLLine;

private:
	CC_DISALLOW_COPY_AND_ASSIGN(DrawNode3D);
};

#endif

對于DrawNode.cpp按照膳綾擎所說同樣修改
要記住

因為頂點有三個元素,.cpp代碼過多,請在文┞仿最后下載源碼,要留意的是繪制時開啟深度測試
 
刪除成員變量,添加DrawNode3D* _drawNode,因為DrawNode3D持續(xù)自Node所以創(chuàng)建時要將其添加到父節(jié)點上,
修改create,init為如下
bool initWithLayer(Node* layer);
同時添加
我們知道DrawNode如不雅不履行clear,那么就不會清空上一幀的繪制數(shù)據(jù)
具體修改如下:
PhysicsDraw3D* PhysicsDraw3D::createWithLayer(Node* layer)
{
	auto draw = new PhysicsDraw3D;
	if (draw && draw->initWithLayer(layer))
	{
		return draw;
	}

	return nullptr;
}
bool PhysicsDraw3D::initWithLayer(Node* layer)
{	
	_drawNode = DrawNode3D::create();
	layer->addChild(_drawNode);
	_debugDrawMode = btIDebugDraw::DBG_MAX_DEBUG_DRAW_MODE;
	return true;
}

void PhysicsDraw3D::clearDraw()
{
	_drawNode->clear();
}

void PhysicsDraw3D::destroy()
{
	_drawNode->removeFromParent();
	delete this;
}

drawLine也就簡化了
void PhysicsDraw3D::drawLine(const btVector3& from,const btVector3& to,const btVector3& color)
{
	Vec3 vertices[2] = {
		Vec3(from.x(), from.y(), from.z()),
		Vec3(to.x(), to.y(), to.z())
	};

	_color.r = color.x();
	_color.g = color.y();
	_color.b = color.z();
	_color.a = 1.f;

	_drawNode->drawLine(vertices[0], vertices[1], _color);
}

PhysicsWorld3D 創(chuàng)建的靜態(tài)函數(shù)添加
static PhysicsWorld3D* createWithDebug(Node* layer, const btVector3& gravity = btVector3(0, -10, 0));

為的就是創(chuàng)建調(diào)試繪制
bool PhysicsWorld3D::initWorldWithDebug(Node* layer, const btVector3& gravity)
{
	if (!this->initWorld(gravity))
	{
		return false;
	}

	_debugDraw = PhysicsDraw3D::createWithLayer(layer);
	_world->setDebugDrawer(_debugDraw);
	
	return true;
}

同時刪除initWorld對_debugDraw的創(chuàng)建,每次繪制時須要斷定是否為debug
void PhysicsWorld3D::debugDraw()
{
	if (_debugDraw)
	{
		_debugDraw->clearDraw();
		_world->debugDrawWorld();
	}
}

完全源碼
csdn
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(V3F_C4B_T2F), (GLvoid *)offsetof(V3F_C4B_T2F, vertices));
要將GLProgram::VERTEX_ATTRIB_POSITION, 2 改為 GLProgram::VERTEX_ATTRIB_POSITION, 3

github

相關(guān)案例查看更多