<commit_before>#include "view/RemoteSkidmarkView.h"

#include <OgreRoot.h>
#include <OgreBillboardSet.h>
#include <OgreBillboard.h>

#include <sstream>
#include <string>

namespace Rally { namespace View {


	RemoteSkidmarkView::RemoteSkidmarkView() {}

	RemoteSkidmarkView::~RemoteSkidmarkView() {}

	void RemoteSkidmarkView::attachTo(Ogre::SceneManager* sceneManager){
		skidmarkNode = sceneManager->getRootSceneNode()->createChildSceneNode();

		Ogre::BillboardType type = Ogre::BillboardType::BBT_PERPENDICULAR_SELF;
		Ogre::BillboardRotationType rotationType = Ogre::BillboardRotationType::BBR_VERTEX;
		Rally::Vector3 up(0, 0, 1);
		Rally::Vector3 common(0, 1, 0);

		skidmarkBillboards = sceneManager->createBillboardSet();
		skidmarkBillboards->setMaterialName("skidmark");
		skidmarkBillboards->setVisible(true);
		skidmarkBillboards->setBillboardType(type);
		skidmarkBillboards->setBillboardRotationType(rotationType);
		skidmarkBillboards->setCommonUpVector(up);
		skidmarkBillboards->setCommonDirection(common);
		skidmarkBillboards->setBillboardsInWorldSpace(true);
		skidmarkBillboards->setDefaultDimensions(Ogre::Real(0.2), Ogre::Real(0.4));
		skidmarkBillboards->setAutoextend(true);

		skidmarkNode->attachObject(skidmarkBillboards);
	}

	void RemoteSkidmarkView::update(const Rally::Model::RemoteCar& car){
        float tractionReq = 0.1f;

        float speed = car.getVelocity().length();

        float heightOffset = -1.0f;

        Rally::Vector3 direction = car.getVelocity().normalisedCopy();
        
        if(car.getTractionVector().x < tractionReq){
            createSkidmark(car.getPosition() + Ogre::Vector3(0.7f, heightOffset, 1.50f), 
                Rally::Vector3(0, 1, 0), direction, car.getTractionVector().x, speed);
        }
        if(car.getTractionVector().y < tractionReq){
			createSkidmark(car.getPosition() + Ogre::Vector3(-0.7f, heightOffset, 1.50f), 
                Rally::Vector3(0, 1, 0), direction, car.getTractionVector().y, speed);
        }
        if(car.getTractionVector().z < tractionReq){
			createSkidmark(car.getPosition() + Ogre::Vector3(0.7f, heightOffset, -1.25f), 
                Rally::Vector3(0, 1, 0), direction, car.getTractionVector().z, speed);
        }
        if(car.getTractionVector().w < tractionReq){
			createSkidmark(car.getPosition() + Ogre::Vector3(-0.7f, heightOffset, -1.25f), 
                Rally::Vector3(0, 1, 0), direction, car.getTractionVector().w, speed);
        }
        
	}

	void RemoteSkidmarkView::createSkidmark(Rally::Vector3 position, Rally::Vector3 normal, Rally::Vector3 direction, float traction, float speed){
		Ogre::Billboard* b = skidmarkBillboards->createBillboard(Rally::Vector3(position.x, position.y+0.05f, position.z), 
			Ogre::ColourValue::Black);
        
        double lengthAdjust = 0.008;
        float alphaAdjust = 4.0f;

        b->setDimensions(Ogre::Real(0.2), Ogre::Real(Ogre::Math::Clamp(lengthAdjust*speed, 0.15, 1.0)));
        b->setColour(Ogre::ColourValue(1.0, 1.0, 1.0, traction*alphaAdjust));

		b->mDirection = normal;

		direction.y = 0;

		Ogre::Radian r = direction.angleBetween(Rally::Vector3(0, 0, 1));

		if(direction.z > 0 && direction.x > 0){
			r =  Ogre::Radian(Ogre::Math::PI*2) - r;
		}

		if(direction.z < 0 && direction.x > 0){
			r *= -1;
		}<commit_msg>Skidmark positions are now more accurate<commit_after>#include "view/RemoteSkidmarkView.h"

#include <OgreRoot.h>
#include <OgreBillboardSet.h>
#include <OgreBillboard.h>

#include <sstream>
#include <string>

namespace Rally { namespace View {


	RemoteSkidmarkView::RemoteSkidmarkView() {}

	RemoteSkidmarkView::~RemoteSkidmarkView() {}

	void RemoteSkidmarkView::attachTo(Ogre::SceneManager* sceneManager){
		skidmarkNode = sceneManager->getRootSceneNode()->createChildSceneNode();

		Ogre::BillboardType type = Ogre::BillboardType::BBT_PERPENDICULAR_SELF;
		Ogre::BillboardRotationType rotationType = Ogre::BillboardRotationType::BBR_VERTEX;
		Rally::Vector3 up(0, 0, 1);
		Rally::Vector3 common(0, 1, 0);

		skidmarkBillboards = sceneManager->createBillboardSet();
		skidmarkBillboards->setMaterialName("skidmark");
		skidmarkBillboards->setVisible(true);
		skidmarkBillboards->setBillboardType(type);
		skidmarkBillboards->setBillboardRotationType(rotationType);
		skidmarkBillboards->setCommonUpVector(up);
		skidmarkBillboards->setCommonDirection(common);
		skidmarkBillboards->setBillboardsInWorldSpace(true);
		skidmarkBillboards->setDefaultDimensions(Ogre::Real(0.15), Ogre::Real(0.4));
		skidmarkBillboards->setAutoextend(true);

		skidmarkNode->attachObject(skidmarkBillboards);
	}

	void RemoteSkidmarkView::update(const Rally::Model::RemoteCar& car){
        float tractionReq = 0.1f;

        float speed = car.getVelocity().length();

        float heightOffset = -1.0f;
        float xOffset = 0.60f;
        float zOffsetFront = 1.50f;
        float zOffsetBack = -1.25f;

        Rally::Vector3 direction = car.getVelocity().normalisedCopy();

        Rally::Vector3 normal(0, 1, 0);
        
        // Right front
        if(car.getTractionVector().x < tractionReq){
            createSkidmark(car.getPosition() + Ogre::Vector3(xOffset, heightOffset, zOffsetFront), 
                normal, direction, car.getTractionVector().x, speed);
        }
        // Left front
        if(car.getTractionVector().y < tractionReq){
			createSkidmark(car.getPosition() + Ogre::Vector3(-xOffset, heightOffset, zOffsetFront), 
                normal, direction, car.getTractionVector().y, speed);
        }
        // Right back
        if(car.getTractionVector().z < tractionReq){
			createSkidmark(car.getPosition() + Ogre::Vector3(xOffset, heightOffset, zOffsetBack), 
                normal, direction, car.getTractionVector().z, speed);
        }
        // Left back
        if(car.getTractionVector().w < tractionReq){
			createSkidmark(car.getPosition() + Ogre::Vector3(-xOffset, heightOffset, zOffsetBack), 
                normal, direction, car.getTractionVector().w, speed);
        }
        
	}

	void RemoteSkidmarkView::createSkidmark(Rally::Vector3 position, Rally::Vector3 normal, Rally::Vector3 direction, float traction, float speed){
		Ogre::Billboard* b = skidmarkBillboards->createBillboard(Rally::Vector3(position.x, position.y+0.05f, position.z), 
			Ogre::ColourValue::Black);
        
        double lengthAdjust = 0.012;
        float alphaAdjust = 4.0f;

        b->setDimensions(Ogre::Real(0.2), Ogre::Real(Ogre::Math::Clamp(lengthAdjust*speed, 0.15, 1.0)));
        b->setColour(Ogre::ColourValue(1.0, 1.0, 1.0, traction*alphaAdjust));

		b->mDirection = normal;

		direction.y = 0;

		Ogre::Radian r = direction.angleBetween(Rally::Vector3(0, 0, 1));

		if(direction.z > 0 && direction.x > 0){
			r =  Ogre::Radian(Ogre::Math::PI*2) - r;
		}

		if(direction.z < 0 && direction.x > 0){
			r *= -1;
		}
{'fraction_non_alphanumeric': 0.14312810037934054, 'fraction_numerical': 0.02421943390720747, 'mean_word_length': 4.11949215832711, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 53, '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': '7464039', 'n_tokens_mistral': 2456, 'n_tokens_neox': 2273, 'n_words': 352}