blob: 42095b0dafb4a3c810a3d335728d80763e64b6f0 [file] [log] [blame]
package org.eclipse.apogy.addons.sensors.fov.ui.jme3.utils;
/*******************************************************************************
* Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pierre Allard - initial API and implementation
* Regent L'Archeveque
* SPDX-License-Identifier: EPL-1.0
*******************************************************************************/
import java.awt.image.BufferedImage;
import org.eclipse.apogy.addons.sensors.fov.RectangularFrustrumFieldOfView;
import org.eclipse.apogy.addons.sensors.fov.ui.jme3.scene_objects.ProjectorData;
import org.eclipse.apogy.common.images.AbstractEImage;
import org.eclipse.apogy.common.images.EImagesUtilities;
import org.eclipse.apogy.common.topology.ui.jme3.JME3Application;
import org.eclipse.swt.graphics.RGB;
import com.jme3.renderer.Camera;
public class RectangularFrustrumFieldOfViewImageProjectorControl
extends AbstractFieldOfViewImageProjectorControl<RectangularFrustrumFieldOfView> {
public RectangularFrustrumFieldOfViewImageProjectorControl(JME3Application jme3Application,
RectangularFrustrumFieldOfView fieldOfView) {
super(jme3Application, fieldOfView);
}
@Override
public float getHorizontalFOVAngleDegrees() {
return (float) Math.toDegrees(this.fieldOfView.getHorizontalFieldOfViewAngle());
}
@Override
public float getTextureHtoVRatio() {
float ratio = 1.0f;
if (this.fieldOfView != null) {
if (this.fieldOfView.getHorizontalFieldOfViewAngle() > 0
&& this.fieldOfView.getVerticalFieldOfViewAngle() > 0) {
ratio = (float) (this.fieldOfView.getHorizontalFieldOfViewAngle()
/ this.fieldOfView.getVerticalFieldOfViewAngle());
}
}
return ratio;
}
@Override
public BufferedImage getProjectedImage() {
int width = 256;
int height = Math.round(width * getTextureHtoVRatio());
AbstractEImage transparentImage = EImagesUtilities.INSTANCE.createTransparentImage(width, height);
RGB projColor = getProjectionColor();
AbstractEImage borderedImage = EImagesUtilities.INSTANCE.addBorder(transparentImage, 4, projColor.red,
projColor.green, projColor.blue);
return borderedImage.asBufferedImage();
}
@Override
public void updateProjectorFOVSettings() {
ProjectorData projectorData = getProjectorData();
// Updates the texture.
projectorData.projector.setProjectiveTextureMap(createTexture());
Camera projectorCamera = projectorData.projector.getProjectorCamera();
projectorCamera.setLocation(getProjectorLocation());
projectorCamera.setRotation(getProjectorRotation());
if (getHorizontalFOVAngleDegrees() > 0) {
projectorCamera.setFrustumPerspective(getHorizontalFOVAngleDegrees(), 1.0f / getTextureHtoVRatio(), 1f, 5f);
} else {
projectorCamera.setFrustumPerspective(0.1f, 1.0f / getTextureHtoVRatio(), 1f, 5f);
}
}
}