<commit_before>// Copyright (C) 2016 <NAME>
// This file is part of the Ouzel engine.

#include <rapidjson/rapidjson.h>
#include <rapidjson/filereadstream.h>
#include <rapidjson/document.h>
#include "CompileConfig.h"
#include "ParticleSystem.h"
#include "Engine.h"
#include "SceneManager.h"
#include "FileSystem.h"
#include "File.h"
#include "Cache.h"
#include "Layer.h"
#include "Camera.h"
#include "MeshBuffer.h"
#include "Utils.h"
#include "MathUtils.h"

namespace ouzel
{
    std::shared_ptr<ParticleSystem> ParticleSystem::createFromFile(const std::string& filename)
    {
        std::shared_ptr<ParticleSystem> result = std::make_shared<ParticleSystem>();
        
        if (!result->initFromFile(filename))
        {
            result.reset();
        }
        
        return result;
    }
    
    ParticleSystem::ParticleSystem()
    {
        _shader = Engine::getInstance()->getCache()->getShader(SHADER_TEXTURE);
        
#ifdef OUZEL_PLATFORM_WINDOWS
        _uniModelViewProj = 0;
#else
        _uniModelViewProj = _shader->getVertexShaderConstantId("modelViewProj");
#endif
    }
    
    ParticleSystem::~ParticleSystem()
    {
        
    }
    
    void ParticleSystem::draw()
    {
        Node::draw();
        
        LayerPtr layer = _layer.lock();
        
        if (_shader && _texture && layer && _particleCount)
        {
            if (_needsMeshUpdate)
            {
                updateParticleMesh();
                _needsMeshUpdate = false;
            }
            
            Engine::getInstance()->getRenderer()->activateTexture(_texture, 0);
            Engine::getInstance()->getRenderer()->activateShader(_shader);
            
            Matrix4 transform;
            
            if (_positionType == PositionType::FREE || _positionType == PositionType::RELATIVE)
            {
                transform = layer->getCamera()->getViewProjection();
            }
            else if (_positionType == PositionType::GROUPED)
            {
                transform = layer->getCamera()->getViewProjection() * getTransform();
            }
            
            _shader->setVertexShaderConstant(_uniModelViewProj, { transform });
            
            Engine::getInstance()->getRenderer()->drawMeshBuffer(_mesh, _particleCount * 6);
        }
    }
    <commit_msg>Correctly calculate particle system's bounding box<commit_after>// Copyright (C) 2016 <NAME>
// This file is part of the Ouzel engine.

#include <rapidjson/rapidjson.h>
#include <rapidjson/filereadstream.h>
#include <rapidjson/document.h>
#include "CompileConfig.h"
#include "ParticleSystem.h"
#include "Engine.h"
#include "SceneManager.h"
#include "FileSystem.h"
#include "File.h"
#include "Cache.h"
#include "Layer.h"
#include "Camera.h"
#include "MeshBuffer.h"
#include "Utils.h"
#include "MathUtils.h"

namespace ouzel
{
    std::shared_ptr<ParticleSystem> ParticleSystem::createFromFile(const std::string& filename)
    {
        std::shared_ptr<ParticleSystem> result = std::make_shared<ParticleSystem>();
        
        if (!result->initFromFile(filename))
        {
            result.reset();
        }
        
        return result;
    }
    
    ParticleSystem::ParticleSystem()
    {
        _shader = Engine::getInstance()->getCache()->getShader(SHADER_TEXTURE);
        
#ifdef OUZEL_PLATFORM_WINDOWS
        _uniModelViewProj = 0;
#else
        _uniModelViewProj = _shader->getVertexShaderConstantId("modelViewProj");
#endif
    }
    
    ParticleSystem::~ParticleSystem()
    {
        
    }
    
    void ParticleSystem::draw()
    {
        Node::draw();
        
        LayerPtr layer = _layer.lock();
        
        if (_shader && _texture && layer && _particleCount)
        {
            if (_needsMeshUpdate)
            {
                updateParticleMesh();
                _needsMeshUpdate = false;
            }
            
            Engine::getInstance()->getRenderer()->activateTexture(_texture, 0);
            Engine::getInstance()->getRenderer()->activateShader(_shader);
            
            _boundingBox.reset();
            
            Matrix4 transform;
            
            if (_positionType == PositionType::FREE || _positionType == PositionType::RELATIVE)
            {
                transform = layer->getCamera()->getViewProjection();
                
                const Matrix4& inverseTransform = getInverseTransform();
                
                for (int32_t i = 0; i < _particleCount; i++)
                {
                    Vector3 position = _particles[i].position;
                    inverseTransform.transformPoint(position);
                    _boundingBox.insertPoint(Vector2(position.x, position.y));
                }
            }
            else if (_positionType == PositionType::GROUPED)
            {
                transform = layer->getCamera()->getViewProjection() * getTransform();
                
                for (int32_t i = 0; i < _particleCount; i++)
                {
                    _boundingBox.insertPoint(_particles[i].position);
                }
            }
            
            _shader->setVertexShaderConstant(_uniModelViewProj, { transform });
            
            Engine::getInstance()->getRenderer()->drawMeshBuffer(_mesh, _particleCount * 6);
        }
    }
    
{'fraction_non_alphanumeric': 0.11774647887323944, 'fraction_numerical': 0.004694835680751174, 'mean_word_length': 2.015855039637599, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 47, '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': '6781046', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1454, 'n_words': 249}