Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperLicht
camera position jumps

schizzomarino
Registered User
Quote
2013-10-24 21:18:33

Hello,
I am trying to get some code to work (I do use CopperCube but I need this entirely in Javascript). It moves the camera to a position according to where one clicks on a map.
But (as per forum) there is no way to disable collisions on the fly in Copperlicht and so the camera gets stuck when a new position entails it moving through a wall. So I am left with the option of creating a new camera on the fly once I have the new position vector. This does create a bit of coding and it seems a pity.

To be clear i do need to see the camera move, I want it to appear in the new position but the Pos function seems to move it rather than transport it.

Is there no way to keep my camera and just move it through walls with JavaScript?

Here is the part of the code that does it (and it does it well in copperlicht if I disable collisions on that camera in CopperCube)


var PositionNew = null;
var height1 = 43.6;

function MoveViewP(e, map) {
var Positi = imgXY(e, map);
var ratioX = -780/220; //where -780 is scene width, 220 img width
var ratioZ = 940/264; //where 940 is scene depth, 264 img height
PositionY = height1;
PositionX = Positi[0] * ratioX;
PositionZ = Positi[1] * ratioZ;
PositionNew = new CL3D.Vect3d(PositionX , PositionY, PositionZ);
CameraMain.Pos = PositionNew;
CameraMain.updateAbsolutePosition();
}

function imgXY(e, map){
var MappaScelta = map.id;
var offset_t = $(''+MappaScelta).offset().top - $(window).scrollTop();
var offset_l = $(''+MappaScelta).offset().left - $(window).scrollLeft();
var left = Math.round( (e.clientX - offset_l) );
var top = Math.round( (e.clientY - offset_t) );
return [left, top];
}


Any help would be much appreciated (if there is a way to temporarily disable then re enable collisions it would be perfect right now)

I can't use restart behaviour of a node in CopperCube as I need this in Javascript

Daniel


schizzomarino
Registered User
Quote
2013-10-24 22:13:42

I have sorted it out myself!!!! I love programming!!

All that was needed was a simple camera and two AnimatorCollisionResponse. Here is the code (simplified) for you all out there who might have needed a simple solution:


CollisionAnim = new CL3D.AnimatorCollisionResponse(new CL3D.Vect3d(1,1,1), new CL3D.Vect3d(0,-100.0,0), new CL3D.Vect3d(0,0,0), scene.CollisionWorld);
CollisionAnimTemp = new CL3D.AnimatorCollisionResponse(new CL3D.Vect3d(1,1,1), new CL3D.Vect3d(0,-100.0,0), new CL3D.Vect3d(0,0,0), "");

CameraMain.addAnimator(CollisionAnim);
var PositionNew = new CL3D.Vect3d(100, 0, 200);
var height1 = 43.6;

function MoveViewP() {
CameraMain.removeAnimator(CollisionAnim);
CameraMain.addAnimator(CollisionAnimTemp);

CameraMain.Pos = PositionNew;
CameraMain.updateAbsolutePosition();

CameraMain.removeAnimator(CollisionAnimTemp);
CollisionAnim.reset();
CameraMain.addAnimator(CollisionAnim);
}

MoveViewP()



The great thing is, this enables disabling of collisions on the fly


niko
Moderator
Quote
2013-10-25 07:21:13

Nice :)


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "?nternational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact