I'm completely new to programming and Qt. I read about Qt 3d, but I have no idea how to do anything with it. All I need is a simple cuboid which I can move with a tilt sensor. I'm using qt 5.6.
I tried to understand the examples, but there they always use stuff I don't know.
// Cuboid shape data
Qt3DRender::QCuboidMesh *cuboid = new Qt3DRender::QCuboidMesh();
// CuboidMesh Transform
Qt3DCore::QTransform *cuboidTransform = new Qt3DCore::QTransform();
cuboidTransform->setScale(4.0f);
cuboidTransform->setTranslation(QVector3D(4.0f, -4.0f, 0.0f));
Qt3DRender::QPhongMaterial *cuboidMaterial = new Qt3DRender::QPhongMaterial();
cuboidMaterial->setDiffuse(QColor(QRgb(0x665423)));
//Cuboid
m_cuboidEntity = new Qt3DCore::QEntity(m_rootEntity);
m_cuboidEntity->addComponent(cuboid);
m_cuboidEntity->addComponent(cuboidMaterial);
m_cuboidEntity->addComponent(cuboidTransform);
I also tried to copy this example code, but guess, it isn't working.
Related
I have a time based tile server with radar data. I want to show this in mapbox.
The only way I get this working is this. Remove Source and layer and create a new source and layer.
mapboxMap.RemoveLayer("layer");
mapboxMap.RemoveSource("source");
RasterSource source = new RasterSource("source", tileset, 256);
mapboxMap.AddSource(source);
RasterLayer layer = new RasterLayer("layer", "source");
mapboxMap.AddLayer(layer);
This is working, bur the problem is that it is flickering. Is there another way to do this. I'm using Naxam.Mapbox.Droid version for Xamarin.
Thanks
Jelle
I'm trying to implement normal maps in a ThreeJS fragment shader, but it seems as though a key feature, computeTangents, has been lost in recent versions.
Here is a working demo using an older version of Three:
http://coryg89.github.io/technical/2013/06/01/photorealistic-3d-moon-demo-in-webgl-and-javascript/
ThreeJS is using computeTangents() to add an attribute called "tangents" to the vertex which is sent to the shader.
So I researched as much as I could and tried using a shader only method of computing the tangent, but this requires dFdx which causes an error about GL_OES_standard_derivatives in the shader on my Macbook Pro.
Then I tried converting the geometry from a simple cube to buffer geometry for use in the BufferGeometryUtils.computeTangent() function, in order to generate the tangents there, but that requires "indexed geometry", which isn't present in basic geo created by ThreeJS.
From the original demo, this is the line I need to recreate using the latest ThreeJS:
var mesh = new THREE.Mesh(geo, mat);
mesh.geometry.computeTangents();
Repo here:
https://github.com/CoryG89/MoonDemo
Is it possible to get this demo working using the new version of Three?
I found the answer to this. For the demo above, it required changing the THREE.SphereGeometry to THREE.SphereBufferGeometry.
var geo = new THREE.SphereBufferGeometry(radius, xSegments, ySegments);
Then I had to add the BufferGeometryUtils.js file and use the following code:
THREE.BufferGeometryUtils.computeTangents( geo );
This got the demo working again.
I searched around in SO to see if someone had a jsbin of the likes to show an example of this question so please forgive if this seems over asked.
Using r67 & r68
I have a simple THREE.Line named 'laser' that I move in some fashion, in this example I move and rotate it by mouse. Where ever the laser is I want to get the world cords of its vertices [0,1] so later I can attach a ray caster to those world cords.
I assume i'm just missing a core function that i'll dig through the source code and try to find. Hope this helps someone else in the future when I can update the jsbin.
Right now I just get its starting positions of 0,20 despite the matrix updates and such.
In the jsbin I left in some other commented out tries of code from other posts online.
Update: might have figured it out!
function render(){
// test finding the lasers vertices
laser.updateMatrixWorld(true);
// move laser
laser.rotation.z = MousePosition.x /50;
laser.position.x = MousePosition.x;
laser.position.y = MousePosition.y;
// which of these is needed?
laser.matrixWorldNeedsUpdate = true;
lasergeo.verticesNeedUpdate = true;
// --> this line looks to work
point1 = laser.localToWorld( lasergeo.vertices[1].clone() );
// console.log("point1", point1);
}
old
http://jsbin.com/yuqocemigacu/1/edit?html,js,console,output
new:
http://jsbin.com/yonaquzufeje/1/edit?html,js,output
In the new the refresh update skips the connection but thats another issue for another day.
Leaving this open cause I don't know if I have the correct method of doing this, could be do 900 matrix calculations and don't know it yet.
I am trying to create a .png image that is X pixels tall and Y pixels short. I am not finding what I am looking for on dlang.org, and am struggling to find any other resources via google.
Can you please provide an example of how to create a .png image in D?
For example, BufferedImage off_Image = new BufferedImage(100, 50, BufferedImage.TYPE_INT_ARGB); from http://docs.oracle.com/javase/tutorial/2d/images/drawonimage.html is what I am looking for (I think), except in the D programming language.
I wrote a little lib that can do this too. Grab png.d and color.d from here:
https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff
import arsd.png;
void main() {
// width * height
TrueColorImage image = new TrueColorImage(100, 50);
// fill it in with a gradient
auto colorData = image.imageData.colors; // get a ref to the color array
foreach(y; 0 .. image.height)
foreach(x; 0 .. image.width)
colorData[y * image.width + x] = Color(x * 2, 0, 0); // fill in (r,g,b,a=255)
writePng("test.png", image); // save it to a file
}
There is nothing in standard library for image work but you should be able to use DevIL or FreeImage to do what you want. Both of them have Derelict bindings.
DevIL (derelict-il)
FreeImage (derelict-fi)
Just use the C API documentation for either of them.
There is no standard 2D or 3D graphics API in Phobos, nor there is something similar to the ImageIO API from Java. However, there are plenty of D libraries written by various individuals, as well as various bindings to C/C++ libraries that could aid you in what you are doing. I am sure you should be able to accomplish what you need by using some parts of the GtkD .
I'd like to offer an alternative to Adam's solution - dlib has quite a few modules that come in handy when writing multi-media applications - image manipulation, linear algebra as well as geometry processing, I/O streams done right, basic XML parsing and others. It's still getting some development on the core interfaces (as of February 2014), but that should get pretty stable within a few weeks.
With dlib, that example code would translate to:
import dlib.image;
// width * height
auto image = new Image!(PixelFormat.RGB8)(100, 50);
// fill it in with a gradient
foreach(y; 0 .. image.height)
foreach(x; 0 .. image.width)
image[x, y] = Color4f(x * 2 / 255.0f, 0, 0);
savePNG(image, "test.png");
Grabbing the bytes directly is of course possible too, but why not do it the easier way? Premature optimization, etc.
If you're building your application with dub (which you probably should), using the latest and best of dlib is as simple as adding "dlib": "~master" to your dependencies.
I'm loading an .obj file into a Object3D object. That's working well and I can see it on the screen. However, I would like to create the impression of spinning sprites (fireflies, lightning globes, that sort of thing) at certain points above the object.
I've been looking over the three.js documentation on sprites and other things, and am very impressed with the capabilities. But I need a little help on how to create a standalone sprite 'globe' as it were, with sprites flying about in their own local coordinate system, then moving that standalone 'globe' to a point above the obj file. Could someone help me get started with this? (I guess it comes down to, how do you position one object relative to another in threejs?)
You should be able to simply attach the spinnning sprites to using the add() function:
//create an empty 'container'/Object3D
var spinningSprites = new Object3D();
//add elements to it:
for(var i = 0 ; i < numSprites; i++) spinningSprites.add(yourParticleObjectInstsance);
//lastly add the whole container to the loaded model:
youLoadedModel.add(spinningSprites);
The above is an example, you would proably use different variable names, etc., but the idea is simple: use add().