<commit_before>/*
 * Copyright (c) 2016. See AUTHORS file.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.mbrlabs.mundus.tools;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.VertexAttributes;
import com.badlogic.gdx.graphics.g3d.Material;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.Shader;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.utils.viewport.Viewport;
import com.mbrlabs.mundus.commons.scene3d.GameObject;
import com.mbrlabs.mundus.commons.utils.MathUtils;
import com.mbrlabs.mundus.core.Mundus;
import com.mbrlabs.mundus.core.project.ProjectContext;
import com.mbrlabs.mundus.core.project.ProjectManager;
import com.mbrlabs.mundus.history.CommandHistory;
import com.mbrlabs.mundus.shader.Shaders;
import com.mbrlabs.mundus.tools.picker.GameObjectPicker;
import com.mbrlabs.mundus.tools.picker.ToolHandlePicker;
import com.mbrlabs.mundus.utils.Fa;
import com.mbrlabs.mundus.utils.Log;
import org.lwjgl.opengl.GL11;

/**
 * @author codenigma
 * @version 03-10-2016
 */
public class ScaleTool extends TransformTool {

    public static final String NAME = "Scale Tool";

    private final ScaleHandle xHandle;
    private final ScaleHandle yHandle;
    private final ScaleHandle zHandle;
    private final ScaleHandle xyzHandle;
    private final ScaleHandle[] handles;

    private final Matrix4 shapeRenderMat = new Matrix4();

    private final Vector3 temp0 = new Vector3();
    private final Vector3 temp1 = new Vector3();
    private final Vector3 tempScale = new Vector3();
    private float temp100ScaleDst = 0;


    private ShapeRenderer shapeRenderer;
    private ProjectContext projectContext;

    private TransformState state = TransformState.IDLE;
    

       public ScaleTool(ProjectManager projectManager, GameObjectPicker goPicker, ToolHandlePicker handlePicker, Shader shader, 
               ShapeRenderer shapeRenderer, ModelBatch batch, CommandHistory history) {
        super(projectManager, goPicker, handlePicker, shader, batch, history);
    
        this.shapeRenderer = shapeRenderer;
        this.projectContext = projectManager.current();
        
        ModelBuilder modelBuilder = new ModelBuilder();
        
        Model xPlaneHandleModel = modelBuilder.createBox(1, 1, 1,
                new Material(ColorAttribute.createDiffuse(COLOR_X)),
                VertexAttributes.Usage.Position);
        Model yPlaneHandleModel = modelBuilder.createBox(1, 1, 1,
                new Material(ColorAttribute.createDiffuse(COLOR_Y)),
                VertexAttributes.Usage.Position);
        Model zPlaneHandleModel = modelBuilder.createBox(1, 1, 1,
                new Material(ColorAttribute.createDiffuse(COLOR_Z)),
                VertexAttributes.Usage.Position);      
        Model xyzPlaneHandleModel = modelBuilder.createBox(1, 1, 1,
                new Material(ColorAttribute.createDiffuse(COLOR_XYZ)),
                VertexAttributes.Usage.Position);
        
        xHandle = new ScaleHandle(X_HANDLE_ID, xPlaneHandleModel);
        yHandle = new ScaleHandle(Y_HANDLE_ID, yPlaneHandleModel);
        zHandle = new ScaleHandle(Z_HANDLE_ID, zPlaneHandleModel);
        xyzHandle = new ScaleHandle(XYZ_HANDLE_ID, xyzPlaneHandleModel);
        
        handles = new ScaleHandle[]{xHandle, yHandle, zHandle, xyzHandle};
    }

    @Override
    public void render() {
        super.render();

        GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
        if(state == TransformState.IDLE && projectContext.currScene.currentSelection != null) {
            batch.begin(projectContext.currScene.cam);
            xHandle.render(batch);
            yHandle.render(batch);
            zHandle.render(batch);
            xyzHandle.render(batch);
            batch.end();
        } else if(projectContext.currScene.currentSelection != null) {
            Viewport vp = projectContext.currScene.viewport;

            GameObject go = projectContext.currScene.currentSelection;
            go.getTransform().getTranslation(temp0);
            Vector3 pivot = projectContext.currScene.cam.project(temp0);

            shapeRenderMat.setToOrtho2D(vp.getScreenX(), vp.getScreenY(), vp.getScreenWidth(), vp.getScreenHeight());
            switch(state) {
                case TRANSFORM_X : 
                    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
                    shapeRenderer.setColor(Color.BLACK);
                    shapeRenderer.setProjectionMatrix(shapeRenderMat);
                    shapeRenderer.rectLine(pivot.x, pivot.y, Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY(), 2);
                    shapeRenderer.setColor(COLOR_X);
                    shapeRenderer.box(pivot.x, pivot.y, pivot.z, 5, 5, 5);
                    shapeRenderer.end();
                    break;
                case TRANSFORM_Y : 
                    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
                    shapeRenderer.setColor(Color.BLACK);
                    shapeRenderer.setProjectionMatrix(shapeRenderMat);
                    shapeRenderer.rectLine(pivot.x, pivot.y, Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY(), 2);
                    shapeRenderer.setColor(COLOR_Y);
                    shapeRenderer.box(pivot.x, pivot.y, pivot.z, 5, 5, 5);
                    shapeRenderer.end();
                    break;
                case TRANSFORM_Z : 
                    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
                    shapeRenderer.setColor(Color.BLACK);
                    shapeRenderer.setProjectionMatrix(shapeRenderMat);
                    shapeRenderer.rectLine(pivot.x, pivot.y, Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY(), 2);
                    shapeRenderer.setColor(COLOR_Z);
                    shapeRenderer.box(pivot.x, pivot.y, pivot.z, 5, 5, 5);
                    shapeRenderer.end();
                    break;
                case TRANSFORM_XYZ : 
                    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
                    shapeRenderer.setColor(Color.BLACK);
                    shapeRenderer.setProjectionMatrix(shapeRenderMat);
                    shapeRenderer.rectLine(pivot.x, pivot.y, Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY(), 2);
                    shapeRenderer.setColor(COLOR_XYZ);
                    shapeRenderer.box(pivot.x, pivot.y, pivot.z, 5, 5, 5);
                    shapeRenderer.end();
                    break;
                default:
                    break;
            }
        }<commit_msg>- pivot scaling box now visible<commit_after>/*
 * Copyright (c) 2016. See AUTHORS file.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.mbrlabs.mundus.tools;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.VertexAttributes;
import com.badlogic.gdx.graphics.g3d.Material;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.Shader;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.utils.viewport.Viewport;
import com.mbrlabs.mundus.commons.scene3d.GameObject;
import com.mbrlabs.mundus.commons.utils.MathUtils;
import com.mbrlabs.mundus.core.Mundus;
import com.mbrlabs.mundus.core.project.ProjectContext;
import com.mbrlabs.mundus.core.project.ProjectManager;
import com.mbrlabs.mundus.history.CommandHistory;
import com.mbrlabs.mundus.shader.Shaders;
import com.mbrlabs.mundus.tools.picker.GameObjectPicker;
import com.mbrlabs.mundus.tools.picker.ToolHandlePicker;
import com.mbrlabs.mundus.utils.Fa;
import com.mbrlabs.mundus.utils.Log;
import org.lwjgl.opengl.GL11;

/**
 * @author codenigma
 * @version 03-10-2016
 */
public class ScaleTool extends TransformTool {

    public static final String NAME = "Scale Tool";

    private final ScaleHandle xHandle;
    private final ScaleHandle yHandle;
    private final ScaleHandle zHandle;
    private final ScaleHandle xyzHandle;
    private final ScaleHandle[] handles;

    private final Matrix4 shapeRenderMat = new Matrix4();

    private final Vector3 temp0 = new Vector3();
    private final Vector3 temp1 = new Vector3();
    private final Vector3 tempScale = new Vector3();
    private float temp100ScaleDst = 0;


    private ShapeRenderer shapeRenderer;
    private ProjectContext projectContext;

    private TransformState state = TransformState.IDLE;
    

       public ScaleTool(ProjectManager projectManager, GameObjectPicker goPicker, ToolHandlePicker handlePicker, Shader shader, 
               ShapeRenderer shapeRenderer, ModelBatch batch, CommandHistory history) {
        super(projectManager, goPicker, handlePicker, shader, batch, history);
    
        this.shapeRenderer = shapeRenderer;
        this.projectContext = projectManager.current();
        
        ModelBuilder modelBuilder = new ModelBuilder();
        
        Model xPlaneHandleModel = modelBuilder.createBox(1, 1, 1,
                new Material(ColorAttribute.createDiffuse(COLOR_X)),
                VertexAttributes.Usage.Position);
        Model yPlaneHandleModel = modelBuilder.createBox(1, 1, 1,
                new Material(ColorAttribute.createDiffuse(COLOR_Y)),
                VertexAttributes.Usage.Position);
        Model zPlaneHandleModel = modelBuilder.createBox(1, 1, 1,
                new Material(ColorAttribute.createDiffuse(COLOR_Z)),
                VertexAttributes.Usage.Position);      
        Model xyzPlaneHandleModel = modelBuilder.createBox(1, 1, 1,
                new Material(ColorAttribute.createDiffuse(COLOR_XYZ)),
                VertexAttributes.Usage.Position);
        
        xHandle = new ScaleHandle(X_HANDLE_ID, xPlaneHandleModel);
        yHandle = new ScaleHandle(Y_HANDLE_ID, yPlaneHandleModel);
        zHandle = new ScaleHandle(Z_HANDLE_ID, zPlaneHandleModel);
        xyzHandle = new ScaleHandle(XYZ_HANDLE_ID, xyzPlaneHandleModel);
        
        handles = new ScaleHandle[]{xHandle, yHandle, zHandle, xyzHandle};
    }

    @Override
    public void render() {
        super.render();

        GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
        if(state == TransformState.IDLE && projectContext.currScene.currentSelection != null) {
            batch.begin(projectContext.currScene.cam);
            xHandle.render(batch);
            yHandle.render(batch);
            zHandle.render(batch);
            xyzHandle.render(batch);
            batch.end();
        } else if(projectContext.currScene.currentSelection != null) {
            Viewport vp = projectContext.currScene.viewport;

            GameObject go = projectContext.currScene.currentSelection;
            go.getTransform().getTranslation(temp0);
            Vector3 pivot = projectContext.currScene.cam.project(temp0);

            shapeRenderMat.setToOrtho2D(vp.getScreenX(), vp.getScreenY(), vp.getScreenWidth(), vp.getScreenHeight());
            switch(state) {
                case TRANSFORM_X : 
                    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
                    shapeRenderer.setColor(Color.BLACK);
                    shapeRenderer.setProjectionMatrix(shapeRenderMat);
                    shapeRenderer.rectLine(pivot.x, pivot.y, Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY(), 2);
                    shapeRenderer.setColor(COLOR_X);
                    shapeRenderer.box(pivot.x, pivot.y, 0, 10, 10, 10);
                    shapeRenderer.end();
                    break;
                case TRANSFORM_Y : 
                    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
                    shapeRenderer.setColor(Color.BLACK);
                    shapeRenderer.setProjectionMatrix(shapeRenderMat);
                    shapeRenderer.rectLine(pivot.x, pivot.y, Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY(), 2);
                    shapeRenderer.setColor(COLOR_Y);
                    shapeRenderer.box(pivot.x, pivot.y, 0, 10, 10, 10);
                    shapeRenderer.end();
                    break;
                case TRANSFORM_Z : 
                    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
                    shapeRenderer.setColor(Color.BLACK);
                    shapeRenderer.setProjectionMatrix(shapeRenderMat);
                    shapeRenderer.rectLine(pivot.x, pivot.y, Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY(), 2);
                    shapeRenderer.setColor(COLOR_Z);
                    shapeRenderer.box(pivot.x, pivot.y, 0, 10, 10, 10);
                    shapeRenderer.end();
                    break;
                case TRANSFORM_XYZ : 
                    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
                    shapeRenderer.setColor(Color.BLACK);
                    shapeRenderer.setProjectionMatrix(shapeRenderMat);
                    shapeRenderer.rectLine(pivot.x, pivot.y, Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY(), 2);
                    shapeRenderer.setColor(COLOR_XYZ);
                    shapeRenderer.box(pivot.x, pivot.y, 0, 10, 10, 10);
                    shapeRenderer.end();
                    break;
                default:
                    break;
            }
        }
{'fraction_non_alphanumeric': 0.0956504494976203, 'fraction_numerical': 0.011501850872554203, 'mean_word_length': 2.5690021231422504, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '823645', 'n_tokens_mistral': 4539, 'n_tokens_neox': 4185, 'n_words': 837}