<commit_before>/* BZWorkbench
 * Copyright (c) 1993 - 2008 <NAME>
 *
 * This package is free software;  you can redistribute it and/or
 * modify it under the terms of the license found in the file
 * named COPYING that should have accompanied this file.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#include "objects/sphere.h"

#ifndef M_PI
#define M_PI           3.14159265358979323846
#endif

const char* sphere::sideNames[MaterialCount] = { "edge", "bottom" };

sphere::sphere() :
bz2object("sphere", "<position><rotation><size><radius><flatshading><name><divisions><shift><shear><spin><scale><smoothbounce><phydrv><matref><hemisphere><drivethrough><shootthrough><passable>" ) {
	setDefaults();
}

void sphere::setDefaults() {
	osg::Group* group = new osg::Group();
	osg::Geode* outside = new osg::Geode();
	osg::Geode* bottom = new osg::Geode();
	group->addChild( outside );
	group->addChild( bottom );
	setThisNode( group );

	SceneBuilder::assignTexture( "boxwall", group->getChild( 0 ) );
	SceneBuilder::assignTexture( "roof", group->getChild( 1 ) );

	MaterialSlot mslotEdge;
	mslotEdge.defaultMaterial = group->getChild( 0 )->getStateSet();
	mslotEdge.node = group->getChild( 0 );
	MaterialSlot mslotBottom;
	mslotBottom.defaultMaterial = group->getChild( 1 )->getStateSet();
	mslotBottom.node = group->getChild( 1 );

	materialSlots[ string( sideNames[ 0 ] ) ] = mslotEdge;
	materialSlots[ string( sideNames[ 1 ] ) ] = mslotBottom;

	// define some basic values
	realSize = osg::Vec3( 10, 10, 10 );
	texsize.set( -4.0f, -4.0f );
	divisions = 16;
	hemisphere = false;

	updateGeometry();
}

// getter
string sphere::get(void) { return toString(); }

int sphere::update(UpdateMessage& message) {
	int result = bz2object::update( message );

	switch( message.type ) {
		case UpdateMessage::SET_POSITION: 	// handle a new position
			setPos( *(message.getAsPosition()) );
			break;

		case UpdateMessage::SET_POSITION_FACTOR:	// handle a translation
			setPos( getPos() + *(message.getAsPositionFactor()) );
			break;

		case UpdateMessage::SET_ROTATION:		// handle a new rotation
			setRotationZ( message.getAsRotation()->z() );
			break;

		case UpdateMessage::SET_ROTATION_FACTOR:	// handle an angular translation
			setRotationZ( getRotation().z() + message.getAsRotationFactor()->z() );
			break;

		case UpdateMessage::SET_SCALE:		// handle a new scale
			setSize( *(message.getAsScale()) );
			break;

		case UpdateMessage::SET_SCALE_FACTOR:	// handle a scaling factor
			setSize( getSize() + *(message.getAsScaleFactor()) );
			break;

		case UpdateMessage::REMOVE_MATERIAL: {
			material* mat = message.getAsMaterial();
			for ( int i = 0; i < MaterialCount; i++ ) 
				if ( ((osg::Group*)getThisNode())->getStateSet() == mat )
					((osg::Group*)getThisNode())->setStateSet( NULL );
			break;
		}

		default:	// unknown event; don't handle
			return result;
	}

	return 1;
}

// bzw methods
bool sphere::parse( std::string& line ) {
	// check if we reached the end of the section
	if ( line == "end" )
		return false;

	string key = BZWParser::key( line.c_str() );
	string value = BZWParser::value( key.c_str(), line.c_str() );

	// parse keys
	if ( key == "divisions" ) {
		divisions = atof( value.c_str() );
	}
	else if ( key == "radius" ) {
		float r = atof( value.c_str() );
		realSize = Point3D( r, r, r );<commit_msg>- added "texsize" to sphere object's parser<commit_after>/* BZWorkbench
 * Copyright (c) 1993 - 2008 <NAME>
 *
 * This package is free software;  you can redistribute it and/or
 * modify it under the terms of the license found in the file
 * named COPYING that should have accompanied this file.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#include "objects/sphere.h"

#ifndef M_PI
#define M_PI           3.14159265358979323846
#endif

const char* sphere::sideNames[MaterialCount] = { "edge", "bottom" };

sphere::sphere() :
bz2object("sphere", "<position><rotation><size><radius><flatshading><name><divisions><shift><shear><spin><scale><smoothbounce><phydrv><matref><hemisphere><drivethrough><shootthrough><passable><texsize>" ) {
	setDefaults();
}

void sphere::setDefaults() {
	osg::Group* group = new osg::Group();
	osg::Geode* outside = new osg::Geode();
	osg::Geode* bottom = new osg::Geode();
	group->addChild( outside );
	group->addChild( bottom );
	setThisNode( group );

	SceneBuilder::assignTexture( "boxwall", group->getChild( 0 ) );
	SceneBuilder::assignTexture( "roof", group->getChild( 1 ) );

	MaterialSlot mslotEdge;
	mslotEdge.defaultMaterial = group->getChild( 0 )->getStateSet();
	mslotEdge.node = group->getChild( 0 );
	MaterialSlot mslotBottom;
	mslotBottom.defaultMaterial = group->getChild( 1 )->getStateSet();
	mslotBottom.node = group->getChild( 1 );

	materialSlots[ string( sideNames[ 0 ] ) ] = mslotEdge;
	materialSlots[ string( sideNames[ 1 ] ) ] = mslotBottom;

	// define some basic values
	realSize = osg::Vec3( 10, 10, 10 );
	texsize.set( -4.0f, -4.0f );
	divisions = 16;
	hemisphere = false;

	updateGeometry();
}

// getter
string sphere::get(void) { return toString(); }

int sphere::update(UpdateMessage& message) {
	int result = bz2object::update( message );

	switch( message.type ) {
		case UpdateMessage::SET_POSITION: 	// handle a new position
			setPos( *(message.getAsPosition()) );
			break;

		case UpdateMessage::SET_POSITION_FACTOR:	// handle a translation
			setPos( getPos() + *(message.getAsPositionFactor()) );
			break;

		case UpdateMessage::SET_ROTATION:		// handle a new rotation
			setRotationZ( message.getAsRotation()->z() );
			break;

		case UpdateMessage::SET_ROTATION_FACTOR:	// handle an angular translation
			setRotationZ( getRotation().z() + message.getAsRotationFactor()->z() );
			break;

		case UpdateMessage::SET_SCALE:		// handle a new scale
			setSize( *(message.getAsScale()) );
			break;

		case UpdateMessage::SET_SCALE_FACTOR:	// handle a scaling factor
			setSize( getSize() + *(message.getAsScaleFactor()) );
			break;

		case UpdateMessage::REMOVE_MATERIAL: {
			material* mat = message.getAsMaterial();
			for ( int i = 0; i < MaterialCount; i++ ) 
				if ( ((osg::Group*)getThisNode())->getStateSet() == mat )
					((osg::Group*)getThisNode())->setStateSet( NULL );
			break;
		}

		default:	// unknown event; don't handle
			return result;
	}

	return 1;
}

// bzw methods
bool sphere::parse( std::string& line ) {
	// check if we reached the end of the section
	if ( line == "end" )
		return false;

	string key = BZWParser::key( line.c_str() );
	string value = BZWParser::value( key.c_str(), line.c_str() );

	// parse keys
	if ( key == "texsize" ) {
		texsize = Point2D( value.c_str() );
	}
	else if ( key == "divisions" ) {
		divisions = atof( value.c_str() );
	}
	else if ( key == "radius" ) {
		float r = atof( value.c_str() );
		realSize = Point3D( r, r, r );
{'fraction_non_alphanumeric': 0.15098314606741572, 'fraction_numerical': 0.015589887640449438, 'mean_word_length': 4.3581640331076, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 70, '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': '4786763', 'n_tokens_mistral': 2566, 'n_tokens_neox': 2336, 'n_words': 615}