<commit_before>/*
 * SimpleSpriteRenderer.cpp
 *
 *  Created on: Dec 2, 2010
 *      Author: rgreen
 */

#include "SimpleSpriteRenderer.h"
#include "../GameConstants.h"
#include <stdio.h>
#include <string.h>
#include <batterytech/Logger.h>
#include <batterytech/util/esTransform.h>
#include <batterytech/render/GraphicsConfiguration.h>
#include <batterytech/render/RenderContext.h>
#include <batterytech/render/GLResourceManager.h>
#include "../World.h"
#include "../GameContext.h"
#include <batterytech/render/QuadRenderer.h>

SimpleSpriteRenderer::SimpleSpriteRenderer(GameContext *context) {
	this->context = context;
}

SimpleSpriteRenderer::~SimpleSpriteRenderer() {
}

void SimpleSpriteRenderer::init(BOOL32 newContext) {
}

void SimpleSpriteRenderer::render(RenderItem *item) {
	Texture *texture = NULL;
	if (item->textureName[0]) {
		texture = context->glResourceManager->getTexture(item->textureName);
	}
	Matrix4f bbMat;
	BOOL32 isBB = item->renderType == RenderItem::RENDERTYPE_BB;
	if (isBB) {
		// calculate billboard matrix
		Vector3f dir = context->world->camera->pos - item->pos;
		dir.normalize();
		Vector3f newY = context->world->camera->invRotMatrix * Vector3f(0,1,0);
		Vector3f newX = context->world->camera->invRotMatrix * Vector3f(1,0,0);
		bbMat.data[0] = newX.x;
		bbMat.data[1] = newX.y;
		bbMat.data[2] = newX.z;
		bbMat.data[4] = newY.x;
		bbMat.data[5] = newY.y;
		bbMat.data[6] = newY.z;
		bbMat.data[8] = dir.x;
		bbMat.data[9] = dir.y;
		bbMat.data[10] = dir.z;
	}
	context->quadRenderer->render(texture, item->pos, item->orientation.v.z, item->uvs, Vector2f(item->scale.x, item->scale.y), item->colorFilter, item->flags & RENDERITEM_FLAG_IS_OPAQUE, isBB, bbMat);
}

void SimpleSpriteRenderer::startBatch() {
    context->quadRenderer->startBatch();
}

void SimpleSpriteRenderer::endBatch() {
    context->quadRenderer->endBatch();
}<commit_msg>BT2 - fixed BB sprite UV<commit_after>/*
 * SimpleSpriteRenderer.cpp
 *
 *  Created on: Dec 2, 2010
 *      Author: rgreen
 */

#include "SimpleSpriteRenderer.h"
#include "../GameConstants.h"
#include <stdio.h>
#include <string.h>
#include <batterytech/Logger.h>
#include <batterytech/util/esTransform.h>
#include <batterytech/render/GraphicsConfiguration.h>
#include <batterytech/render/RenderContext.h>
#include <batterytech/render/GLResourceManager.h>
#include "../World.h"
#include "../GameContext.h"
#include <batterytech/render/QuadRenderer.h>

SimpleSpriteRenderer::SimpleSpriteRenderer(GameContext *context) {
	this->context = context;
}

SimpleSpriteRenderer::~SimpleSpriteRenderer() {
}

void SimpleSpriteRenderer::init(BOOL32 newContext) {
}

void SimpleSpriteRenderer::render(RenderItem *item) {
	Texture *texture = NULL;
	if (item->textureName[0]) {
		texture = context->glResourceManager->getTexture(item->textureName);
	}
	Matrix4f bbMat;
	BOOL32 isBB = item->renderType == RenderItem::RENDERTYPE_BB;
	Vector4f newUvs = item->uvs;
	if (isBB) {
		// calculate billboard matrix
		Vector3f dir = context->world->camera->pos - item->pos;
		dir.normalize();
		Vector3f newY = context->world->camera->invRotMatrix * Vector3f(0,1,0);
		Vector3f newX = context->world->camera->invRotMatrix * Vector3f(1,0,0);
		bbMat.data[0] = newX.x;
		bbMat.data[1] = newX.y;
		bbMat.data[2] = newX.z;
		bbMat.data[4] = newY.x;
		bbMat.data[5] = newY.y;
		bbMat.data[6] = newY.z;
		bbMat.data[8] = dir.x;
		bbMat.data[9] = dir.y;
		bbMat.data[10] = dir.z;
		// uvs will need flipping to avoid switching to LHS to flip Y
		newUvs.y = newUvs.w;
		newUvs.w = item->uvs.y;
	}
	context->quadRenderer->render(texture, item->pos, item->orientation.v.z, newUvs, Vector2f(item->scale.x, item->scale.y), item->colorFilter, item->flags & RENDERITEM_FLAG_IS_OPAQUE, isBB, bbMat);
}

void SimpleSpriteRenderer::startBatch() {
    context->quadRenderer->startBatch();
}

void SimpleSpriteRenderer::endBatch() {
    context->quadRenderer->endBatch();
}
{'fraction_non_alphanumeric': 0.16150499104172, 'fraction_numerical': 0.017404658305605322, 'mean_word_length': 4.939209726443769, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 78, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2365896', 'n_tokens_mistral': 1471, 'n_tokens_neox': 1432, 'n_words': 243}